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
|
|
103 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
104 # define set_lheader_implementation(header,imp) \
|
213
|
105 do { (header)->type = lrecord_type_index((imp)); \
|
211
|
106 (header)->mark = 0; \
|
|
107 (header)->pure = 0; \
|
|
108 } while (0)
|
|
109 #else
|
|
110 # define set_lheader_implementation(header,imp) (header)->implementation=(imp)
|
|
111 #endif
|
0
|
112
|
|
113 struct lcrecord_header
|
2
|
114 {
|
|
115 struct lrecord_header lheader;
|
|
116 /* The "next" field is normally used to chain all lrecords together
|
|
117 so that the GC can find (and free) all of them.
|
|
118 "alloc_lcrecord" threads records together.
|
185
|
119
|
2
|
120 The "next" field may be used for other purposes as long as some
|
|
121 other mechanism is provided for letting the GC do its work. (For
|
|
122 example, the event and marker datatypes allocate members out of
|
|
123 memory chunks, and are able to find all unmarked members by
|
|
124 sweeping through the elements of the list of chunks) */
|
|
125 struct lcrecord_header *next;
|
|
126 /* This is just for debugging/printing convenience.
|
|
127 Having this slot doesn't hurt us much spacewise, since an lcrecord
|
|
128 already has the above slots together with malloc overhead. */
|
|
129 unsigned int uid :31;
|
|
130 /* A flag that indicates whether this lcrecord is on a "free list".
|
|
131 Free lists are used to minimize the number of calls to malloc()
|
|
132 when we're repeatedly allocating and freeing a number of the
|
|
133 same sort of lcrecord. Lcrecords on a free list always get
|
|
134 marked in a different fashion, so we can use this flag as a
|
|
135 sanity check to make sure that free lists only have freed lcrecords
|
|
136 and there are no freed lcrecords elsewhere. */
|
|
137 unsigned int free :1;
|
|
138 };
|
0
|
139
|
|
140 /* Used for lcrecords in an lcrecord-list. */
|
|
141 struct free_lcrecord_header
|
2
|
142 {
|
|
143 struct lcrecord_header lcheader;
|
|
144 Lisp_Object chain;
|
|
145 };
|
0
|
146
|
185
|
147 /* This as the value of lheader->implementation->finalizer
|
0
|
148 * means that this record is already marked */
|
|
149 extern void this_marks_a_marked_record (void *, int);
|
|
150
|
|
151 /* see alloc.c for an explanation */
|
|
152 extern Lisp_Object this_one_is_unmarkable (Lisp_Object obj,
|
|
153 void (*markobj) (Lisp_Object));
|
|
154
|
|
155 struct lrecord_implementation
|
2
|
156 {
|
|
157 CONST char *name;
|
|
158 /* This function is called at GC time, to make sure that all Lisp_Objects
|
|
159 pointed to by this object get properly marked. It should call
|
|
160 the mark_object function on all Lisp_Objects in the object. If
|
|
161 the return value is non-nil, it should be a Lisp_Object to be
|
|
162 marked (don't call the mark_object function explicitly on it,
|
|
163 because the GC routines will do this). Doing it this way reduces
|
|
164 recursion, so the object returned should preferably be the one
|
|
165 with the deepest level of Lisp_Object pointers. This function
|
|
166 can be NULL, meaning no GC marking is necessary. */
|
|
167 Lisp_Object (*marker) (Lisp_Object, void (*mark_object) (Lisp_Object));
|
|
168 /* This can be NULL if the object is an lcrecord; the
|
|
169 default_object_printer() in print.c will be used. */
|
|
170 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
|
|
171 /* This function is called at GC time when the object is about to
|
|
172 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
|
|
173 case). It should perform any necessary cleanup (e.g. freeing
|
|
174 malloc()ed memory. This can be NULL, meaning no special
|
|
175 finalization is necessary.
|
185
|
176
|
2
|
177 WARNING: remember that the finalizer is called at dump time even
|
|
178 though the object is not being freed. */
|
|
179 void (*finalizer) (void *header, int for_disksave);
|
|
180 /* This can be NULL, meaning compare objects with EQ(). */
|
|
181 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
|
|
182 /* This can be NULL, meaning use the Lisp_Object itself as the hash;
|
|
183 but *only* if the `equal' function is EQ (if two objects are
|
|
184 `equal', they *must* hash to the same value or the hashing won't
|
|
185 work). */
|
|
186 unsigned long (*hash) (Lisp_Object, int);
|
|
187 Lisp_Object (*getprop) (Lisp_Object obj, Lisp_Object prop);
|
|
188 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
|
|
189 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
|
|
190 Lisp_Object (*plist) (Lisp_Object obj);
|
0
|
191
|
2
|
192 /* Only one of these is non-0. If both are 0, it means that this type
|
|
193 is not instantiable by alloc_lcrecord(). */
|
|
194 unsigned int static_size;
|
|
195 unsigned int (*size_in_bytes_method) (CONST void *header);
|
|
196 /* A unique subtag-code (dynamically) assigned to this datatype. */
|
|
197 /* (This is a pointer so the rest of this structure can be read-only.) */
|
|
198 int *lrecord_type_index;
|
|
199 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
|
|
200 one that does not have an lcrecord_header at the front and which
|
|
201 is (usually) allocated in frob blocks. We only use this flag for
|
|
202 some consistency checking, and that only when error-checking is
|
|
203 enabled. */
|
|
204 int basic_p;
|
|
205 };
|
0
|
206
|
211
|
207 extern CONST struct lrecord_implementation *lrecord_implementations_table[];
|
|
208
|
|
209 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
210 # define XRECORD_LHEADER_IMPLEMENTATION(obj) \
|
|
211 (lrecord_implementations_table[XRECORD_LHEADER (obj)->type])
|
|
212 # define LHEADER_IMPLEMENTATION(lh) (lrecord_implementations_table[(lh)->type])
|
|
213 #else
|
|
214 # define XRECORD_LHEADER_IMPLEMENTATION(obj) \
|
|
215 (XRECORD_LHEADER (obj)->implementation)
|
|
216 # define LHEADER_IMPLEMENTATION(lh) ((lh)->implementation)
|
|
217 #endif
|
|
218
|
0
|
219 extern int gc_in_progress;
|
|
220
|
211
|
221 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
222 # define MARKED_RECORD_P(obj) (gc_in_progress && XRECORD_LHEADER (obj)->mark)
|
|
223 #else
|
|
224 # define MARKED_RECORD_P(obj) (gc_in_progress && \
|
0
|
225 XRECORD_LHEADER (obj)->implementation->finalizer == \
|
|
226 this_marks_a_marked_record)
|
211
|
227 #endif
|
0
|
228
|
211
|
229 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
207
|
230
|
211
|
231 # define MARKED_RECORD_HEADER_P(lheader) (lheader)->mark
|
|
232 # define MARK_RECORD_HEADER(lheader) (lheader)->mark = 1
|
|
233 # define UNMARK_RECORD_HEADER(lheader) (lheader)->mark = 0
|
|
234
|
|
235 #else /* ! USE_INDEXED_LRECORD_IMPLEMENTATION */
|
|
236
|
|
237 # define MARKED_RECORD_HEADER_P(lheader) \
|
207
|
238 (((lheader)->implementation->finalizer) == this_marks_a_marked_record)
|
211
|
239 # define MARK_RECORD_HEADER(lheader) \
|
207
|
240 do { (((lheader)->implementation)++); } while (0)
|
211
|
241 # define UNMARK_RECORD_HEADER(lheader) \
|
207
|
242 do { (((lheader)->implementation)--); } while (0)
|
|
243
|
211
|
244 #endif /* ! USE_INDEXED_LRECORD_IMPLEMENTATION */
|
|
245
|
|
246 #define UNMARKABLE_RECORD_HEADER_P(lheader) \
|
|
247 ((LHEADER_IMPLEMENTATION (lheader)->marker) \
|
|
248 == this_one_is_unmarkable)
|
207
|
249
|
0
|
250 /* Declaring the following structures as const puts them in the
|
|
251 text (read-only) segment, which makes debugging inconvenient
|
|
252 because this segment is not mapped when processing a core-
|
|
253 dump file */
|
|
254
|
|
255 #ifdef DEBUG_XEMACS
|
|
256 #define CONST_IF_NOT_DEBUG
|
|
257 #else
|
|
258 #define CONST_IF_NOT_DEBUG CONST
|
|
259 #endif
|
|
260
|
|
261 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
|
|
262 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
|
|
263 */
|
|
264
|
|
265 #if defined (ERROR_CHECK_TYPECHECK)
|
|
266 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
|
|
267 #else
|
|
268 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
|
|
269 #endif
|
|
270
|
|
271 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,structtype) \
|
|
272 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
273 static int lrecord_##c_name##_lrecord_type_index; \
|
|
274 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
275 { { name, marker, printer, nuker, equal, hash, \
|
|
276 0, 0, 0, 0, sizeof (structtype), 0, \
|
|
277 &(lrecord_##c_name##_lrecord_type_index), 1 }, \
|
|
278 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }
|
|
279
|
|
280 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,structtype) \
|
|
281 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
282 static int lrecord_##c_name##_lrecord_type_index; \
|
|
283 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
284 { { name, marker, printer, nuker, equal, hash, \
|
|
285 getprop, putprop, remprop, props, sizeof (structtype), 0, \
|
|
286 &(lrecord_##c_name##_lrecord_type_index), 1 }, \
|
|
287 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } }
|
|
288
|
|
289 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,structtype) \
|
|
290 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
291 static int lrecord_##c_name##_lrecord_type_index; \
|
|
292 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
293 { { name, marker, printer, nuker, equal, hash, \
|
|
294 0, 0, 0, 0, sizeof (structtype), 0, \
|
|
295 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
296 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
297
|
|
298 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,structtype) \
|
|
299 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
300 static int lrecord_##c_name##_lrecord_type_index; \
|
|
301 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
302 { { name, marker, printer, nuker, equal, hash, \
|
|
303 getprop, putprop, remprop, props, sizeof (structtype), 0, \
|
|
304 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
305 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
306
|
|
307 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,sizer,structtype) \
|
|
308 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
309 static int lrecord_##c_name##_lrecord_type_index; \
|
|
310 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
311 { { name, marker, printer, nuker, equal, hash, \
|
|
312 0, 0, 0, 0, 0, sizer, \
|
|
313 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
314 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
315
|
|
316 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,sizer,structtype) \
|
|
317 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
|
318 static int lrecord_##c_name##_lrecord_type_index; \
|
|
319 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
|
|
320 { { name, marker, printer, nuker, equal, hash, \
|
|
321 getprop, putprop, remprop, props, 0, sizer, \
|
|
322 &(lrecord_##c_name##_lrecord_type_index), 0 }, \
|
|
323 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
|
|
324
|
185
|
325 #define LRECORDP(a) (XTYPE ((a)) == Lisp_Type_Record)
|
0
|
326 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
|
211
|
327
|
|
328 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
329 # define RECORD_TYPEP(x, ty) \
|
|
330 (LRECORDP (x) && \
|
|
331 lrecord_implementations_table[XRECORD_LHEADER (x)->type] == (ty))
|
|
332 #else
|
|
333 # define RECORD_TYPEP(x, ty) \
|
0
|
334 (LRECORDP (x) && XRECORD_LHEADER (x)->implementation == (ty))
|
211
|
335 #endif
|
0
|
336
|
|
337 /* NOTE: the DECLARE_LRECORD() must come before the associated
|
|
338 DEFINE_LRECORD_*() or you will get compile errors.
|
|
339
|
|
340 Furthermore, you always need to put the DECLARE_LRECORD() in a header
|
|
341 file, and make sure the header file is included in inline.c, even
|
|
342 if the type is private to a particular file. Otherwise, you will
|
|
343 get undefined references for the error_check_foo() inline function
|
|
344 under GCC. */
|
|
345
|
|
346 #ifdef ERROR_CHECK_TYPECHECK
|
|
347
|
2
|
348 # define DECLARE_LRECORD(c_name, structtype) \
|
|
349 extern CONST_IF_NOT_DEBUG struct lrecord_implementation \
|
|
350 lrecord_##c_name[]; \
|
|
351 INLINE structtype *error_check_##c_name (Lisp_Object _obj); \
|
|
352 INLINE structtype * \
|
|
353 error_check_##c_name (Lisp_Object _obj) \
|
|
354 { \
|
|
355 XUNMARK (_obj); \
|
|
356 assert (RECORD_TYPEP (_obj, lrecord_##c_name) || \
|
|
357 MARKED_RECORD_P (_obj)); \
|
|
358 return (structtype *) XPNTR (_obj); \
|
|
359 } \
|
0
|
360 extern Lisp_Object Q##c_name##p
|
|
361
|
2
|
362 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
|
363 INLINE structtype *error_check_##c_name (Lisp_Object _obj); \
|
|
364 INLINE structtype * \
|
|
365 error_check_##c_name (Lisp_Object _obj) \
|
|
366 { \
|
|
367 XUNMARK (_obj); \
|
|
368 assert (XGCTYPE (_obj) == type_enum); \
|
|
369 return (structtype *) XPNTR (_obj); \
|
|
370 } \
|
0
|
371 extern Lisp_Object Q##c_name##p
|
|
372
|
|
373 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
|
|
374 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
|
|
375
|
2
|
376 # define XSETRECORD(var, p, c_name) do \
|
|
377 { \
|
185
|
378 XSETOBJ (var, Lisp_Type_Record, p); \
|
2
|
379 assert (RECORD_TYPEP (var, lrecord_##c_name) || \
|
|
380 MARKED_RECORD_P (var)); \
|
0
|
381 } while (0)
|
|
382
|
|
383 #else /* not ERROR_CHECK_TYPECHECK */
|
|
384
|
2
|
385 # define DECLARE_LRECORD(c_name, structtype) \
|
|
386 extern Lisp_Object Q##c_name##p; \
|
|
387 extern CONST_IF_NOT_DEBUG struct lrecord_implementation \
|
0
|
388 lrecord_##c_name[]
|
2
|
389 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
0
|
390 extern Lisp_Object Q##c_name##p
|
|
391 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
|
2
|
392 # define XNONRECORD(x, c_name, type_enum, structtype) \
|
0
|
393 ((structtype *) XPNTR (x))
|
185
|
394 # define XSETRECORD(var, p, c_name) XSETOBJ (var, Lisp_Type_Record, p)
|
0
|
395
|
|
396 #endif /* not ERROR_CHECK_TYPECHECK */
|
|
397
|
|
398 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_##c_name)
|
|
399 #define GC_RECORDP(x, c_name) gc_record_type_p (x, lrecord_##c_name)
|
|
400
|
|
401 /* Note: we now have two different kinds of type-checking macros.
|
|
402 The "old" kind has now been renamed CONCHECK_foo. The reason for
|
|
403 this is that the CONCHECK_foo macros signal a continuable error,
|
185
|
404 allowing the user (through debug-on-error) to substitute a different
|
0
|
405 value and return from the signal, which causes the lvalue argument
|
|
406 to get changed. Quite a lot of code would crash if that happened,
|
|
407 because it did things like
|
|
408
|
|
409 foo = XCAR (list);
|
|
410 CHECK_STRING (foo);
|
|
411
|
|
412 and later on did XSTRING (XCAR (list)), assuming that the type
|
|
413 is correct (when it might be wrong, if the user substituted a
|
|
414 correct value in the debugger).
|
|
415
|
|
416 To get around this, I made all the CHECK_foo macros signal a
|
|
417 non-continuable error. Places where a continuable error is OK
|
|
418 (generally only when called directly on the argument of a Lisp
|
|
419 primitive) should be changed to use CONCHECK().
|
|
420
|
|
421 FSF Emacs does not have this problem because RMS took the cheesy
|
|
422 way out and disabled returning from a signal entirely. */
|
|
423
|
185
|
424 #define CONCHECK_RECORD(x, c_name) do { \
|
|
425 if (!RECORD_TYPEP (x, lrecord_##c_name)) \
|
|
426 x = wrong_type_argument (Q##c_name##p, x); \
|
|
427 } while (0)
|
|
428 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
|
|
429 if (XTYPE (x) != lisp_enum) \
|
|
430 x = wrong_type_argument (predicate, x); \
|
|
431 } while (0)
|
|
432 #define CHECK_RECORD(x, c_name) do { \
|
|
433 if (!RECORD_TYPEP (x, lrecord_##c_name)) \
|
|
434 dead_wrong_type_argument (Q##c_name##p, x); \
|
|
435 } while (0)
|
|
436 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
|
|
437 if (XTYPE (x) != lisp_enum) \
|
|
438 dead_wrong_type_argument (predicate, x); \
|
|
439 } while (0)
|
0
|
440
|
|
441 void *alloc_lcrecord (int size, CONST struct lrecord_implementation *);
|
|
442
|
185
|
443 #define alloc_lcrecord_type(type, lrecord_implementation) \
|
|
444 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
|
|
445
|
0
|
446 int gc_record_type_p (Lisp_Object frob,
|
|
447 CONST struct lrecord_implementation *type);
|
|
448
|
|
449 /* Copy the data from one lcrecord structure into another, but don't
|
|
450 overwrite the header information. */
|
|
451
|
2
|
452 #define copy_lcrecord(dst, src) \
|
|
453 memcpy ((char *) dst + sizeof (struct lcrecord_header), \
|
|
454 (char *) src + sizeof (struct lcrecord_header), \
|
0
|
455 sizeof (*dst) - sizeof (struct lcrecord_header))
|
|
456
|
2
|
457 #define zero_lcrecord(lcr) \
|
|
458 memset ((char *) lcr + sizeof (struct lcrecord_header), 0, \
|
0
|
459 sizeof (*lcr) - sizeof (struct lcrecord_header))
|
|
460
|
|
461 #endif /* _XEMACS_LRECORD_H_ */
|