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 unsigned int morphisms:/*number_of_cat_morphism_kinds => */6;
79 long unsigned int hash_cache;
82 struct lrecord_implementation;
83 int lrecord_type_index(const struct lrecord_implementation *implementation);
85 #define set_lheader_implementation(header,imp) \
87 struct lrecord_header* SLI_header = (header); \
88 SLI_header->type = (imp)->lrecord_type_index; \
89 SLI_header->mark = 0; \
90 SLI_header->c_readonly = 0; \
91 SLI_header->lisp_readonly = 0; \
92 SLI_header->morphisms = 0; \
93 SLI_header->hash_cache = 0; \
96 struct lcrecord_header {
97 struct lrecord_header lheader;
99 #if !defined HAVE_BDWGC || !defined EF_USE_BDWGC
100 /* The `next' field is normally used to chain all lcrecords together
101 so that the GC can find (and free) all of them.
102 `alloc_lcrecord' threads lcrecords together.
104 The `next' field may be used for other purposes as long as some
105 other mechanism is provided for letting the GC do its work.
107 For example, the event and marker object types allocate members
108 out of memory chunks, and are able to find all unmarked members
109 by sweeping through the elements of the list of chunks. */
110 struct lcrecord_header *next;
113 /* The `uid' field is just for debugging/printing convenience.
114 Having this slot doesn't hurt us much spacewise, since an
115 lcrecord already has the above slots plus malloc overhead. */
118 /* The `free' field is a flag that indicates whether this lcrecord
119 is on a "free list". Free lists are used to minimize the number
120 of calls to malloc() when we're repeatedly allocating and freeing
121 a number of the same sort of lcrecord. Lcrecords on a free list
122 always get marked in a different fashion, so we can use this flag
123 as a sanity check to make sure that free lists only have freed
124 lcrecords and there are no freed lcrecords elsewhere. */
128 /* Used for lcrecords in an lcrecord-list. */
129 struct free_lcrecord_header {
130 struct lcrecord_header lcheader;
135 /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast.
136 #### This should be replaced by a symbol_value_magic_p flag
137 in the Lisp_Symbol lrecord_header. */
138 lrecord_type_symbol_value_forward, /* 0 */
139 lrecord_type_symbol_value_varalias,
140 lrecord_type_symbol_value_lisp_magic,
141 lrecord_type_symbol_value_buffer_local,
142 lrecord_type_max_symbol_value_magic = /* 3 */
143 lrecord_type_symbol_value_buffer_local,
145 lrecord_type_symbol, /* 4 */
150 lrecord_type_lcrecord_list,
151 lrecord_type_compiled_function, /* 10 */
152 lrecord_type_weak_list,
153 lrecord_type_bit_vector,
154 lrecord_type_hash_table,
155 lrecord_type_lstream,
156 lrecord_type_process,
157 lrecord_type_charset,
158 lrecord_type_coding_system,
159 lrecord_type_char_table,
160 lrecord_type_char_table_entry,
161 lrecord_type_range_table, /* 20 */
163 lrecord_type_opaque_ptr,
164 lrecord_type_dynacat,
167 lrecord_type_extent_info,
168 lrecord_type_extent_auxiliary,
170 lrecord_type_event_queue,
171 lrecord_type_event_prique, /* 30 */
172 lrecord_type_worker_job,
174 lrecord_type_command_builder,
175 lrecord_type_timeout,
176 lrecord_type_specifier,
177 lrecord_type_console,
181 lrecord_type_window_configuration, /* 40 */
182 lrecord_type_gui_item,
183 lrecord_type_popup_data,
184 lrecord_type_toolbar_button,
185 lrecord_type_color_instance,
186 lrecord_type_font_instance,
187 lrecord_type_image_instance,
190 lrecord_type_database,
193 lrecord_type_pgresult,
194 lrecord_type_devmode,
195 lrecord_type_case_table,
196 lrecord_type_emacs_ffi,
197 lrecord_type_ffiobject, /* 60 */
198 lrecord_type_evp_pkey,
199 lrecord_type_ssl_conn,
201 lrecord_type_skiplist,
203 lrecord_type_audio_device,
204 lrecord_type_media_stream,
205 lrecord_type_media_thread,
208 lrecord_first_ent_type = lrecord_type_marker,
209 lrecord_type_float, /* 70 */
216 lrecord_type_quatern,
217 lrecord_type_indef, /* 78 */
218 lrecord_type_free, /* only used for "free" lrecords */
219 lrecord_type_undefined, /* only used for debugging */
220 lrecord_type_last_built_in_type /* must be last */
223 extern unsigned int lrecord_type_count;
225 struct lrecord_implementation {
228 /* `marker' is called at GC time, to make sure that all Lisp_Objects
229 pointed to by this object get properly marked. It should call
230 the mark_object function on all Lisp_Objects in the object. If
231 the return value is non-nil, it should be a Lisp_Object to be
232 marked (don't call the mark_object function explicitly on it,
233 because the GC routines will do this). Doing it this way reduces
234 recursion, so the object returned should preferably be the one
235 with the deepest level of Lisp_Object pointers. This function
236 can be NULL, meaning no GC marking is necessary. */
237 Lisp_Object(*marker) (Lisp_Object);
239 /* `printer' converts the object to a printed representation.
240 This can be NULL; in this case default_object_printer() will be
242 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
244 /* `finalizer' is called at GC time when the object is about to
245 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
246 case). It should perform any necessary cleanup (e.g. freeing
247 malloc()ed memory). This can be NULL, meaning no special
248 finalization is necessary.
250 WARNING: remember that `finalizer' is called at dump time even
251 though the object is not being freed. */
252 void (*finalizer) (void *header, int for_disksave);
254 /* This can be NULL, meaning compare objects with EQ(). */
255 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
257 /* `hash' generates hash values for use with hash tables that have
258 `equal' as their test function. This can be NULL, meaning use
259 the Lisp_Object itself as the hash. But, you must still satisfy
260 the constraint that if two objects are `equal', then they *must*
261 hash to the same value in order for hash tables to work properly.
262 This means that `hash' can be NULL only if the `equal' method is
264 long unsigned int (*hash) (Lisp_Object, int);
266 /* External data layout description */
267 const struct lrecord_description *description;
269 /* These functions allow any object type to have builtin property
270 lists that can be manipulated from the lisp level with
271 `get', `put', `remprop', and `object-plist'. */
272 Lisp_Object(*getprop) (Lisp_Object obj, Lisp_Object prop);
273 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
274 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
275 Lisp_Object(*plist) (Lisp_Object obj);
277 /* Only one of `static_size' and `size_in_bytes_method' is non-0.
278 If both are 0, this type is not instantiable by alloc_lcrecord(). */
280 size_t(*size_in_bytes_method) (const void *header);
282 /* The (constant) index into lrecord_implementations_table */
283 enum lrecord_type lrecord_type_index;
285 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
286 one that does not have an lcrecord_header at the front and which
287 is (usually) allocated in frob blocks. We only use this flag for
288 some consistency checking, and that only when error-checking is
293 /* All the built-in lisp object types are enumerated in `enum record_type'.
294 Additional ones may be defined by a module (none yet). We leave some
295 room in `lrecord_implementations_table' for such new lisp object types. */
296 #define MODULE_DEFINABLE_TYPE_COUNT 32
298 extern const struct lrecord_implementation
299 *lrecord_implementations_table[(unsigned int)lrecord_type_last_built_in_type
300 + MODULE_DEFINABLE_TYPE_COUNT];
302 #define XRECORD_LHEADER_IMPLEMENTATION(obj) \
303 LHEADER_IMPLEMENTATION (XRECORD_LHEADER (obj))
304 #define LHEADER_IMPLEMENTATION(lh) lrecord_implementations_table[(lh)->type]
306 extern int gc_in_progress;
308 #define MARKED_RECORD_P(obj) (XRECORD_LHEADER (obj)->mark)
309 #define MARKED_RECORD_HEADER_P(lheader) ((lheader)->mark)
310 #define MARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 1))
311 #define UNMARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 0))
313 #define C_READONLY_RECORD_HEADER_P(lheader) ((lheader)->c_readonly)
314 #define LISP_READONLY_RECORD_HEADER_P(lheader) ((lheader)->lisp_readonly)
315 #define SET_C_READONLY_RECORD_HEADER(lheader) \
317 struct lrecord_header *SCRRH_lheader = (lheader); \
318 SCRRH_lheader->c_readonly = 1; \
319 SCRRH_lheader->lisp_readonly = 1; \
320 SCRRH_lheader->mark = 1; \
322 #define SET_LISP_READONLY_RECORD_HEADER(lheader) \
323 ((void) ((lheader)->lisp_readonly = 1))
324 #define RECORD_MARKER(lheader) lrecord_markers[(lheader)->type]
326 /* External description stuff
328 A lrecord external description is an array of values. The first
329 value of each line is a type, the second the offset in the lrecord
330 structure. Following values are parameters, their presence, type
331 and number is type-dependent.
333 The description ends with a "XD_END" or "XD_SPECIFIER_END" record.
335 Some example descriptions :
337 static const struct lrecord_description cons_description[] = {
338 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
339 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
343 Which means "two lisp objects starting at the 'car' and 'cdr' elements"
345 static const struct lrecord_description string_description[] = {
346 { XD_BYTECOUNT, offsetof (Lisp_String, size) },
347 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) },
348 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
351 "A pointer to string data at 'data', the size of the pointed array being the value
352 of the size variable plus 1, and one lisp object at 'plist'"
356 A Lisp object. This is also the type to use for pointers to other lrecords.
359 An array of Lisp objects or pointers to lrecords.
360 The third element is the count.
363 Link in a linked list of objects of the same type.
366 Pointer to undumpable data. Must be NULL when dumping.
369 Pointer to described struct. Parameters are number of structures and
373 Pointer to dumpable opaque data. Parameter is the size of the data.
374 Pointed data must be relocatable without changes.
377 Pointer to a C string.
380 Pointer to a doc string (C string if positive, opaque value if negative)
383 An integer which will be reset to a given value in the dump file.
386 size_t value. Used for counts.
389 int value. Used for counts.
392 long value. Used for counts.
395 bytecount value. Used for counts.
398 Special type indicating the end of the array.
401 Special type indicating the end of the array for a specifier. Extra
402 description is going to be fetched from the specifier methods.
405 XD_INDIRECT(line, delta)
406 Usable where a "count" or "size" is requested. Gives the value of
407 the element which is at line number 'line' in the description (count
408 starts at zero) and adds delta to it.
411 enum lrecord_description_type {
412 XD_LISP_OBJECT_ARRAY,
429 struct lrecord_description {
430 enum lrecord_description_type type;
433 const struct struct_description *data2;
436 struct struct_description {
438 const struct lrecord_description *description;
441 #define XD_INDIRECT(val, delta) (-1-((val)|(delta<<8)))
443 #define XD_IS_INDIRECT(code) (code<0)
444 #define XD_INDIRECT_VAL(code) ((-1-code) & 255)
445 #define XD_INDIRECT_DELTA(code) (((-1-code)>>8) & 255)
447 #define XD_DYNARR_DESC(base_type, sub_desc) \
448 { XD_STRUCT_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), sub_desc }, \
449 { XD_INT, offsetof (base_type, cur) }, \
450 { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) }
452 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
453 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
456 #if defined (ERROR_CHECK_TYPECHECK)
457 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
459 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
462 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
463 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
465 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
466 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
468 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
469 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
471 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
472 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
474 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
475 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
477 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
478 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
480 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
481 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype) \
483 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
484 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
485 const struct lrecord_implementation lrecord_##c_name = \
486 { name, marker, printer, nuker, equal, hash, desc, \
487 getprop, putprop, remprop, plist, size, sizer, \
488 lrecord_type_##c_name, basic_p }
490 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
491 DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
493 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
494 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
496 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
497 DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
499 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
500 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
502 #define MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
503 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
504 unsigned int lrecord_type_##c_name; \
505 struct lrecord_implementation lrecord_##c_name = \
506 { name, marker, printer, nuker, equal, hash, desc, \
507 getprop, putprop, remprop, plist, size, sizer, \
508 lrecord_type_last_built_in_type, basic_p }
510 extern Lisp_Object(*lrecord_markers[]) (Lisp_Object);
512 #define INIT_LRECORD_IMPLEMENTATION(type) do { \
513 lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
514 lrecord_markers[lrecord_type_##type] = \
515 lrecord_implementations_table[lrecord_type_##type]->marker; \
518 #define INIT_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
519 lrecord_type_##type = lrecord_type_count++; \
520 lrecord_##type.lrecord_type_index = (enum lrecord_type) lrecord_type_##type; \
521 INIT_LRECORD_IMPLEMENTATION(type); \
524 #define LRECORDP(a) (XTYPE (a) == Lisp_Type_Record)
525 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
527 #define RECORD_TYPEP(x, ty) \
528 (LRECORDP (x) && (((unsigned int)(XRECORD_LHEADER (x)->type)) == ((unsigned int)(ty))))
530 #if defined(EF_USE_POM)
531 #define XRECORD_MTX(x) (XRECORD_LHEADER(x)->objmtx)
532 #define XLOCKRECORD(x) \
533 SXE_MUTEX_LOCK(&(XRECORD_MTX(x)))
534 #define XUNLOCKRECORD(x) \
535 SXE_MUTEX_UNLOCK(&(XRECORD_MTX(x)))
537 #define XRECORD_MTX(x)
538 #define XLOCKRECORD(x)
539 #define XUNLOCKRECORD(x)
542 /* Steps to create a new object:
544 1. Declare the struct for your object in a header file somewhere.
545 Remember that it must begin with
547 struct lcrecord_header header;
549 2. Put a DECLARE_LRECORD() for the object below the struct definition,
550 along with the standard XFOO/XSETFOO junk.
552 3. Add this header file to inline.c.
554 4. Create the methods for your object. Note that technically you don't
555 need any, but you will almost always want at least a mark method.
557 5. Define your object with DEFINE_LRECORD_IMPLEMENTATION() or some
560 6. Include the header file in the .c file where you defined the object.
562 7. Put a call to INIT_LRECORD_IMPLEMENTATION() for the object in the
563 .c file's syms_of_foo() function.
565 8. Add a type enum for the object to enum lrecord_type, earlier in this
570 ------------------------------ in toolbar.h -----------------------------
572 struct toolbar_button
574 struct lcrecord_header header;
579 Lisp_Object up_glyph;
580 Lisp_Object down_glyph;
581 Lisp_Object disabled_glyph;
583 Lisp_Object cap_up_glyph;
584 Lisp_Object cap_down_glyph;
585 Lisp_Object cap_disabled_glyph;
587 Lisp_Object callback;
588 Lisp_Object enabled_p;
589 Lisp_Object help_string;
603 DECLARE_LRECORD (toolbar_button, struct toolbar_button);
604 #define XTOOLBAR_BUTTON(x) XRECORD (x, toolbar_button, struct toolbar_button)
605 #define XSETTOOLBAR_BUTTON(x, p) XSETRECORD (x, p, toolbar_button)
606 #define TOOLBAR_BUTTONP(x) RECORDP (x, toolbar_button)
607 #define CHECK_TOOLBAR_BUTTON(x) CHECK_RECORD (x, toolbar_button)
608 #define CONCHECK_TOOLBAR_BUTTON(x) CONCHECK_RECORD (x, toolbar_button)
610 ------------------------------ in toolbar.c -----------------------------
612 #include "ui/toolbar.h"
617 mark_toolbar_button (Lisp_Object obj)
619 struct toolbar_button *data = XTOOLBAR_BUTTON (obj);
620 mark_object (data->next);
621 mark_object (data->frame);
622 mark_object (data->up_glyph);
623 mark_object (data->down_glyph);
624 mark_object (data->disabled_glyph);
625 mark_object (data->cap_up_glyph);
626 mark_object (data->cap_down_glyph);
627 mark_object (data->cap_disabled_glyph);
628 mark_object (data->callback);
629 mark_object (data->enabled_p);
630 return data->help_string;
633 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-button", toolbar_button,
634 mark_toolbar_button, 0, 0, 0, 0, 0,
635 struct toolbar_button);
640 syms_of_toolbar (void)
642 INIT_LRECORD_IMPLEMENTATION (toolbar_button);
647 ------------------------------ in inline.c -----------------------------
650 #include "ui/toolbar.h"
653 ------------------------------ in lrecord.h -----------------------------
658 lrecord_type_toolbar_button,
666 Note: Object types defined in external dynamically-loaded modules (not
667 part of the XEmacs main source code) should use DECLARE_EXTERNAL_LRECORD
668 and DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION rather than DECLARE_LRECORD
669 and DEFINE_LRECORD_IMPLEMENTATION.
673 #ifdef ERROR_CHECK_TYPECHECK
675 # define DECLARE_LRECORD(c_name, structtype) \
676 extern const struct lrecord_implementation lrecord_##c_name; \
677 extern_inline structtype * \
678 error_check_##c_name (Lisp_Object obj); \
679 extern_inline structtype * \
680 error_check_##c_name (Lisp_Object obj) \
682 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
683 return (structtype *) XPNTR (obj); \
685 extern Lisp_Object Q##c_name##p
687 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
688 extern unsigned int lrecord_type_##c_name; \
689 extern struct lrecord_implementation lrecord_##c_name; \
690 extern_inline structtype * \
691 error_check_##c_name (Lisp_Object obj); \
692 extern_inline structtype * \
693 error_check_##c_name (Lisp_Object obj) \
695 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
696 return (structtype *) XPNTR (obj); \
698 extern Lisp_Object Q##c_name##p
700 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
701 extern_inline structtype * \
702 error_check_##c_name (Lisp_Object obj); \
703 extern_inline structtype * \
704 error_check_##c_name (Lisp_Object obj) \
706 assert (XTYPE (obj) == type_enum); \
707 return (structtype *) XPNTR (obj); \
709 extern Lisp_Object Q##c_name##p
711 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
712 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
714 # define XSETRECORD(var, p, c_name) do \
717 assert (RECORD_TYPEP (var, lrecord_type_##c_name)); \
720 #else /* not ERROR_CHECK_TYPECHECK */
722 # define DECLARE_LRECORD(c_name, structtype) \
723 extern Lisp_Object Q##c_name##p; \
724 extern const struct lrecord_implementation lrecord_##c_name
725 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
726 extern Lisp_Object Q##c_name##p; \
727 extern unsigned int lrecord_type_##c_name; \
728 extern struct lrecord_implementation lrecord_##c_name
729 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
730 extern Lisp_Object Q##c_name##p
731 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
732 # define XNONRECORD(x, c_name, type_enum, structtype) \
733 ((structtype *) XPNTR (x))
734 # define XSETRECORD(var, p, c_name) XSETOBJ (var, p)
736 #endif /* not ERROR_CHECK_TYPECHECK */
738 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_type_##c_name)
740 /* Note: we now have two different kinds of type-checking macros.
741 The "old" kind has now been renamed CONCHECK_foo. The reason for
742 this is that the CONCHECK_foo macros signal a continuable error,
743 allowing the user (through debug-on-error) to substitute a different
744 value and return from the signal, which causes the lvalue argument
745 to get changed. Quite a lot of code would crash if that happened,
746 because it did things like
751 and later on did XSTRING (XCAR (list)), assuming that the type
752 is correct (when it might be wrong, if the user substituted a
753 correct value in the debugger).
755 To get around this, I made all the CHECK_foo macros signal a
756 non-continuable error. Places where a continuable error is OK
757 (generally only when called directly on the argument of a Lisp
758 primitive) should be changed to use CONCHECK().
760 FSF Emacs does not have this problem because RMS took the cheesy
761 way out and disabled returning from a signal entirely. */
763 #define CONCHECK_RECORD(x, c_name) do { \
764 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
765 x = wrong_type_argument (Q##c_name##p, x); \
767 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
768 if (XTYPE (x) != lisp_enum) \
769 x = wrong_type_argument (predicate, x); \
771 #define CHECK_RECORD(x, c_name) do { \
772 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
773 dead_wrong_type_argument (Q##c_name##p, x); \
775 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
776 if (XTYPE (x) != lisp_enum) \
777 dead_wrong_type_argument (predicate, x); \
780 void *alloc_lcrecord(size_t size, const struct lrecord_implementation *);
782 #define alloc_lcrecord_type(type, lrecord_implementation) \
783 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
785 /* Copy the data from one lcrecord structure into another, but don't
786 overwrite the header information. */
788 #define copy_lcrecord(dst, src) \
789 memcpy ((char *) (dst) + sizeof (struct lcrecord_header), \
790 (char *) (src) + sizeof (struct lcrecord_header), \
791 sizeof (*(dst)) - sizeof (struct lcrecord_header))
793 #define zero_lcrecord(lcr) \
794 memset ((char *) (lcr) + sizeof (struct lcrecord_header), 0, \
795 sizeof (*(lcr)) - sizeof (struct lcrecord_header))
797 #endif /* INCLUDED_lrecord_h_ */