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.
5 This file is part of SXEmacs
7 SXEmacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 SXEmacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 /* Synched up with: Not in FSF. */
23 #ifndef INCLUDED_lrecord_h_
24 #define INCLUDED_lrecord_h_
26 /* The "lrecord" type of Lisp object is used for all object types
27 other than a few simple ones. This allows many types to be
28 implemented but only a few bits required in a Lisp object for type
29 information. (The tradeoff is that each object has its type marked
30 in it, thereby increasing its size.) All lrecords begin with a
31 `struct lrecord_header', which identifies the lisp object type, by
32 providing an index into a table of `struct lrecord_implementation',
33 which describes the behavior of the lisp object. It also contains
36 Lrecords are of two types: straight lrecords, and lcrecords.
37 Straight lrecords are used for those types of objects that have
38 their own allocation routines (typically allocated out of 2K chunks
39 of memory called `frob blocks'). These objects have a `struct
40 lrecord_header' at the top, containing only the bits needed to find
41 the lrecord_implementation for the object. There are special
42 routines in alloc.c to deal with each such object type.
44 Lcrecords are used for less common sorts of objects that don't do
45 their own allocation. Each such object is malloc()ed individually,
46 and the objects are chained together through a `next' pointer.
47 Lcrecords have a `struct lcrecord_header' at the top, which
48 contains a `struct lrecord_header' and a `next' pointer, and are
49 allocated using alloc_lcrecord().
51 Creating a new lcrecord type is fairly easy; just follow the
52 lead of some existing type (e.g. hash tables). Note that you
53 do not need to supply all the methods (see below); reasonable
54 defaults are provided for many of them. Alternatively, if you're
55 just looking for a way of encapsulating data (which possibly
56 could contain Lisp_Objects in it), you may well be able to use
59 struct lrecord_header {
60 /* index into lrecord_implementations_table[] */
63 /* If `mark' is 0 after the GC mark phase, the object will be freed
64 during the GC sweep phase. There are 2 ways that `mark' can be 1:
65 - by being referenced from other objects during the GC mark phase
66 - because it is permanently on, for c_readonly objects */
69 /* 1 if the object resides in logically read-only space, and does not
70 reference other non-c_readonly objects.
71 Invariant: if (c_readonly == 1), then (mark == 1 && lisp_readonly == 1) */
72 unsigned int c_readonly:1;
74 /* 1 if the object is readonly from lisp */
75 unsigned int lisp_readonly:1;
77 long unsigned int hash_cache;
78 unsigned int morphisms:/*number_of_cat_morphism_kinds => */6;
81 struct lrecord_implementation;
82 int lrecord_type_index(const struct lrecord_implementation *implementation);
84 #define set_lheader_implementation(header,imp) \
86 struct lrecord_header* SLI_header = (header); \
87 SLI_header->type = (imp)->lrecord_type_index; \
88 SLI_header->mark = 0; \
89 SLI_header->c_readonly = 0; \
90 SLI_header->lisp_readonly = 0; \
93 struct lcrecord_header {
94 struct lrecord_header lheader;
96 #if !defined HAVE_BDWGC || !defined EF_USE_BDWGC
97 /* The `next' field is normally used to chain all lcrecords together
98 so that the GC can find (and free) all of them.
99 `alloc_lcrecord' threads lcrecords together.
101 The `next' field may be used for other purposes as long as some
102 other mechanism is provided for letting the GC do its work.
104 For example, the event and marker object types allocate members
105 out of memory chunks, and are able to find all unmarked members
106 by sweeping through the elements of the list of chunks. */
107 struct lcrecord_header *next;
110 /* The `uid' field is just for debugging/printing convenience.
111 Having this slot doesn't hurt us much spacewise, since an
112 lcrecord already has the above slots plus malloc overhead. */
115 /* The `free' field is a flag that indicates whether this lcrecord
116 is on a "free list". Free lists are used to minimize the number
117 of calls to malloc() when we're repeatedly allocating and freeing
118 a number of the same sort of lcrecord. Lcrecords on a free list
119 always get marked in a different fashion, so we can use this flag
120 as a sanity check to make sure that free lists only have freed
121 lcrecords and there are no freed lcrecords elsewhere. */
125 /* Used for lcrecords in an lcrecord-list. */
126 struct free_lcrecord_header {
127 struct lcrecord_header lcheader;
132 /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast.
133 #### This should be replaced by a symbol_value_magic_p flag
134 in the Lisp_Symbol lrecord_header. */
135 lrecord_type_symbol_value_forward, /* 0 */
136 lrecord_type_symbol_value_varalias,
137 lrecord_type_symbol_value_lisp_magic,
138 lrecord_type_symbol_value_buffer_local,
139 lrecord_type_max_symbol_value_magic = /* 3 */
140 lrecord_type_symbol_value_buffer_local,
142 lrecord_type_symbol, /* 4 */
147 lrecord_type_lcrecord_list,
148 lrecord_type_compiled_function, /* 10 */
149 lrecord_type_weak_list,
150 lrecord_type_bit_vector,
151 lrecord_type_hash_table,
152 lrecord_type_lstream,
153 lrecord_type_process,
154 lrecord_type_charset,
155 lrecord_type_coding_system,
156 lrecord_type_char_table,
157 lrecord_type_char_table_entry,
158 lrecord_type_range_table, /* 20 */
160 lrecord_type_opaque_ptr,
161 lrecord_type_dynacat,
164 lrecord_type_extent_info,
165 lrecord_type_extent_auxiliary,
167 lrecord_type_event_queue,
168 lrecord_type_event_prique, /* 30 */
169 lrecord_type_worker_job,
171 lrecord_type_command_builder,
172 lrecord_type_timeout,
173 lrecord_type_specifier,
174 lrecord_type_console,
178 lrecord_type_window_configuration, /* 40 */
179 lrecord_type_gui_item,
180 lrecord_type_popup_data,
181 lrecord_type_toolbar_button,
182 lrecord_type_color_instance,
183 lrecord_type_font_instance,
184 lrecord_type_image_instance,
187 lrecord_type_database,
190 lrecord_type_pgresult,
191 lrecord_type_devmode,
192 lrecord_type_case_table,
193 lrecord_type_emacs_ffi,
194 lrecord_type_emacs_gtk_object,
195 lrecord_type_emacs_gtk_boxed,
196 lrecord_type_ffiobject, /* 60 */
197 lrecord_type_evp_pkey,
198 lrecord_type_ssl_conn,
200 lrecord_type_skiplist,
202 lrecord_type_audio_device,
203 lrecord_type_media_stream,
204 lrecord_type_media_thread,
207 lrecord_first_ent_type = lrecord_type_marker,
208 lrecord_type_float, /* 70 */
215 lrecord_type_quatern,
216 lrecord_type_indef, /* 78 */
217 lrecord_type_free, /* only used for "free" lrecords */
218 lrecord_type_undefined, /* only used for debugging */
219 lrecord_type_last_built_in_type /* must be last */
222 extern unsigned int lrecord_type_count;
224 struct lrecord_implementation {
227 /* `marker' is called at GC time, to make sure that all Lisp_Objects
228 pointed to by this object get properly marked. It should call
229 the mark_object function on all Lisp_Objects in the object. If
230 the return value is non-nil, it should be a Lisp_Object to be
231 marked (don't call the mark_object function explicitly on it,
232 because the GC routines will do this). Doing it this way reduces
233 recursion, so the object returned should preferably be the one
234 with the deepest level of Lisp_Object pointers. This function
235 can be NULL, meaning no GC marking is necessary. */
236 Lisp_Object(*marker) (Lisp_Object);
238 /* `printer' converts the object to a printed representation.
239 This can be NULL; in this case default_object_printer() will be
241 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
243 /* `finalizer' is called at GC time when the object is about to
244 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
245 case). It should perform any necessary cleanup (e.g. freeing
246 malloc()ed memory). This can be NULL, meaning no special
247 finalization is necessary.
249 WARNING: remember that `finalizer' is called at dump time even
250 though the object is not being freed. */
251 void (*finalizer) (void *header, int for_disksave);
253 /* This can be NULL, meaning compare objects with EQ(). */
254 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
256 /* `hash' generates hash values for use with hash tables that have
257 `equal' as their test function. This can be NULL, meaning use
258 the Lisp_Object itself as the hash. But, you must still satisfy
259 the constraint that if two objects are `equal', then they *must*
260 hash to the same value in order for hash tables to work properly.
261 This means that `hash' can be NULL only if the `equal' method is
263 long unsigned int (*hash) (Lisp_Object, int);
265 /* External data layout description */
266 const struct lrecord_description *description;
268 /* These functions allow any object type to have builtin property
269 lists that can be manipulated from the lisp level with
270 `get', `put', `remprop', and `object-plist'. */
271 Lisp_Object(*getprop) (Lisp_Object obj, Lisp_Object prop);
272 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
273 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
274 Lisp_Object(*plist) (Lisp_Object obj);
276 /* Only one of `static_size' and `size_in_bytes_method' is non-0.
277 If both are 0, this type is not instantiable by alloc_lcrecord(). */
279 size_t(*size_in_bytes_method) (const void *header);
281 /* The (constant) index into lrecord_implementations_table */
282 enum lrecord_type lrecord_type_index;
284 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
285 one that does not have an lcrecord_header at the front and which
286 is (usually) allocated in frob blocks. We only use this flag for
287 some consistency checking, and that only when error-checking is
292 /* All the built-in lisp object types are enumerated in `enum record_type'.
293 Additional ones may be defined by a module (none yet). We leave some
294 room in `lrecord_implementations_table' for such new lisp object types. */
295 #define MODULE_DEFINABLE_TYPE_COUNT 32
297 extern const struct lrecord_implementation
298 *lrecord_implementations_table[(unsigned int)lrecord_type_last_built_in_type
299 + MODULE_DEFINABLE_TYPE_COUNT];
301 #define XRECORD_LHEADER_IMPLEMENTATION(obj) \
302 LHEADER_IMPLEMENTATION (XRECORD_LHEADER (obj))
303 #define LHEADER_IMPLEMENTATION(lh) lrecord_implementations_table[(lh)->type]
305 extern int gc_in_progress;
307 #define MARKED_RECORD_P(obj) (XRECORD_LHEADER (obj)->mark)
308 #define MARKED_RECORD_HEADER_P(lheader) ((lheader)->mark)
309 #define MARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 1))
310 #define UNMARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 0))
312 #define C_READONLY_RECORD_HEADER_P(lheader) ((lheader)->c_readonly)
313 #define LISP_READONLY_RECORD_HEADER_P(lheader) ((lheader)->lisp_readonly)
314 #define SET_C_READONLY_RECORD_HEADER(lheader) \
316 struct lrecord_header *SCRRH_lheader = (lheader); \
317 SCRRH_lheader->c_readonly = 1; \
318 SCRRH_lheader->lisp_readonly = 1; \
319 SCRRH_lheader->mark = 1; \
321 #define SET_LISP_READONLY_RECORD_HEADER(lheader) \
322 ((void) ((lheader)->lisp_readonly = 1))
323 #define RECORD_MARKER(lheader) lrecord_markers[(lheader)->type]
325 /* External description stuff
327 A lrecord external description is an array of values. The first
328 value of each line is a type, the second the offset in the lrecord
329 structure. Following values are parameters, their presence, type
330 and number is type-dependent.
332 The description ends with a "XD_END" or "XD_SPECIFIER_END" record.
334 Some example descriptions :
336 static const struct lrecord_description cons_description[] = {
337 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
338 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
342 Which means "two lisp objects starting at the 'car' and 'cdr' elements"
344 static const struct lrecord_description string_description[] = {
345 { XD_BYTECOUNT, offsetof (Lisp_String, size) },
346 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) },
347 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
350 "A pointer to string data at 'data', the size of the pointed array being the value
351 of the size variable plus 1, and one lisp object at 'plist'"
355 A Lisp object. This is also the type to use for pointers to other lrecords.
358 An array of Lisp objects or pointers to lrecords.
359 The third element is the count.
362 Link in a linked list of objects of the same type.
365 Pointer to undumpable data. Must be NULL when dumping.
368 Pointer to described struct. Parameters are number of structures and
372 Pointer to dumpable opaque data. Parameter is the size of the data.
373 Pointed data must be relocatable without changes.
376 Pointer to a C string.
379 Pointer to a doc string (C string if positive, opaque value if negative)
382 An integer which will be reset to a given value in the dump file.
385 size_t value. Used for counts.
388 int value. Used for counts.
391 long value. Used for counts.
394 bytecount value. Used for counts.
397 Special type indicating the end of the array.
400 Special type indicating the end of the array for a specifier. Extra
401 description is going to be fetched from the specifier methods.
404 XD_INDIRECT(line, delta)
405 Usable where a "count" or "size" is requested. Gives the value of
406 the element which is at line number 'line' in the description (count
407 starts at zero) and adds delta to it.
410 enum lrecord_description_type {
411 XD_LISP_OBJECT_ARRAY,
428 struct lrecord_description {
429 enum lrecord_description_type type;
432 const struct struct_description *data2;
435 struct struct_description {
437 const struct lrecord_description *description;
440 #define XD_INDIRECT(val, delta) (-1-((val)|(delta<<8)))
442 #define XD_IS_INDIRECT(code) (code<0)
443 #define XD_INDIRECT_VAL(code) ((-1-code) & 255)
444 #define XD_INDIRECT_DELTA(code) (((-1-code)>>8) & 255)
446 #define XD_DYNARR_DESC(base_type, sub_desc) \
447 { XD_STRUCT_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), sub_desc }, \
448 { XD_INT, offsetof (base_type, cur) }, \
449 { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) }
451 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
452 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
455 #if defined (ERROR_CHECK_TYPECHECK)
456 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
458 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
461 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
462 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
464 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
465 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
467 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
468 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
470 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
471 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
473 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
474 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
476 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
477 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
479 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
480 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype) \
482 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
483 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
484 const struct lrecord_implementation lrecord_##c_name = \
485 { name, marker, printer, nuker, equal, hash, desc, \
486 getprop, putprop, remprop, plist, size, sizer, \
487 lrecord_type_##c_name, basic_p }
489 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
490 DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
492 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
493 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
495 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
496 DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
498 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
499 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
501 #define MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
502 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
503 unsigned int lrecord_type_##c_name; \
504 struct lrecord_implementation lrecord_##c_name = \
505 { name, marker, printer, nuker, equal, hash, desc, \
506 getprop, putprop, remprop, plist, size, sizer, \
507 lrecord_type_last_built_in_type, basic_p }
509 extern Lisp_Object(*lrecord_markers[]) (Lisp_Object);
511 #define INIT_LRECORD_IMPLEMENTATION(type) do { \
512 lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
513 lrecord_markers[lrecord_type_##type] = \
514 lrecord_implementations_table[lrecord_type_##type]->marker; \
517 #define INIT_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
518 lrecord_type_##type = lrecord_type_count++; \
519 lrecord_##type.lrecord_type_index = (enum lrecord_type) lrecord_type_##type; \
520 INIT_LRECORD_IMPLEMENTATION(type); \
523 #define LRECORDP(a) (XTYPE (a) == Lisp_Type_Record)
524 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
526 #define RECORD_TYPEP(x, ty) \
527 (LRECORDP (x) && (((unsigned int)(XRECORD_LHEADER (x)->type)) == ((unsigned int)(ty))))
529 #if defined(EF_USE_POM)
530 #define XRECORD_MTX(x) (XRECORD_LHEADER(x)->objmtx)
531 #define XLOCKRECORD(x) \
532 SXE_MUTEX_LOCK(&(XRECORD_MTX(x)))
533 #define XUNLOCKRECORD(x) \
534 SXE_MUTEX_UNLOCK(&(XRECORD_MTX(x)))
536 #define XRECORD_MTX(x)
537 #define XLOCKRECORD(x)
538 #define XUNLOCKRECORD(x)
541 /* Steps to create a new object:
543 1. Declare the struct for your object in a header file somewhere.
544 Remember that it must begin with
546 struct lcrecord_header header;
548 2. Put a DECLARE_LRECORD() for the object below the struct definition,
549 along with the standard XFOO/XSETFOO junk.
551 3. Add this header file to inline.c.
553 4. Create the methods for your object. Note that technically you don't
554 need any, but you will almost always want at least a mark method.
556 5. Define your object with DEFINE_LRECORD_IMPLEMENTATION() or some
559 6. Include the header file in the .c file where you defined the object.
561 7. Put a call to INIT_LRECORD_IMPLEMENTATION() for the object in the
562 .c file's syms_of_foo() function.
564 8. Add a type enum for the object to enum lrecord_type, earlier in this
569 ------------------------------ in toolbar.h -----------------------------
571 struct toolbar_button
573 struct lcrecord_header header;
578 Lisp_Object up_glyph;
579 Lisp_Object down_glyph;
580 Lisp_Object disabled_glyph;
582 Lisp_Object cap_up_glyph;
583 Lisp_Object cap_down_glyph;
584 Lisp_Object cap_disabled_glyph;
586 Lisp_Object callback;
587 Lisp_Object enabled_p;
588 Lisp_Object help_string;
602 DECLARE_LRECORD (toolbar_button, struct toolbar_button);
603 #define XTOOLBAR_BUTTON(x) XRECORD (x, toolbar_button, struct toolbar_button)
604 #define XSETTOOLBAR_BUTTON(x, p) XSETRECORD (x, p, toolbar_button)
605 #define TOOLBAR_BUTTONP(x) RECORDP (x, toolbar_button)
606 #define CHECK_TOOLBAR_BUTTON(x) CHECK_RECORD (x, toolbar_button)
607 #define CONCHECK_TOOLBAR_BUTTON(x) CONCHECK_RECORD (x, toolbar_button)
609 ------------------------------ in toolbar.c -----------------------------
611 #include "ui/toolbar.h"
616 mark_toolbar_button (Lisp_Object obj)
618 struct toolbar_button *data = XTOOLBAR_BUTTON (obj);
619 mark_object (data->next);
620 mark_object (data->frame);
621 mark_object (data->up_glyph);
622 mark_object (data->down_glyph);
623 mark_object (data->disabled_glyph);
624 mark_object (data->cap_up_glyph);
625 mark_object (data->cap_down_glyph);
626 mark_object (data->cap_disabled_glyph);
627 mark_object (data->callback);
628 mark_object (data->enabled_p);
629 return data->help_string;
632 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-button", toolbar_button,
633 mark_toolbar_button, 0, 0, 0, 0, 0,
634 struct toolbar_button);
639 syms_of_toolbar (void)
641 INIT_LRECORD_IMPLEMENTATION (toolbar_button);
646 ------------------------------ in inline.c -----------------------------
649 #include "ui/toolbar.h"
652 ------------------------------ in lrecord.h -----------------------------
657 lrecord_type_toolbar_button,
665 Note: Object types defined in external dynamically-loaded modules (not
666 part of the XEmacs main source code) should use DECLARE_EXTERNAL_LRECORD
667 and DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION rather than DECLARE_LRECORD
668 and DEFINE_LRECORD_IMPLEMENTATION.
672 #ifdef ERROR_CHECK_TYPECHECK
674 # define DECLARE_LRECORD(c_name, structtype) \
675 extern const struct lrecord_implementation lrecord_##c_name; \
676 extern_inline structtype * \
677 error_check_##c_name (Lisp_Object obj); \
678 extern_inline structtype * \
679 error_check_##c_name (Lisp_Object obj) \
681 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
682 return (structtype *) XPNTR (obj); \
684 extern Lisp_Object Q##c_name##p
686 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
687 extern unsigned int lrecord_type_##c_name; \
688 extern struct lrecord_implementation lrecord_##c_name; \
689 extern_inline structtype * \
690 error_check_##c_name (Lisp_Object obj); \
691 extern_inline structtype * \
692 error_check_##c_name (Lisp_Object obj) \
694 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
695 return (structtype *) XPNTR (obj); \
697 extern Lisp_Object Q##c_name##p
699 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
700 extern_inline structtype * \
701 error_check_##c_name (Lisp_Object obj); \
702 extern_inline structtype * \
703 error_check_##c_name (Lisp_Object obj) \
705 assert (XTYPE (obj) == type_enum); \
706 return (structtype *) XPNTR (obj); \
708 extern Lisp_Object Q##c_name##p
710 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
711 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
713 # define XSETRECORD(var, p, c_name) do \
716 assert (RECORD_TYPEP (var, lrecord_type_##c_name)); \
719 #else /* not ERROR_CHECK_TYPECHECK */
721 # define DECLARE_LRECORD(c_name, structtype) \
722 extern Lisp_Object Q##c_name##p; \
723 extern const struct lrecord_implementation lrecord_##c_name
724 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
725 extern Lisp_Object Q##c_name##p; \
726 extern unsigned int lrecord_type_##c_name; \
727 extern struct lrecord_implementation lrecord_##c_name
728 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
729 extern Lisp_Object Q##c_name##p
730 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
731 # define XNONRECORD(x, c_name, type_enum, structtype) \
732 ((structtype *) XPNTR (x))
733 # define XSETRECORD(var, p, c_name) XSETOBJ (var, p)
735 #endif /* not ERROR_CHECK_TYPECHECK */
737 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_type_##c_name)
739 /* Note: we now have two different kinds of type-checking macros.
740 The "old" kind has now been renamed CONCHECK_foo. The reason for
741 this is that the CONCHECK_foo macros signal a continuable error,
742 allowing the user (through debug-on-error) to substitute a different
743 value and return from the signal, which causes the lvalue argument
744 to get changed. Quite a lot of code would crash if that happened,
745 because it did things like
750 and later on did XSTRING (XCAR (list)), assuming that the type
751 is correct (when it might be wrong, if the user substituted a
752 correct value in the debugger).
754 To get around this, I made all the CHECK_foo macros signal a
755 non-continuable error. Places where a continuable error is OK
756 (generally only when called directly on the argument of a Lisp
757 primitive) should be changed to use CONCHECK().
759 FSF Emacs does not have this problem because RMS took the cheesy
760 way out and disabled returning from a signal entirely. */
762 #define CONCHECK_RECORD(x, c_name) do { \
763 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
764 x = wrong_type_argument (Q##c_name##p, x); \
766 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
767 if (XTYPE (x) != lisp_enum) \
768 x = wrong_type_argument (predicate, x); \
770 #define CHECK_RECORD(x, c_name) do { \
771 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
772 dead_wrong_type_argument (Q##c_name##p, x); \
774 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
775 if (XTYPE (x) != lisp_enum) \
776 dead_wrong_type_argument (predicate, x); \
779 void *alloc_lcrecord(size_t size, const struct lrecord_implementation *);
781 #define alloc_lcrecord_type(type, lrecord_implementation) \
782 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
784 /* Copy the data from one lcrecord structure into another, but don't
785 overwrite the header information. */
787 #define copy_lcrecord(dst, src) \
788 memcpy ((char *) (dst) + sizeof (struct lcrecord_header), \
789 (char *) (src) + sizeof (struct lcrecord_header), \
790 sizeof (*(dst)) - sizeof (struct lcrecord_header))
792 #define zero_lcrecord(lcr) \
793 memset ((char *) (lcr) + sizeof (struct lcrecord_header), 0, \
794 sizeof (*(lcr)) - sizeof (struct lcrecord_header))
796 #endif /* INCLUDED_lrecord_h_ */