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_ffiobject, /* 60 */
195 lrecord_type_evp_pkey,
196 lrecord_type_ssl_conn,
198 lrecord_type_skiplist,
200 lrecord_type_audio_device,
201 lrecord_type_media_stream,
202 lrecord_type_media_thread,
205 lrecord_first_ent_type = lrecord_type_marker,
206 lrecord_type_float, /* 70 */
213 lrecord_type_quatern,
214 lrecord_type_indef, /* 78 */
215 lrecord_type_free, /* only used for "free" lrecords */
216 lrecord_type_undefined, /* only used for debugging */
217 lrecord_type_last_built_in_type /* must be last */
220 extern unsigned int lrecord_type_count;
222 struct lrecord_implementation {
225 /* `marker' is called at GC time, to make sure that all Lisp_Objects
226 pointed to by this object get properly marked. It should call
227 the mark_object function on all Lisp_Objects in the object. If
228 the return value is non-nil, it should be a Lisp_Object to be
229 marked (don't call the mark_object function explicitly on it,
230 because the GC routines will do this). Doing it this way reduces
231 recursion, so the object returned should preferably be the one
232 with the deepest level of Lisp_Object pointers. This function
233 can be NULL, meaning no GC marking is necessary. */
234 Lisp_Object(*marker) (Lisp_Object);
236 /* `printer' converts the object to a printed representation.
237 This can be NULL; in this case default_object_printer() will be
239 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
241 /* `finalizer' is called at GC time when the object is about to
242 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
243 case). It should perform any necessary cleanup (e.g. freeing
244 malloc()ed memory). This can be NULL, meaning no special
245 finalization is necessary.
247 WARNING: remember that `finalizer' is called at dump time even
248 though the object is not being freed. */
249 void (*finalizer) (void *header, int for_disksave);
251 /* This can be NULL, meaning compare objects with EQ(). */
252 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
254 /* `hash' generates hash values for use with hash tables that have
255 `equal' as their test function. This can be NULL, meaning use
256 the Lisp_Object itself as the hash. But, you must still satisfy
257 the constraint that if two objects are `equal', then they *must*
258 hash to the same value in order for hash tables to work properly.
259 This means that `hash' can be NULL only if the `equal' method is
261 long unsigned int (*hash) (Lisp_Object, int);
263 /* External data layout description */
264 const struct lrecord_description *description;
266 /* These functions allow any object type to have builtin property
267 lists that can be manipulated from the lisp level with
268 `get', `put', `remprop', and `object-plist'. */
269 Lisp_Object(*getprop) (Lisp_Object obj, Lisp_Object prop);
270 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
271 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
272 Lisp_Object(*plist) (Lisp_Object obj);
274 /* Only one of `static_size' and `size_in_bytes_method' is non-0.
275 If both are 0, this type is not instantiable by alloc_lcrecord(). */
277 size_t(*size_in_bytes_method) (const void *header);
279 /* The (constant) index into lrecord_implementations_table */
280 enum lrecord_type lrecord_type_index;
282 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
283 one that does not have an lcrecord_header at the front and which
284 is (usually) allocated in frob blocks. We only use this flag for
285 some consistency checking, and that only when error-checking is
290 /* All the built-in lisp object types are enumerated in `enum record_type'.
291 Additional ones may be defined by a module (none yet). We leave some
292 room in `lrecord_implementations_table' for such new lisp object types. */
293 #define MODULE_DEFINABLE_TYPE_COUNT 32
295 extern const struct lrecord_implementation
296 *lrecord_implementations_table[(unsigned int)lrecord_type_last_built_in_type
297 + MODULE_DEFINABLE_TYPE_COUNT];
299 #define XRECORD_LHEADER_IMPLEMENTATION(obj) \
300 LHEADER_IMPLEMENTATION (XRECORD_LHEADER (obj))
301 #define LHEADER_IMPLEMENTATION(lh) lrecord_implementations_table[(lh)->type]
303 extern int gc_in_progress;
305 #define MARKED_RECORD_P(obj) (XRECORD_LHEADER (obj)->mark)
306 #define MARKED_RECORD_HEADER_P(lheader) ((lheader)->mark)
307 #define MARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 1))
308 #define UNMARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 0))
310 #define C_READONLY_RECORD_HEADER_P(lheader) ((lheader)->c_readonly)
311 #define LISP_READONLY_RECORD_HEADER_P(lheader) ((lheader)->lisp_readonly)
312 #define SET_C_READONLY_RECORD_HEADER(lheader) \
314 struct lrecord_header *SCRRH_lheader = (lheader); \
315 SCRRH_lheader->c_readonly = 1; \
316 SCRRH_lheader->lisp_readonly = 1; \
317 SCRRH_lheader->mark = 1; \
319 #define SET_LISP_READONLY_RECORD_HEADER(lheader) \
320 ((void) ((lheader)->lisp_readonly = 1))
321 #define RECORD_MARKER(lheader) lrecord_markers[(lheader)->type]
323 /* External description stuff
325 A lrecord external description is an array of values. The first
326 value of each line is a type, the second the offset in the lrecord
327 structure. Following values are parameters, their presence, type
328 and number is type-dependent.
330 The description ends with a "XD_END" or "XD_SPECIFIER_END" record.
332 Some example descriptions :
334 static const struct lrecord_description cons_description[] = {
335 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
336 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
340 Which means "two lisp objects starting at the 'car' and 'cdr' elements"
342 static const struct lrecord_description string_description[] = {
343 { XD_BYTECOUNT, offsetof (Lisp_String, size) },
344 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) },
345 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
348 "A pointer to string data at 'data', the size of the pointed array being the value
349 of the size variable plus 1, and one lisp object at 'plist'"
353 A Lisp object. This is also the type to use for pointers to other lrecords.
356 An array of Lisp objects or pointers to lrecords.
357 The third element is the count.
360 Link in a linked list of objects of the same type.
363 Pointer to undumpable data. Must be NULL when dumping.
366 Pointer to described struct. Parameters are number of structures and
370 Pointer to dumpable opaque data. Parameter is the size of the data.
371 Pointed data must be relocatable without changes.
374 Pointer to a C string.
377 Pointer to a doc string (C string if positive, opaque value if negative)
380 An integer which will be reset to a given value in the dump file.
383 size_t value. Used for counts.
386 int value. Used for counts.
389 long value. Used for counts.
392 bytecount value. Used for counts.
395 Special type indicating the end of the array.
398 Special type indicating the end of the array for a specifier. Extra
399 description is going to be fetched from the specifier methods.
402 XD_INDIRECT(line, delta)
403 Usable where a "count" or "size" is requested. Gives the value of
404 the element which is at line number 'line' in the description (count
405 starts at zero) and adds delta to it.
408 enum lrecord_description_type {
409 XD_LISP_OBJECT_ARRAY,
426 struct lrecord_description {
427 enum lrecord_description_type type;
430 const struct struct_description *data2;
433 struct struct_description {
435 const struct lrecord_description *description;
438 #define XD_INDIRECT(val, delta) (-1-((val)|(delta<<8)))
440 #define XD_IS_INDIRECT(code) (code<0)
441 #define XD_INDIRECT_VAL(code) ((-1-code) & 255)
442 #define XD_INDIRECT_DELTA(code) (((-1-code)>>8) & 255)
444 #define XD_DYNARR_DESC(base_type, sub_desc) \
445 { XD_STRUCT_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), sub_desc }, \
446 { XD_INT, offsetof (base_type, cur) }, \
447 { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) }
449 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
450 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
453 #if defined (ERROR_CHECK_TYPECHECK)
454 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
456 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
459 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
460 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
462 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
463 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
465 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
466 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
468 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
469 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
471 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
472 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
474 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
475 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
477 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
478 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype) \
480 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
481 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
482 const struct lrecord_implementation lrecord_##c_name = \
483 { name, marker, printer, nuker, equal, hash, desc, \
484 getprop, putprop, remprop, plist, size, sizer, \
485 lrecord_type_##c_name, basic_p }
487 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
488 DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
490 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
491 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
493 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
494 DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
496 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
497 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
499 #define MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
500 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
501 unsigned int lrecord_type_##c_name; \
502 struct lrecord_implementation lrecord_##c_name = \
503 { name, marker, printer, nuker, equal, hash, desc, \
504 getprop, putprop, remprop, plist, size, sizer, \
505 lrecord_type_last_built_in_type, basic_p }
507 extern Lisp_Object(*lrecord_markers[]) (Lisp_Object);
509 #define INIT_LRECORD_IMPLEMENTATION(type) do { \
510 lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
511 lrecord_markers[lrecord_type_##type] = \
512 lrecord_implementations_table[lrecord_type_##type]->marker; \
515 #define INIT_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
516 lrecord_type_##type = lrecord_type_count++; \
517 lrecord_##type.lrecord_type_index = (enum lrecord_type) lrecord_type_##type; \
518 INIT_LRECORD_IMPLEMENTATION(type); \
521 #define LRECORDP(a) (XTYPE (a) == Lisp_Type_Record)
522 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
524 #define RECORD_TYPEP(x, ty) \
525 (LRECORDP (x) && (((unsigned int)(XRECORD_LHEADER (x)->type)) == ((unsigned int)(ty))))
527 #if defined(EF_USE_POM)
528 #define XRECORD_MTX(x) (XRECORD_LHEADER(x)->objmtx)
529 #define XLOCKRECORD(x) \
530 SXE_MUTEX_LOCK(&(XRECORD_MTX(x)))
531 #define XUNLOCKRECORD(x) \
532 SXE_MUTEX_UNLOCK(&(XRECORD_MTX(x)))
534 #define XRECORD_MTX(x)
535 #define XLOCKRECORD(x)
536 #define XUNLOCKRECORD(x)
539 /* Steps to create a new object:
541 1. Declare the struct for your object in a header file somewhere.
542 Remember that it must begin with
544 struct lcrecord_header header;
546 2. Put a DECLARE_LRECORD() for the object below the struct definition,
547 along with the standard XFOO/XSETFOO junk.
549 3. Add this header file to inline.c.
551 4. Create the methods for your object. Note that technically you don't
552 need any, but you will almost always want at least a mark method.
554 5. Define your object with DEFINE_LRECORD_IMPLEMENTATION() or some
557 6. Include the header file in the .c file where you defined the object.
559 7. Put a call to INIT_LRECORD_IMPLEMENTATION() for the object in the
560 .c file's syms_of_foo() function.
562 8. Add a type enum for the object to enum lrecord_type, earlier in this
567 ------------------------------ in toolbar.h -----------------------------
569 struct toolbar_button
571 struct lcrecord_header header;
576 Lisp_Object up_glyph;
577 Lisp_Object down_glyph;
578 Lisp_Object disabled_glyph;
580 Lisp_Object cap_up_glyph;
581 Lisp_Object cap_down_glyph;
582 Lisp_Object cap_disabled_glyph;
584 Lisp_Object callback;
585 Lisp_Object enabled_p;
586 Lisp_Object help_string;
600 DECLARE_LRECORD (toolbar_button, struct toolbar_button);
601 #define XTOOLBAR_BUTTON(x) XRECORD (x, toolbar_button, struct toolbar_button)
602 #define XSETTOOLBAR_BUTTON(x, p) XSETRECORD (x, p, toolbar_button)
603 #define TOOLBAR_BUTTONP(x) RECORDP (x, toolbar_button)
604 #define CHECK_TOOLBAR_BUTTON(x) CHECK_RECORD (x, toolbar_button)
605 #define CONCHECK_TOOLBAR_BUTTON(x) CONCHECK_RECORD (x, toolbar_button)
607 ------------------------------ in toolbar.c -----------------------------
609 #include "ui/toolbar.h"
614 mark_toolbar_button (Lisp_Object obj)
616 struct toolbar_button *data = XTOOLBAR_BUTTON (obj);
617 mark_object (data->next);
618 mark_object (data->frame);
619 mark_object (data->up_glyph);
620 mark_object (data->down_glyph);
621 mark_object (data->disabled_glyph);
622 mark_object (data->cap_up_glyph);
623 mark_object (data->cap_down_glyph);
624 mark_object (data->cap_disabled_glyph);
625 mark_object (data->callback);
626 mark_object (data->enabled_p);
627 return data->help_string;
630 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-button", toolbar_button,
631 mark_toolbar_button, 0, 0, 0, 0, 0,
632 struct toolbar_button);
637 syms_of_toolbar (void)
639 INIT_LRECORD_IMPLEMENTATION (toolbar_button);
644 ------------------------------ in inline.c -----------------------------
647 #include "ui/toolbar.h"
650 ------------------------------ in lrecord.h -----------------------------
655 lrecord_type_toolbar_button,
663 Note: Object types defined in external dynamically-loaded modules (not
664 part of the XEmacs main source code) should use DECLARE_EXTERNAL_LRECORD
665 and DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION rather than DECLARE_LRECORD
666 and DEFINE_LRECORD_IMPLEMENTATION.
670 #ifdef ERROR_CHECK_TYPECHECK
672 # define DECLARE_LRECORD(c_name, structtype) \
673 extern const struct lrecord_implementation lrecord_##c_name; \
674 extern_inline structtype * \
675 error_check_##c_name (Lisp_Object obj); \
676 extern_inline structtype * \
677 error_check_##c_name (Lisp_Object obj) \
679 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
680 return (structtype *) XPNTR (obj); \
682 extern Lisp_Object Q##c_name##p
684 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
685 extern unsigned int lrecord_type_##c_name; \
686 extern struct lrecord_implementation lrecord_##c_name; \
687 extern_inline structtype * \
688 error_check_##c_name (Lisp_Object obj); \
689 extern_inline structtype * \
690 error_check_##c_name (Lisp_Object obj) \
692 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
693 return (structtype *) XPNTR (obj); \
695 extern Lisp_Object Q##c_name##p
697 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
698 extern_inline structtype * \
699 error_check_##c_name (Lisp_Object obj); \
700 extern_inline structtype * \
701 error_check_##c_name (Lisp_Object obj) \
703 assert (XTYPE (obj) == type_enum); \
704 return (structtype *) XPNTR (obj); \
706 extern Lisp_Object Q##c_name##p
708 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
709 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
711 # define XSETRECORD(var, p, c_name) do \
714 assert (RECORD_TYPEP (var, lrecord_type_##c_name)); \
717 #else /* not ERROR_CHECK_TYPECHECK */
719 # define DECLARE_LRECORD(c_name, structtype) \
720 extern Lisp_Object Q##c_name##p; \
721 extern const struct lrecord_implementation lrecord_##c_name
722 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
723 extern Lisp_Object Q##c_name##p; \
724 extern unsigned int lrecord_type_##c_name; \
725 extern struct lrecord_implementation lrecord_##c_name
726 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
727 extern Lisp_Object Q##c_name##p
728 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
729 # define XNONRECORD(x, c_name, type_enum, structtype) \
730 ((structtype *) XPNTR (x))
731 # define XSETRECORD(var, p, c_name) XSETOBJ (var, p)
733 #endif /* not ERROR_CHECK_TYPECHECK */
735 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_type_##c_name)
737 /* Note: we now have two different kinds of type-checking macros.
738 The "old" kind has now been renamed CONCHECK_foo. The reason for
739 this is that the CONCHECK_foo macros signal a continuable error,
740 allowing the user (through debug-on-error) to substitute a different
741 value and return from the signal, which causes the lvalue argument
742 to get changed. Quite a lot of code would crash if that happened,
743 because it did things like
748 and later on did XSTRING (XCAR (list)), assuming that the type
749 is correct (when it might be wrong, if the user substituted a
750 correct value in the debugger).
752 To get around this, I made all the CHECK_foo macros signal a
753 non-continuable error. Places where a continuable error is OK
754 (generally only when called directly on the argument of a Lisp
755 primitive) should be changed to use CONCHECK().
757 FSF Emacs does not have this problem because RMS took the cheesy
758 way out and disabled returning from a signal entirely. */
760 #define CONCHECK_RECORD(x, c_name) do { \
761 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
762 x = wrong_type_argument (Q##c_name##p, x); \
764 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
765 if (XTYPE (x) != lisp_enum) \
766 x = wrong_type_argument (predicate, x); \
768 #define CHECK_RECORD(x, c_name) do { \
769 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
770 dead_wrong_type_argument (Q##c_name##p, x); \
772 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
773 if (XTYPE (x) != lisp_enum) \
774 dead_wrong_type_argument (predicate, x); \
777 void *alloc_lcrecord(size_t size, const struct lrecord_implementation *);
779 #define alloc_lcrecord_type(type, lrecord_implementation) \
780 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
782 /* Copy the data from one lcrecord structure into another, but don't
783 overwrite the header information. */
785 #define copy_lcrecord(dst, src) \
786 memcpy ((char *) (dst) + sizeof (struct lcrecord_header), \
787 (char *) (src) + sizeof (struct lcrecord_header), \
788 sizeof (*(dst)) - sizeof (struct lcrecord_header))
790 #define zero_lcrecord(lcr) \
791 memset ((char *) (lcr) + sizeof (struct lcrecord_header), 0, \
792 sizeof (*(lcr)) - sizeof (struct lcrecord_header))
794 #endif /* INCLUDED_lrecord_h_ */