XEmacs 21.2.33 "Melpomene".
[chise/xemacs-chise.git.1] / src / lrecord.h
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 INCLUDED_lrecord_h_
25 #define INCLUDED_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 type
30    information. (The tradeoff is that each object has its type marked
31    in it, thereby increasing its size.) All lrecords begin with a
32    `struct lrecord_header', which identifies the lisp object type, by
33    providing an index into a table of `struct lrecord_implementation',
34    which describes the behavior of the lisp object.  It also contains
35    some other data bits.
36
37    Lrecords are of two types: straight lrecords, and lcrecords.
38    Straight lrecords are used for those types of objects that have
39    their own allocation routines (typically allocated out of 2K chunks
40    of memory called `frob blocks').  These objects have a `struct
41    lrecord_header' at the top, containing only the bits needed to find
42    the lrecord_implementation for the object.  There are special
43    routines in alloc.c to deal with each such object type.
44
45    Lcrecords are used for less common sorts of objects that don't do
46    their own allocation.  Each such object is malloc()ed individually,
47    and the objects are chained together through a `next' pointer.
48    Lcrecords have a `struct lcrecord_header' at the top, which
49    contains a `struct lrecord_header' and a `next' pointer, and are
50    allocated using alloc_lcrecord().
51
52    Creating a new lcrecord type is fairly easy; just follow the
53    lead of some existing type (e.g. hash tables).  Note that you
54    do not need to supply all the methods (see below); reasonable
55    defaults are provided for many of them.  Alternatively, if you're
56    just looking for a way of encapsulating data (which possibly
57    could contain Lisp_Objects in it), you may well be able to use
58    the opaque type. */
59
60 struct lrecord_header
61 {
62   /* index into lrecord_implementations_table[] */
63   unsigned int type :8;
64
65   /* If `mark' is 0 after the GC mark phase, the object will be freed
66      during the GC sweep phase.  There are 2 ways that `mark' can be 1:
67      - by being referenced from other objects during the GC mark phase
68      - because it is permanently on, for c_readonly objects */
69   unsigned int mark :1;
70
71   /* 1 if the object resides in logically read-only space, and does not
72      reference other non-c_readonly objects.
73      Invariant: if (c_readonly == 1), then (mark == 1 && lisp_readonly == 1) */
74   unsigned int c_readonly :1;
75
76   /* 1 if the object is readonly from lisp */
77   unsigned int lisp_readonly :1;
78 };
79
80 struct lrecord_implementation;
81 int lrecord_type_index (const struct lrecord_implementation *implementation);
82
83 #define set_lheader_implementation(header,imp) do {     \
84   struct lrecord_header* SLI_header = (header);         \
85   SLI_header->type = (imp)->lrecord_type_index;         \
86   SLI_header->mark = 0;                                 \
87   SLI_header->c_readonly = 0;                           \
88   SLI_header->lisp_readonly = 0;                        \
89 } while (0)
90
91 struct lcrecord_header
92 {
93   struct lrecord_header lheader;
94
95   /* The `next' field is normally used to chain all lcrecords together
96      so that the GC can find (and free) all of them.
97      `alloc_lcrecord' threads lcrecords together.
98
99      The `next' field may be used for other purposes as long as some
100      other mechanism is provided for letting the GC do its work.
101
102      For example, the event and marker object types allocate members
103      out of memory chunks, and are able to find all unmarked members
104      by sweeping through the elements of the list of chunks.  */
105   struct lcrecord_header *next;
106
107   /* The `uid' field is just for debugging/printing convenience.
108      Having this slot doesn't hurt us much spacewise, since an
109      lcrecord already has the above slots plus malloc overhead. */
110   unsigned int uid :31;
111
112   /* The `free' field is a flag that indicates whether this lcrecord
113      is on a "free list".  Free lists are used to minimize the number
114      of calls to malloc() when we're repeatedly allocating and freeing
115      a number of the same sort of lcrecord.  Lcrecords on a free list
116      always get marked in a different fashion, so we can use this flag
117      as a sanity check to make sure that free lists only have freed
118      lcrecords and there are no freed lcrecords elsewhere. */
119   unsigned int free :1;
120 };
121
122 /* Used for lcrecords in an lcrecord-list. */
123 struct free_lcrecord_header
124 {
125   struct lcrecord_header lcheader;
126   Lisp_Object chain;
127 };
128
129 enum lrecord_type
130 {
131   /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast.
132      #### This should be replaced by a symbol_value_magic_p flag
133      in the Lisp_Symbol lrecord_header. */
134   lrecord_type_symbol_value_forward,
135   lrecord_type_symbol_value_varalias,
136   lrecord_type_symbol_value_lisp_magic,
137   lrecord_type_symbol_value_buffer_local,
138   lrecord_type_max_symbol_value_magic = lrecord_type_symbol_value_buffer_local,
139   
140   lrecord_type_symbol,
141   lrecord_type_subr,
142   lrecord_type_cons,
143   lrecord_type_vector,
144   lrecord_type_string,
145   lrecord_type_lcrecord_list,
146   lrecord_type_compiled_function,
147   lrecord_type_weak_list,
148   lrecord_type_bit_vector,
149   lrecord_type_float,
150   lrecord_type_hash_table,
151   lrecord_type_lstream,
152   lrecord_type_process,
153   lrecord_type_charset,
154   lrecord_type_coding_system,
155   lrecord_type_char_table,
156   lrecord_type_char_table_entry,
157   lrecord_type_range_table,
158   lrecord_type_opaque,
159   lrecord_type_opaque_ptr,
160   lrecord_type_buffer,
161   lrecord_type_extent,
162   lrecord_type_extent_info,
163   lrecord_type_extent_auxiliary,
164   lrecord_type_marker,
165   lrecord_type_event,
166   lrecord_type_keymap,
167   lrecord_type_command_builder,
168   lrecord_type_timeout,
169   lrecord_type_specifier,
170   lrecord_type_console,
171   lrecord_type_device,
172   lrecord_type_frame,
173   lrecord_type_window,
174   lrecord_type_window_configuration,
175   lrecord_type_gui_item,
176   lrecord_type_popup_data,
177   lrecord_type_toolbar_button,
178   lrecord_type_color_instance,
179   lrecord_type_font_instance,
180   lrecord_type_image_instance,
181   lrecord_type_glyph,
182   lrecord_type_face,
183   lrecord_type_database,
184   lrecord_type_tooltalk_message,
185   lrecord_type_tooltalk_pattern,
186   lrecord_type_ldap,
187   lrecord_type_pgconn,
188   lrecord_type_pgresult,
189   lrecord_type_count /* must be last */
190 };
191
192 struct lrecord_implementation
193 {
194   const char *name;
195
196   /* `marker' is called at GC time, to make sure that all Lisp_Objects
197      pointed to by this object get properly marked.  It should call
198      the mark_object function on all Lisp_Objects in the object.  If
199      the return value is non-nil, it should be a Lisp_Object to be
200      marked (don't call the mark_object function explicitly on it,
201      because the GC routines will do this).  Doing it this way reduces
202      recursion, so the object returned should preferably be the one
203      with the deepest level of Lisp_Object pointers.  This function
204      can be NULL, meaning no GC marking is necessary. */
205   Lisp_Object (*marker) (Lisp_Object);
206
207   /* `printer' converts the object to a printed representation.
208      This can be NULL; in this case default_object_printer() will be
209      used instead. */
210   void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
211
212   /* `finalizer' is called at GC time when the object is about to
213      be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
214      case).  It should perform any necessary cleanup (e.g. freeing
215      malloc()ed memory).  This can be NULL, meaning no special
216      finalization is necessary.
217
218      WARNING: remember that `finalizer' is called at dump time even
219      though the object is not being freed. */
220   void (*finalizer) (void *header, int for_disksave);
221
222   /* This can be NULL, meaning compare objects with EQ(). */
223   int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
224
225   /* `hash' generates hash values for use with hash tables that have
226      `equal' as their test function.  This can be NULL, meaning use
227      the Lisp_Object itself as the hash.  But, you must still satisfy
228      the constraint that if two objects are `equal', then they *must*
229      hash to the same value in order for hash tables to work properly.
230      This means that `hash' can be NULL only if the `equal' method is
231      also NULL. */
232   unsigned long (*hash) (Lisp_Object, int);
233
234   /* External data layout description */
235   const struct lrecord_description *description;
236
237   /* These functions allow any object type to have builtin property
238      lists that can be manipulated from the lisp level with
239      `get', `put', `remprop', and `object-plist'. */
240   Lisp_Object (*getprop) (Lisp_Object obj, Lisp_Object prop);
241   int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
242   int (*remprop) (Lisp_Object obj, Lisp_Object prop);
243   Lisp_Object (*plist) (Lisp_Object obj);
244
245   /* Only one of `static_size' and `size_in_bytes_method' is non-0.
246      If both are 0, this type is not instantiable by alloc_lcrecord(). */
247   size_t static_size;
248   size_t (*size_in_bytes_method) (const void *header);
249
250   /* The (constant) index into lrecord_implementations_table */
251   enum lrecord_type lrecord_type_index;
252
253   /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
254      one that does not have an lcrecord_header at the front and which
255      is (usually) allocated in frob blocks.  We only use this flag for
256      some consistency checking, and that only when error-checking is
257      enabled. */
258   unsigned int basic_p :1;
259 };
260
261 extern const struct lrecord_implementation *lrecord_implementations_table[];
262
263 #define XRECORD_LHEADER_IMPLEMENTATION(obj) \
264    LHEADER_IMPLEMENTATION (XRECORD_LHEADER (obj))
265 #define LHEADER_IMPLEMENTATION(lh) lrecord_implementations_table[(lh)->type]
266
267 extern int gc_in_progress;
268
269 #define MARKED_RECORD_P(obj) (XRECORD_LHEADER (obj)->mark)
270 #define MARKED_RECORD_HEADER_P(lheader) ((lheader)->mark)
271 #define MARK_RECORD_HEADER(lheader)   ((void) ((lheader)->mark = 1))
272 #define UNMARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 0))
273
274 #define C_READONLY_RECORD_HEADER_P(lheader)  ((lheader)->c_readonly)
275 #define LISP_READONLY_RECORD_HEADER_P(lheader)  ((lheader)->lisp_readonly)
276 #define SET_C_READONLY_RECORD_HEADER(lheader) do {      \
277   struct lrecord_header *SCRRH_lheader = (lheader);     \
278   SCRRH_lheader->c_readonly = 1;                        \
279   SCRRH_lheader->lisp_readonly = 1;                     \
280   SCRRH_lheader->mark = 1;                              \
281 } while (0)
282 #define SET_LISP_READONLY_RECORD_HEADER(lheader) \
283   ((void) ((lheader)->lisp_readonly = 1))
284 #define RECORD_MARKER(lheader) lrecord_markers[(lheader)->type]
285
286 /* External description stuff
287
288    A lrecord external description  is an array  of values.  The  first
289    value of each line is a type, the second  the offset in the lrecord
290    structure.  Following values  are parameters, their  presence, type
291    and number is type-dependant.
292
293    The description ends with a "XD_END" or "XD_SPECIFIER_END" record.
294
295    Some example descriptions :
296
297    static const struct lrecord_description cons_description[] = {
298      { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
299      { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
300      { XD_END }
301    };
302
303    Which means "two lisp objects starting at the 'car' and 'cdr' elements"
304
305   static const struct lrecord_description string_description[] = {
306     { XD_BYTECOUNT,       offsetof (Lisp_String, size) },
307     { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) },
308     { XD_LISP_OBJECT,     offsetof (Lisp_String, plist) },
309     { XD_END }
310   };
311   "A pointer to string data at 'data', the size of the pointed array being the value
312    of the size variable plus 1, and one lisp object at 'plist'"
313
314   The existing types :
315     XD_LISP_OBJECT
316   A Lisp object.  This is also the type to use for pointers to other lrecords.
317
318     XD_LISP_OBJECT_ARRAY
319   An array of Lisp objects or pointers to lrecords.
320   The third element is the count.
321
322     XD_LO_RESET_NIL
323   Lisp objects which will be reset to Qnil when dumping.  Useful for cleaning
324   up caches.
325
326     XD_LO_LINK
327   Link in a linked list of objects of the same type.
328
329     XD_OPAQUE_PTR
330   Pointer to undumpable data.  Must be NULL when dumping.
331
332     XD_STRUCT_PTR
333   Pointer to described struct.  Parameters are number of structures and
334   struct_description.
335
336     XD_OPAQUE_DATA_PTR
337   Pointer to dumpable opaque data.  Parameter is the size of the data.
338   Pointed data must be relocatable without changes.
339
340     XD_C_STRING
341   Pointer to a C string.
342
343     XD_DOC_STRING
344   Pointer to a doc string (C string if positive, opaque value if negative)
345
346     XD_INT_RESET
347   An integer which will be reset to a given value in the dump file.
348
349
350     XD_SIZE_T
351   size_t value.  Used for counts.
352
353     XD_INT
354   int value.  Used for counts.
355
356     XD_LONG
357   long value.  Used for counts.
358
359     XD_BYTECOUNT
360   bytecount value.  Used for counts.
361
362     XD_END
363   Special type indicating the end of the array.
364
365     XD_SPECIFIER_END
366   Special type indicating the end of the array for a specifier.  Extra
367   description is going to be fetched from the specifier methods.
368
369
370   Special macros:
371     XD_INDIRECT(line, delta)
372   Usable where  a "count" or "size"  is requested.  Gives the value of
373   the element which is at line number 'line' in the description (count
374   starts at zero) and adds delta to it.
375 */
376
377 enum lrecord_description_type {
378   XD_LISP_OBJECT_ARRAY,
379   XD_LISP_OBJECT,
380   XD_LO_RESET_NIL,
381   XD_LO_LINK,
382   XD_OPAQUE_PTR,
383   XD_STRUCT_PTR,
384   XD_OPAQUE_DATA_PTR,
385   XD_C_STRING,
386   XD_DOC_STRING,
387   XD_INT_RESET,
388   XD_SIZE_T,
389   XD_INT,
390   XD_LONG,
391   XD_BYTECOUNT,
392   XD_END,
393   XD_SPECIFIER_END
394 };
395
396 struct lrecord_description {
397   enum lrecord_description_type type;
398   int offset;
399   EMACS_INT data1;
400   const struct struct_description *data2;
401 };
402
403 struct struct_description {
404   size_t size;
405   const struct lrecord_description *description;
406 };
407
408 #define XD_INDIRECT(val, delta) (-1-((val)|(delta<<8)))
409
410 #define XD_IS_INDIRECT(code) (code<0)
411 #define XD_INDIRECT_VAL(code) ((-1-code) & 255)
412 #define XD_INDIRECT_DELTA(code) (((-1-code)>>8) & 255)
413
414 #define XD_DYNARR_DESC(base_type, sub_desc) \
415   { XD_STRUCT_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), sub_desc }, \
416   { XD_INT,        offsetof (base_type, cur) }, \
417   { XD_INT_RESET,  offsetof (base_type, max), XD_INDIRECT(1, 0) }
418
419 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
420    DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
421  */
422
423 #if defined (ERROR_CHECK_TYPECHECK)
424 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
425 #else
426 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
427 #endif
428
429 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
430 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
431
432 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
433 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
434
435 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
436 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
437
438 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
439 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
440
441 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
442 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
443
444 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
445 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
446
447 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
448 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype) \
449
450 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
451 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)                       \
452 const struct lrecord_implementation lrecord_##c_name =                  \
453   { name, marker, printer, nuker, equal, hash, desc,                    \
454     getprop, putprop, remprop, plist, size, sizer,                      \
455     lrecord_type_##c_name, basic_p }
456
457 extern Lisp_Object (*lrecord_markers[]) (Lisp_Object);
458
459 #define INIT_LRECORD_IMPLEMENTATION(type) do {                          \
460   lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
461   lrecord_markers[lrecord_type_##type] =                                \
462     lrecord_implementations_table[lrecord_type_##type]->marker;         \
463 } while (0)
464
465 #define LRECORDP(a) (XTYPE (a) == Lisp_Type_Record)
466 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
467
468 #define RECORD_TYPEP(x, ty) \
469   (LRECORDP (x) && XRECORD_LHEADER (x)->type == (ty))
470
471 /* NOTE: the DECLARE_LRECORD() must come before the associated
472    DEFINE_LRECORD_*() or you will get compile errors.
473
474    Furthermore, you always need to put the DECLARE_LRECORD() in a header
475    file, and make sure the header file is included in inline.c, even
476    if the type is private to a particular file.  Otherwise, you will
477    get undefined references for the error_check_foo() inline function
478    under GCC. */
479
480 #ifdef ERROR_CHECK_TYPECHECK
481
482 # define DECLARE_LRECORD(c_name, structtype)                    \
483 extern const struct lrecord_implementation lrecord_##c_name;    \
484 INLINE_HEADER structtype *                                      \
485 error_check_##c_name (Lisp_Object obj);                         \
486 INLINE_HEADER structtype *                                      \
487 error_check_##c_name (Lisp_Object obj)                          \
488 {                                                               \
489   assert (RECORD_TYPEP (obj, lrecord_type_##c_name));           \
490   return (structtype *) XPNTR (obj);                            \
491 }                                                               \
492 extern Lisp_Object Q##c_name##p
493
494 # define DECLARE_NONRECORD(c_name, type_enum, structtype)       \
495 INLINE_HEADER structtype *                                      \
496 error_check_##c_name (Lisp_Object obj);                         \
497 INLINE_HEADER structtype *                                      \
498 error_check_##c_name (Lisp_Object obj)                          \
499 {                                                               \
500   assert (XTYPE (obj) == type_enum);                            \
501   return (structtype *) XPNTR (obj);                            \
502 }                                                               \
503 extern Lisp_Object Q##c_name##p
504
505 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
506 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
507
508 # define XSETRECORD(var, p, c_name) do                          \
509 {                                                               \
510   XSETOBJ (var, Lisp_Type_Record, p);                           \
511   assert (RECORD_TYPEP (var, lrecord_type_##c_name));           \
512 } while (0)
513
514 #else /* not ERROR_CHECK_TYPECHECK */
515
516 # define DECLARE_LRECORD(c_name, structtype)                    \
517 extern Lisp_Object Q##c_name##p;                                \
518 extern const struct lrecord_implementation lrecord_##c_name
519 # define DECLARE_NONRECORD(c_name, type_enum, structtype)       \
520 extern Lisp_Object Q##c_name##p
521 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
522 # define XNONRECORD(x, c_name, type_enum, structtype)           \
523   ((structtype *) XPNTR (x))
524 # define XSETRECORD(var, p, c_name) XSETOBJ (var, Lisp_Type_Record, p)
525
526 #endif /* not ERROR_CHECK_TYPECHECK */
527
528 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_type_##c_name)
529
530 /* Note: we now have two different kinds of type-checking macros.
531    The "old" kind has now been renamed CONCHECK_foo.  The reason for
532    this is that the CONCHECK_foo macros signal a continuable error,
533    allowing the user (through debug-on-error) to substitute a different
534    value and return from the signal, which causes the lvalue argument
535    to get changed.  Quite a lot of code would crash if that happened,
536    because it did things like
537
538    foo = XCAR (list);
539    CHECK_STRING (foo);
540
541    and later on did XSTRING (XCAR (list)), assuming that the type
542    is correct (when it might be wrong, if the user substituted a
543    correct value in the debugger).
544
545    To get around this, I made all the CHECK_foo macros signal a
546    non-continuable error.  Places where a continuable error is OK
547    (generally only when called directly on the argument of a Lisp
548    primitive) should be changed to use CONCHECK().
549
550    FSF Emacs does not have this problem because RMS took the cheesy
551    way out and disabled returning from a signal entirely. */
552
553 #define CONCHECK_RECORD(x, c_name) do {                 \
554  if (!RECORD_TYPEP (x, lrecord_type_##c_name))          \
555    x = wrong_type_argument (Q##c_name##p, x);           \
556 }  while (0)
557 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
558  if (XTYPE (x) != lisp_enum)                            \
559    x = wrong_type_argument (predicate, x);              \
560  } while (0)
561 #define CHECK_RECORD(x, c_name) do {                    \
562  if (!RECORD_TYPEP (x, lrecord_type_##c_name))          \
563    dead_wrong_type_argument (Q##c_name##p, x);          \
564  } while (0)
565 #define CHECK_NONRECORD(x, lisp_enum, predicate) do {   \
566  if (XTYPE (x) != lisp_enum)                            \
567    dead_wrong_type_argument (predicate, x);             \
568  } while (0)
569
570 void *alloc_lcrecord (size_t size, const struct lrecord_implementation *);
571
572 #define alloc_lcrecord_type(type, lrecord_implementation) \
573   ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
574
575 /* Copy the data from one lcrecord structure into another, but don't
576    overwrite the header information. */
577
578 #define copy_lcrecord(dst, src)                                 \
579   memcpy ((char *) (dst) + sizeof (struct lcrecord_header),     \
580           (char *) (src) + sizeof (struct lcrecord_header),     \
581           sizeof (*(dst)) - sizeof (struct lcrecord_header))
582
583 #define zero_lcrecord(lcr)                                      \
584    memset ((char *) (lcr) + sizeof (struct lcrecord_header), 0, \
585            sizeof (*(lcr)) - sizeof (struct lcrecord_header))
586
587 #endif /* INCLUDED_lrecord_h_ */