0
|
1 /* The "lrecord" structure (header of a compound lisp object).
|
|
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1996 Ben Wing.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 #ifndef _XEMACS_LRECORD_H_
|
|
25 #define _XEMACS_LRECORD_H_
|
|
26
|
|
27 /* The "lrecord" type of Lisp object is used for all object types
|
|
28 other than a few simple ones. This allows many types to be
|
|
29 implemented but only a few bits required in a Lisp object for
|
|
30 type information. (The tradeoff is that each object has its
|
|
31 type marked in it, thereby increasing its size.) The first
|
211
|
32 four bytes of all lrecords is either a pointer to a struct
|
|
33 lrecord_implementation, which contains methods describing how
|
|
34 to process this object, or an index into an array of pointers
|
|
35 to struct lrecord_implementations plus some other data bits.
|
0
|
36
|
|
37 lrecords are of two types: straight lrecords, and lcrecords.
|
|
38 Straight lrecords are used for those types of objects that
|
211
|
39 have their own allocation routines (typically allocated out of
|
|
40 2K chunks of memory). These objects have a `struct
|
|
41 lrecord_header' at the top, containing only the bits needed to
|
|
42 find the lrecord_implementation for the object. There are
|
|
43 special routines in alloc.c to deal with each such object
|
|
44 type.
|
0
|
45
|
|
46 Lcrecords are used for less common sorts of objects that don't
|
|
47 do their own allocation. Each such object is malloc()ed
|
|
48 individually, and the objects are chained together through
|
|
49 a `next' pointer. Lcrecords have a `struct lcrecord_header'
|
211
|
50 at the top, which contains a `struct lrecord_header' and
|
0
|
51 a `next' pointer, and are allocated using alloc_lcrecord().
|
|
52
|
|
53 Creating a new lcrecord type is fairly easy; just follow the
|
|
54 lead of some existing type (e.g. hashtables). Note that you
|
|
55 do not need to supply all the methods (see below); reasonable
|
|
56 defaults are provided for many of them. Alternatively, if you're
|
|
57 just looking for a way of encapsulating data (which possibly
|
|
58 could contain Lisp_Objects in it), you may well be able to use
|
|
59 the opaque type. */
|
|
60
|
|
61 struct lrecord_header
|
2
|
62 {
|
|
63 /* It would be better to put the mark-bit together with the
|
|
64 following datatype identification field in an 8- or 16-bit
|
|
65 integer rather than playing funny games with changing
|
|
66 header->implementation and "wasting" 32 bits on the below
|
|
67 pointer. The type-id would then be a 7 or 15 bit index into a
|
|
68 table of lrecord-implementations rather than a direct pointer.
|
|
69 There would be 24 (or 16) bits left over for datatype-specific
|
|
70 per-instance flags.
|
185
|
71
|
2
|
72 The below is the simplest thing to do for the present,
|
|
73 and doesn't incur that much overhead as most Emacs records
|
|
74 are of such a size that the overhead isn't too bad.
|
|
75 (The marker datatype is the worst case.)
|
185
|
76
|
2
|
77 It also has the very very very slight advantage that type-checking
|
|
78 involves one memory read (of the "implementation" slot) and a
|
|
79 comparison against a link-time constant address rather than a
|
|
80 read and a comparison against a variable value. (Variable since
|
|
81 it is a very good idea to assign the indices into the hypothetical
|
|
82 type-code table dynamically rather that pre-defining them.)
|
|
83 I think I remember that Elk Lisp does something like this.
|
|
84 Gee, I wonder if some cretin has patented it? */
|
211
|
85
|
|
86 /*
|
|
87 * If USE_INDEXED_LRECORD_IMPLEMENTATION is defined, we are
|
|
88 * implementing the scheme described in the 'It would be better
|
|
89 * ...' paragraph above.
|
|
90 */
|
|
91 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
92 /* index into lrecord_implementations_table[] */
|
|
93 unsigned type:8;
|
|
94 /* 1 if the object is marked during GC, 0 otherwise. */
|
|
95 unsigned mark:1;
|
|
96 /* 1 if the object was resides in pure (read-only) space */
|
|
97 unsigned pure:1;
|
|
98 #else
|
2
|
99 CONST struct lrecord_implementation *implementation;
|
211
|
100 #endif
|
2
|
101 };
|
211
|
102
|
243
|
103
|
211
|
104 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
243
|
105 struct lrecord_implementation;
|
|
106 int lrecord_type_index (CONST struct lrecord_implementation *implementation);
|
211
|
107 # define set_lheader_implementation(header,imp) \
|
213
|
108 do { (header)->type = lrecord_type_index((imp)); \
|
211
|
109 (header)->mark = 0; \
|
|
110 (header)->pure = 0; \
|
|
111 } while (0)
|
|
112 #else
|
|
113 # define set_lheader_implementation(header,imp) (header)->implementation=(imp)
|
|
114 #endif
|
0
|
115
|
|
116 struct lcrecord_header
|
2
|
117 {
|
|
118 struct lrecord_header lheader;
|
|
119 /* The "next" field is normally used to chain all lrecords together
|
|
120 so that the GC can find (and free) all of them.
|
|
121 "alloc_lcrecord" threads records together.
|
185
|
122
|
2
|
123 The "next" field may be used for other purposes as long as some
|
|
124 other mechanism is provided for letting the GC do its work. (For
|
|
125 example, the event and marker datatypes allocate members out of
|
|
126 memory chunks, and are able to find all unmarked members by
|
|
127 sweeping through the elements of the list of chunks) */
|
|
128 struct lcrecord_header *next;
|
|
129 /* This is just for debugging/printing convenience.
|
|
130 Having this slot doesn't hurt us much spacewise, since an lcrecord
|
|
131 already has the above slots together with malloc overhead. */
|
|
132 unsigned int uid :31;
|
|
133 /* A flag that indicates whether this lcrecord is on a "free list".
|
|
134 Free lists are used to minimize the number of calls to malloc()
|
|
135 when we're repeatedly allocating and freeing a number of the
|
|
136 same sort of lcrecord. Lcrecords on a free list always get
|
|
137 marked in a different fashion, so we can use this flag as a
|
|
138 sanity check to make sure that free lists only have freed lcrecords
|
|
139 and there are no freed lcrecords elsewhere. */
|
|
140 unsigned int free :1;
|
|
141 };
|
0
|
142
|
|
143 /* Used for lcrecords in an lcrecord-list. */
|
|
144 struct free_lcrecord_header
|
2
|
145 {
|
|
146 struct lcrecord_header lcheader;
|
|
147 Lisp_Object chain;
|
|
148 };
|
0
|
149
|
185
|
150 /* This as the value of lheader->implementation->finalizer
|
0
|
151 * means that this record is already marked */
|
|
152 extern void this_marks_a_marked_record (void *, int);
|
|
153
|
|
154 /* see alloc.c for an explanation */
|
|
155 extern Lisp_Object this_one_is_unmarkable (Lisp_Object obj,
|
|
156 void (*markobj) (Lisp_Object));
|
|
157
|
|
158 struct lrecord_implementation
|
2
|
159 {
|
|
160 CONST char *name;
|
|
161 /* This function is called at GC time, to make sure that all Lisp_Objects
|
|
162 pointed to by this object get properly marked. It should call
|
|
163 the mark_object function on all Lisp_Objects in the object. If
|
|
164 the return value is non-nil, it should be a Lisp_Object to be
|
|
165 marked (don't call the mark_object function explicitly on it,
|
|
166 because the GC routines will do this). Doing it this way reduces
|
|
167 recursion, so the object returned should preferably be the one
|
|
168 with the deepest level of Lisp_Object pointers. This function
|
|
169 can be NULL, meaning no GC marking is necessary. */
|
|
170 Lisp_Object (*marker) (Lisp_Object, void (*mark_object) (Lisp_Object));
|
|
171 /* This can be NULL if the object is an lcrecord; the
|
|
172 default_object_printer() in print.c will be used. */
|
|
173 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
|
|
174 /* This function is called at GC time when the object is about to
|
|
175 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
|
|
176 case). It should perform any necessary cleanup (e.g. freeing
|
|
177 malloc()ed memory. This can be NULL, meaning no special
|
|
178 finalization is necessary.
|
185
|
179
|
2
|
180 WARNING: remember that the finalizer is called at dump time even
|
|
181 though the object is not being freed. */
|
|
182 void (*finalizer) (void *header, int for_disksave);
|
|
183 /* This can be NULL, meaning compare objects with EQ(). */
|
|
184 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
|
|
185 /* This can be NULL, meaning use the Lisp_Object itself as the hash;
|
|
186 but *only* if the `equal' function is EQ (if two objects are
|
|
187 `equal', they *must* hash to the same value or the hashing won't
|
|
188 work). */
|
|
189 unsigned long (*hash) (Lisp_Object, int);
|
|
190 Lisp_Object (*getprop) (Lisp_Object obj, Lisp_Object prop);
|
|
191 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
|
|
192 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
|
|
193 Lisp_Object (*plist) (Lisp_Object obj);
|
0
|
194
|
2
|
195 /* Only one of these is non-0. If both are 0, it means that this type
|
|
196 is not instantiable by alloc_lcrecord(). */
|
|
197 unsigned int static_size;
|
|
198 unsigned int (*size_in_bytes_method) (CONST void *header);
|
|
199 /* A unique subtag-code (dynamically) assigned to this datatype. */
|
|
200 /* (This is a pointer so the rest of this structure can be read-only.) */
|
|
201 int *lrecord_type_index;
|
|
202 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
|
|
203 one that does not have an lcrecord_header at the front and which
|
|
204 is (usually) allocated in frob blocks. We only use this flag for
|
|
205 some consistency checking, and that only when error-checking is
|
|
206 enabled. */
|
|
207 int basic_p;
|
|
208 };
|
0
|
209
|
211
|
210 extern CONST struct lrecord_implementation *lrecord_implementations_table[];
|
|
211
|
|
212 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
213 # define XRECORD_LHEADER_IMPLEMENTATION(obj) \
|
|
214 (lrecord_implementations_table[XRECORD_LHEADER (obj)->type])
|
|
215 # define LHEADER_IMPLEMENTATION(lh) (lrecord_implementations_table[(lh)->type])
|
|
216 #else
|
|
217 # define XRECORD_LHEADER_IMPLEMENTATION(obj) \
|
|
218 (XRECORD_LHEADER (obj)->implementation)
|
|
219 # define LHEADER_IMPLEMENTATION(lh) ((lh)->implementation)
|
|
220 #endif
|
|
221
|
0
|
222 extern int gc_in_progress;
|
|
223
|
211
|
224 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
225 # define MARKED_RECORD_P(obj) (gc_in_progress && XRECORD_LHEADER (obj)->mark)
|
|
226 #else
|
|
227 # define MARKED_RECORD_P(obj) (gc_in_progress && \
|
0
|
228 XRECORD_LHEADER (obj)->implementation->finalizer == \
|
|
229 this_marks_a_marked_record)
|
211
|
230 #endif
|
0
|
231
|
211
|
232 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
207
|
233
|
211
|
234 # define MARKED_RECORD_HEADER_P(lheader) (lheader)->mark
|
|
235 # define MARK_RECORD_HEADER(lheader) (lheader)->mark = 1
|
|
236 # define UNMARK_RECORD_HEADER(lheader) (lheader)->mark = 0
|
|
237
|
|
238 #else /* ! USE_INDEXED_LRECORD_IMPLEMENTATION */
|
|
239
|
|
240 # define MARKED_RECORD_HEADER_P(lheader) \
|
207
|
241 (((lheader)->implementation->finalizer) == this_marks_a_marked_record)
|
211
|
242 # define MARK_RECORD_HEADER(lheader) \
|
207
|
243 do { (((lheader)->implementation)++); } while (0)
|
211
|
244 # define UNMARK_RECORD_HEADER(lheader) \
|
207
|
245 do { (((lheader)->implementation)--); } while (0)
|
|
246
|
211
|
247 #endif /* ! USE_INDEXED_LRECORD_IMPLEMENTATION */
|
|
248
|
|
249 #define UNMARKABLE_RECORD_HEADER_P(lheader) \
|
|
250 ((LHEADER_IMPLEMENTATION (lheader)->marker) \
|
|
251 == this_one_is_unmarkable)
|
207
|
252
|
0
|
253 /* Declaring the following structures as const puts them in the
|
|
254 text (read-only) segment, which makes debugging inconvenient
|
|
255 because this segment is not mapped when processing a core-
|
|
256 dump file */
|
|
257
|
|
258 #ifdef DEBUG_XEMACS
|
|
259 #define CONST_IF_NOT_DEBUG
|
|
260 #else
|
|
261 #define CONST_IF_NOT_DEBUG CONST
|
|
262 #endif
|
|
263
|
|
264 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
|
|
265 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
|
|
266 */
|
|
267
|
|
268 #if defined (ERROR_CHECK_TYPECHECK)
|
|
269 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
|
|
270 #else
|
|
271 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
|
|
272 #endif
|
|
273
|
|
274 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,structtype) \
|
|
275 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
276 static int lrecord_##c_name##_lrecord_type_index; \
|
|
277 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
278 { { name, marker, printer, nuker, equal, hash, \
|
|
279 0, 0, 0, 0, sizeof (structtype), 0, \
|
|
280 &(lrecord_##c_name##_lrecord_type_index), 1 }, \
|
|
281 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }
|
|
282
|
|
283 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,structtype) \
|
|
284 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
285 static int lrecord_##c_name##_lrecord_type_index; \
|
|
286 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
287 { { name, marker, printer, nuker, equal, hash, \
|
|
288 getprop, putprop, remprop, props, sizeof (structtype), 0, \
|
|
289 &(lrecord_##c_name##_lrecord_type_index), 1 }, \
|
|
290 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }
|
|
291
|
|
292 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,structtype) \
|
|
293 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
294 static int lrecord_##c_name##_lrecord_type_index; \
|
|
295 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
296 { { name, marker, printer, nuker, equal, hash, \
|
|
297 0, 0, 0, 0, sizeof (structtype), 0, \
|
|
298 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
299 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
300
|
|
301 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,structtype) \
|
|
302 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
303 static int lrecord_##c_name##_lrecord_type_index; \
|
|
304 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
305 { { name, marker, printer, nuker, equal, hash, \
|
|
306 getprop, putprop, remprop, props, sizeof (structtype), 0, \
|
|
307 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
308 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
309
|
|
310 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,sizer,structtype) \
|
|
311 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
312 static int lrecord_##c_name##_lrecord_type_index; \
|
|
313 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
314 { { name, marker, printer, nuker, equal, hash, \
|
|
315 0, 0, 0, 0, 0, sizer, \
|
|
316 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
317 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
318
|
|
319 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,sizer,structtype) \
|
|
320 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
321 static int lrecord_##c_name##_lrecord_type_index; \
|
|
322 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
323 { { name, marker, printer, nuker, equal, hash, \
|
|
324 getprop, putprop, remprop, props, 0, sizer, \
|
|
325 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
326 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
327
|
185
|
328 #define LRECORDP(a) (XTYPE ((a)) == Lisp_Type_Record)
|
0
|
329 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
|
211
|
330
|
|
331 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
332 # define RECORD_TYPEP(x, ty) \
|
|
333 (LRECORDP (x) && \
|
|
334 lrecord_implementations_table[XRECORD_LHEADER (x)->type] == (ty))
|
|
335 #else
|
|
336 # define RECORD_TYPEP(x, ty) \
|
0
|
337 (LRECORDP (x) && XRECORD_LHEADER (x)->implementation == (ty))
|
211
|
338 #endif
|
0
|
339
|
|
340 /* NOTE: the DECLARE_LRECORD() must come before the associated
|
|
341 DEFINE_LRECORD_*() or you will get compile errors.
|
|
342
|
|
343 Furthermore, you always need to put the DECLARE_LRECORD() in a header
|
|
344 file, and make sure the header file is included in inline.c, even
|
|
345 if the type is private to a particular file. Otherwise, you will
|
|
346 get undefined references for the error_check_foo() inline function
|
|
347 under GCC. */
|
|
348
|
|
349 #ifdef ERROR_CHECK_TYPECHECK
|
|
350
|
2
|
351 # define DECLARE_LRECORD(c_name, structtype) \
|
|
352 extern CONST_IF_NOT_DEBUG struct lrecord_implementation \
|
|
353 lrecord_##c_name[]; \
|
|
354 INLINE structtype *error_check_##c_name (Lisp_Object _obj); \
|
|
355 INLINE structtype * \
|
|
356 error_check_##c_name (Lisp_Object _obj) \
|
|
357 { \
|
|
358 XUNMARK (_obj); \
|
|
359 assert (RECORD_TYPEP (_obj, lrecord_##c_name) || \
|
|
360 MARKED_RECORD_P (_obj)); \
|
|
361 return (structtype *) XPNTR (_obj); \
|
|
362 } \
|
0
|
363 extern Lisp_Object Q##c_name##p
|
|
364
|
2
|
365 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
|
366 INLINE structtype *error_check_##c_name (Lisp_Object _obj); \
|
|
367 INLINE structtype * \
|
|
368 error_check_##c_name (Lisp_Object _obj) \
|
|
369 { \
|
|
370 XUNMARK (_obj); \
|
|
371 assert (XGCTYPE (_obj) == type_enum); \
|
|
372 return (structtype *) XPNTR (_obj); \
|
|
373 } \
|
0
|
374 extern Lisp_Object Q##c_name##p
|
|
375
|
|
376 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
|
|
377 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
|
|
378
|
2
|
379 # define XSETRECORD(var, p, c_name) do \
|
|
380 { \
|
185
|
381 XSETOBJ (var, Lisp_Type_Record, p); \
|
2
|
382 assert (RECORD_TYPEP (var, lrecord_##c_name) || \
|
|
383 MARKED_RECORD_P (var)); \
|
0
|
384 } while (0)
|
|
385
|
|
386 #else /* not ERROR_CHECK_TYPECHECK */
|
|
387
|
2
|
388 # define DECLARE_LRECORD(c_name, structtype) \
|
|
389 extern Lisp_Object Q##c_name##p; \
|
|
390 extern CONST_IF_NOT_DEBUG struct lrecord_implementation \
|
0
|
391 lrecord_##c_name[]
|
2
|
392 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
0
|
393 extern Lisp_Object Q##c_name##p
|
|
394 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
|
2
|
395 # define XNONRECORD(x, c_name, type_enum, structtype) \
|
0
|
396 ((structtype *) XPNTR (x))
|
185
|
397 # define XSETRECORD(var, p, c_name) XSETOBJ (var, Lisp_Type_Record, p)
|
0
|
398
|
|
399 #endif /* not ERROR_CHECK_TYPECHECK */
|
|
400
|
|
401 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_##c_name)
|
|
402 #define GC_RECORDP(x, c_name) gc_record_type_p (x, lrecord_##c_name)
|
|
403
|
|
404 /* Note: we now have two different kinds of type-checking macros.
|
|
405 The "old" kind has now been renamed CONCHECK_foo. The reason for
|
|
406 this is that the CONCHECK_foo macros signal a continuable error,
|
185
|
407 allowing the user (through debug-on-error) to substitute a different
|
0
|
408 value and return from the signal, which causes the lvalue argument
|
|
409 to get changed. Quite a lot of code would crash if that happened,
|
|
410 because it did things like
|
|
411
|
|
412 foo = XCAR (list);
|
|
413 CHECK_STRING (foo);
|
|
414
|
|
415 and later on did XSTRING (XCAR (list)), assuming that the type
|
|
416 is correct (when it might be wrong, if the user substituted a
|
|
417 correct value in the debugger).
|
|
418
|
|
419 To get around this, I made all the CHECK_foo macros signal a
|
|
420 non-continuable error. Places where a continuable error is OK
|
|
421 (generally only when called directly on the argument of a Lisp
|
|
422 primitive) should be changed to use CONCHECK().
|
|
423
|
|
424 FSF Emacs does not have this problem because RMS took the cheesy
|
|
425 way out and disabled returning from a signal entirely. */
|
|
426
|
185
|
427 #define CONCHECK_RECORD(x, c_name) do { \
|
|
428 if (!RECORD_TYPEP (x, lrecord_##c_name)) \
|
|
429 x = wrong_type_argument (Q##c_name##p, x); \
|
|
430 } while (0)
|
|
431 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
|
|
432 if (XTYPE (x) != lisp_enum) \
|
|
433 x = wrong_type_argument (predicate, x); \
|
|
434 } while (0)
|
|
435 #define CHECK_RECORD(x, c_name) do { \
|
|
436 if (!RECORD_TYPEP (x, lrecord_##c_name)) \
|
|
437 dead_wrong_type_argument (Q##c_name##p, x); \
|
|
438 } while (0)
|
|
439 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
|
|
440 if (XTYPE (x) != lisp_enum) \
|
|
441 dead_wrong_type_argument (predicate, x); \
|
|
442 } while (0)
|
0
|
443
|
|
444 void *alloc_lcrecord (int size, CONST struct lrecord_implementation *);
|
|
445
|
185
|
446 #define alloc_lcrecord_type(type, lrecord_implementation) \
|
|
447 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
|
|
448
|
0
|
449 int gc_record_type_p (Lisp_Object frob,
|
|
450 CONST struct lrecord_implementation *type);
|
|
451
|
|
452 /* Copy the data from one lcrecord structure into another, but don't
|
|
453 overwrite the header information. */
|
|
454
|
2
|
455 #define copy_lcrecord(dst, src) \
|
|
456 memcpy ((char *) dst + sizeof (struct lcrecord_header), \
|
|
457 (char *) src + sizeof (struct lcrecord_header), \
|
0
|
458 sizeof (*dst) - sizeof (struct lcrecord_header))
|
|
459
|
2
|
460 #define zero_lcrecord(lcr) \
|
|
461 memset ((char *) lcr + sizeof (struct lcrecord_header), 0, \
|
0
|
462 sizeof (*lcr) - sizeof (struct lcrecord_header))
|
|
463
|
|
464 #endif /* _XEMACS_LRECORD_H_ */
|