comparison src/lisp.h @ 456:e7ef97881643 r21-2-43

Import from CVS: tag r21-2-43
author cvs
date Mon, 13 Aug 2007 11:41:24 +0200
parents d7a9135ec789
children c33ae14dd6d0
comparison
equal deleted inserted replaced
455:5b97c1cd6ed0 456:e7ef97881643
214 - it doesn't work with C++. The C++ committee has decided, 214 - it doesn't work with C++. The C++ committee has decided,
215 in its infinite wisdom, that: 215 in its infinite wisdom, that:
216 "Types must be declared in declarations, not in expressions." */ 216 "Types must be declared in declarations, not in expressions." */
217 # define ALIGNOF(type) offsetof (struct { char c; type member; }, member) 217 # define ALIGNOF(type) offsetof (struct { char c; type member; }, member)
218 # else 218 # else
219 /* The following should be completely portable, but might give values 219 /* C++ is annoying, but it has a big bag of tricks.
220 that are larger than necessary. But never larger than the maximum 220 The following doesn't have the "inside out" declaration bug C does. */
221 possible alignment. */ 221 template<class T> struct alignment_trick { char c; T member; };
222 # define ALIGNOF(type) \ 222 # define ALIGNOF(type) offsetof (alignment_trick<type>, member)
223 ((sizeof (type) % sizeof (max_align_t)) == 0 ? \
224 sizeof (max_align_t) : \
225 (sizeof (type) % sizeof (max_align_t)))
226 # endif 223 # endif
227 #endif /* ALIGNOF */ 224 #endif /* ALIGNOF */
228 225
229 #define ALIGN_SIZE(len, unit) \ 226 #define ALIGN_SIZE(len, unit) \
230 ((((len) + (unit) - 1) / (unit)) * (unit)) 227 ((((len) + (unit) - 1) / (unit)) * (unit))
1201 # define string_char_addr(s, i) string_byte_addr (s, i) 1198 # define string_char_addr(s, i) string_byte_addr (s, i)
1202 # define set_string_char(s, i, c) set_string_byte (s, i, (Bufbyte)c) 1199 # define set_string_char(s, i, c) set_string_byte (s, i, (Bufbyte)c)
1203 1200
1204 #endif /* not MULE */ 1201 #endif /* not MULE */
1205 1202
1206 /* Return the true size of a struct with a variable-length array field. */ 1203 /* Return the true aligned size of a struct whose last member is a
1207 #define FLEXIBLE_ARRAY_STRUCT_SIZEOF(flexible_array_structtype, \ 1204 variable-length array field. (this is known as the "struct hack") */
1208 flexible_array_field, \ 1205 /* Implementation: in practice, structtype and fieldtype usually have
1209 flexible_array_length) \ 1206 the same alignment, but we can't be sure. We need to use
1210 (offsetof (flexible_array_structtype, flexible_array_field) + \ 1207 ALIGN_SIZE to be absolutely sure of getting the correct alignment.
1211 (offsetof (flexible_array_structtype, flexible_array_field[1]) - \ 1208 To help the compiler's optimizer, we use a ternary expression that
1212 offsetof (flexible_array_structtype, flexible_array_field[0])) * \ 1209 only a very stupid compiler would fail to correctly simplify. */
1213 (flexible_array_length)) 1210 #define FLEXIBLE_ARRAY_STRUCT_SIZEOF(structtype, \
1211 fieldtype, \
1212 fieldname, \
1213 array_length) \
1214 (ALIGNOF (structtype) == ALIGNOF (fieldtype) \
1215 ? (offsetof (structtype, fieldname) + \
1216 (offsetof (structtype, fieldname[1]) - \
1217 offsetof (structtype, fieldname[0])) * \
1218 (array_length)) \
1219 : (ALIGN_SIZE \
1220 ((offsetof (structtype, fieldname) + \
1221 (offsetof (structtype, fieldname[1]) - \
1222 offsetof (structtype, fieldname[0])) * \
1223 (array_length)), \
1224 ALIGNOF (structtype))))
1214 1225
1215 /*------------------------------ vector --------------------------------*/ 1226 /*------------------------------ vector --------------------------------*/
1216 1227
1217 struct Lisp_Vector 1228 struct Lisp_Vector
1218 { 1229 {