428
|
1 /* The "lrecord" structure (header of a compound lisp object).
|
|
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
788
|
3 Copyright (C) 1996, 2001, 2002 Ben Wing.
|
428
|
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
|
440
|
24 #ifndef INCLUDED_lrecord_h_
|
|
25 #define INCLUDED_lrecord_h_
|
428
|
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
|
442
|
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.
|
428
|
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
|
442
|
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().
|
428
|
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[] */
|
442
|
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
|
428
|
76 /* 1 if the object is readonly from lisp */
|
442
|
77 unsigned int lisp_readonly :1;
|
771
|
78
|
|
79 unsigned int unused :21;
|
934
|
80
|
428
|
81 };
|
|
82
|
|
83 struct lrecord_implementation;
|
442
|
84 int lrecord_type_index (const struct lrecord_implementation *implementation);
|
428
|
85
|
430
|
86 #define set_lheader_implementation(header,imp) do { \
|
428
|
87 struct lrecord_header* SLI_header = (header); \
|
442
|
88 SLI_header->type = (imp)->lrecord_type_index; \
|
430
|
89 SLI_header->mark = 0; \
|
|
90 SLI_header->c_readonly = 0; \
|
|
91 SLI_header->lisp_readonly = 0; \
|
428
|
92 } while (0)
|
|
93
|
|
94 struct lcrecord_header
|
|
95 {
|
|
96 struct lrecord_header lheader;
|
|
97
|
442
|
98 /* The `next' field is normally used to chain all lcrecords together
|
428
|
99 so that the GC can find (and free) all of them.
|
442
|
100 `alloc_lcrecord' threads lcrecords together.
|
428
|
101
|
|
102 The `next' field may be used for other purposes as long as some
|
|
103 other mechanism is provided for letting the GC do its work.
|
|
104
|
|
105 For example, the event and marker object types allocate members
|
|
106 out of memory chunks, and are able to find all unmarked members
|
|
107 by sweeping through the elements of the list of chunks. */
|
|
108 struct lcrecord_header *next;
|
|
109
|
|
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. */
|
|
113 unsigned int uid :31;
|
|
114
|
|
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. */
|
|
122 unsigned int free :1;
|
|
123 };
|
|
124
|
|
125 /* Used for lcrecords in an lcrecord-list. */
|
|
126 struct free_lcrecord_header
|
|
127 {
|
|
128 struct lcrecord_header lcheader;
|
|
129 Lisp_Object chain;
|
|
130 };
|
|
131
|
442
|
132 enum lrecord_type
|
|
133 {
|
|
134 /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast.
|
|
135 #### This should be replaced by a symbol_value_magic_p flag
|
|
136 in the Lisp_Symbol lrecord_header. */
|
|
137 lrecord_type_symbol_value_forward,
|
|
138 lrecord_type_symbol_value_varalias,
|
|
139 lrecord_type_symbol_value_lisp_magic,
|
|
140 lrecord_type_symbol_value_buffer_local,
|
|
141 lrecord_type_max_symbol_value_magic = lrecord_type_symbol_value_buffer_local,
|
|
142
|
|
143 lrecord_type_symbol,
|
|
144 lrecord_type_subr,
|
|
145 lrecord_type_cons,
|
|
146 lrecord_type_vector,
|
|
147 lrecord_type_string,
|
|
148 lrecord_type_lcrecord_list,
|
|
149 lrecord_type_compiled_function,
|
|
150 lrecord_type_weak_list,
|
|
151 lrecord_type_bit_vector,
|
|
152 lrecord_type_float,
|
|
153 lrecord_type_hash_table,
|
|
154 lrecord_type_lstream,
|
|
155 lrecord_type_process,
|
|
156 lrecord_type_charset,
|
|
157 lrecord_type_coding_system,
|
|
158 lrecord_type_char_table,
|
|
159 lrecord_type_char_table_entry,
|
|
160 lrecord_type_range_table,
|
|
161 lrecord_type_opaque,
|
|
162 lrecord_type_opaque_ptr,
|
|
163 lrecord_type_buffer,
|
|
164 lrecord_type_extent,
|
|
165 lrecord_type_extent_info,
|
|
166 lrecord_type_extent_auxiliary,
|
|
167 lrecord_type_marker,
|
|
168 lrecord_type_event,
|
934
|
169 #ifdef USE_KKCC
|
|
170 lrecord_type_key_data,
|
|
171 lrecord_type_button_data,
|
|
172 lrecord_type_motion_data,
|
|
173 lrecord_type_process_data,
|
|
174 lrecord_type_timeout_data,
|
|
175 lrecord_type_eval_data,
|
|
176 lrecord_type_misc_user_data,
|
|
177 lrecord_type_magic_eval_data,
|
|
178 lrecord_type_magic_data,
|
|
179 #endif /* USE_KKCC */
|
442
|
180 lrecord_type_keymap,
|
|
181 lrecord_type_command_builder,
|
|
182 lrecord_type_timeout,
|
|
183 lrecord_type_specifier,
|
|
184 lrecord_type_console,
|
|
185 lrecord_type_device,
|
|
186 lrecord_type_frame,
|
|
187 lrecord_type_window,
|
617
|
188 lrecord_type_window_mirror,
|
442
|
189 lrecord_type_window_configuration,
|
|
190 lrecord_type_gui_item,
|
|
191 lrecord_type_popup_data,
|
|
192 lrecord_type_toolbar_button,
|
617
|
193 lrecord_type_scrollbar_instance,
|
442
|
194 lrecord_type_color_instance,
|
|
195 lrecord_type_font_instance,
|
|
196 lrecord_type_image_instance,
|
|
197 lrecord_type_glyph,
|
|
198 lrecord_type_face,
|
|
199 lrecord_type_database,
|
|
200 lrecord_type_tooltalk_message,
|
|
201 lrecord_type_tooltalk_pattern,
|
|
202 lrecord_type_ldap,
|
|
203 lrecord_type_pgconn,
|
|
204 lrecord_type_pgresult,
|
|
205 lrecord_type_devmode,
|
|
206 lrecord_type_mswindows_dialog_id,
|
446
|
207 lrecord_type_case_table,
|
462
|
208 lrecord_type_emacs_ffi,
|
|
209 lrecord_type_emacs_gtk_object,
|
|
210 lrecord_type_emacs_gtk_boxed,
|
858
|
211 lrecord_type_weak_box,
|
888
|
212 lrecord_type_ephemeron,
|
454
|
213 lrecord_type_free, /* only used for "free" lrecords */
|
|
214 lrecord_type_undefined, /* only used for debugging */
|
442
|
215 lrecord_type_last_built_in_type /* must be last */
|
|
216 };
|
|
217
|
647
|
218 extern int lrecord_type_count;
|
428
|
219
|
|
220 struct lrecord_implementation
|
|
221 {
|
442
|
222 const char *name;
|
|
223
|
934
|
224 /* information for the dumper: is the object dumpable and should it
|
|
225 be dumped. */
|
|
226 unsigned int dumpable :1;
|
|
227
|
442
|
228 /* `marker' is called at GC time, to make sure that all Lisp_Objects
|
428
|
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);
|
442
|
238
|
|
239 /* `printer' converts the object to a printed representation.
|
|
240 This can be NULL; in this case default_object_printer() will be
|
|
241 used instead. */
|
428
|
242 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
|
442
|
243
|
|
244 /* `finalizer' is called at GC time when the object is about to
|
428
|
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
|
442
|
247 malloc()ed memory). This can be NULL, meaning no special
|
428
|
248 finalization is necessary.
|
|
249
|
442
|
250 WARNING: remember that `finalizer' is called at dump time even
|
428
|
251 though the object is not being freed. */
|
|
252 void (*finalizer) (void *header, int for_disksave);
|
442
|
253
|
428
|
254 /* This can be NULL, meaning compare objects with EQ(). */
|
|
255 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
|
442
|
256
|
|
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
|
|
263 also NULL. */
|
428
|
264 unsigned long (*hash) (Lisp_Object, int);
|
|
265
|
|
266 /* External data layout description */
|
|
267 const struct lrecord_description *description;
|
|
268
|
442
|
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'. */
|
428
|
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);
|
|
276
|
442
|
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(). */
|
665
|
279 Bytecount static_size;
|
|
280 Bytecount (*size_in_bytes_method) (const void *header);
|
442
|
281
|
|
282 /* The (constant) index into lrecord_implementations_table */
|
|
283 enum lrecord_type lrecord_type_index;
|
|
284
|
428
|
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
|
|
289 enabled. */
|
442
|
290 unsigned int basic_p :1;
|
428
|
291 };
|
|
292
|
617
|
293 /* All the built-in lisp object types are enumerated in `enum lrecord_type'.
|
442
|
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
|
|
297
|
647
|
298 extern const struct lrecord_implementation *lrecord_implementations_table[lrecord_type_last_built_in_type + MODULE_DEFINABLE_TYPE_COUNT];
|
428
|
299
|
|
300 #define XRECORD_LHEADER_IMPLEMENTATION(obj) \
|
442
|
301 LHEADER_IMPLEMENTATION (XRECORD_LHEADER (obj))
|
|
302 #define LHEADER_IMPLEMENTATION(lh) lrecord_implementations_table[(lh)->type]
|
428
|
303
|
|
304 extern int gc_in_progress;
|
|
305
|
442
|
306 #define MARKED_RECORD_P(obj) (XRECORD_LHEADER (obj)->mark)
|
428
|
307 #define MARKED_RECORD_HEADER_P(lheader) ((lheader)->mark)
|
|
308 #define MARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 1))
|
|
309 #define UNMARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 0))
|
|
310
|
|
311 #define C_READONLY_RECORD_HEADER_P(lheader) ((lheader)->c_readonly)
|
|
312 #define LISP_READONLY_RECORD_HEADER_P(lheader) ((lheader)->lisp_readonly)
|
442
|
313 #define SET_C_READONLY_RECORD_HEADER(lheader) do { \
|
|
314 struct lrecord_header *SCRRH_lheader = (lheader); \
|
|
315 SCRRH_lheader->c_readonly = 1; \
|
|
316 SCRRH_lheader->lisp_readonly = 1; \
|
|
317 SCRRH_lheader->mark = 1; \
|
|
318 } while (0)
|
428
|
319 #define SET_LISP_READONLY_RECORD_HEADER(lheader) \
|
|
320 ((void) ((lheader)->lisp_readonly = 1))
|
442
|
321 #define RECORD_MARKER(lheader) lrecord_markers[(lheader)->type]
|
428
|
322
|
934
|
323 #ifdef USE_KKCC
|
|
324 #define RECORD_DUMPABLE(lheader) (lrecord_implementations_table[(lheader)->type])->dumpable
|
|
325 #endif /* USE_KKCC */
|
|
326
|
428
|
327 /* External description stuff
|
|
328
|
771
|
329 PLEASE NOTE: Both lrecord_description and struct_description are
|
|
330 badly misnamed. In reality, an lrecord_description is nothing more
|
|
331 than a list of the elements in a block of memory that need
|
|
332 relocating or other special handling, and a struct_description is
|
|
333 no more than an lrecord_description plus the size of the block of
|
|
334 memory. (In fact, a struct_description can now have its size given
|
|
335 as zero, i.e. unspecified, meaning that the last element in the
|
|
336 structure is noted in the list and the size of the block can
|
|
337 therefore be computed from it.) The names stem from the fact
|
|
338 lrecord_descriptions are used to describe lrecords (the size of the
|
|
339 lrecord is elsewhere in its description, attached to its methods,
|
|
340 so it does not need to be given here), while struct_descriptions
|
|
341 are used to describe C structs; but both are used in various
|
|
342 additional ways. Much better terms would be memory_description and
|
|
343 sized_memory_description.
|
428
|
344
|
771
|
345 An lrecord_description is an array of values. (This is actually
|
|
346 misnamed, in that it does not just describe lrecords, but any
|
|
347 blocks of memory.) The first value of each line is a type, the
|
|
348 second the offset in the lrecord structure. The third and
|
|
349 following elements are parameters; their presence, type and number
|
|
350 is type-dependent.
|
|
351
|
|
352 The description ends with a "XD_END", "XD_SPECIFIER_END" or
|
|
353 "XD_CODING_SYSTEM_END" record.
|
|
354
|
|
355 The top-level description of an lrecord or lcrecord does not need
|
|
356 to describe every element, just the ones that need to be relocated,
|
|
357 since the size of the lrecord is known. (The same goes for nested
|
|
358 structures, whenever the structure size is given, rather than being
|
|
359 defaulted by specifying 0 for the size.)
|
|
360
|
814
|
361 A struct_description is used for describing nested "structures". (Again
|
|
362 a misnomer, since it can be used for any blocks of memory, not just
|
|
363 structures.) It just contains a size for the memory block, a pointer to
|
|
364 an lrecord_description, and (for unions only) a union constant,
|
|
365 described below. The size can be 0, in which case the size will be
|
|
366 determined from the largest offset logically referenced (i.e. last
|
|
367 offset mentioned + size of that object). This is useful for stretchy
|
|
368 arrays.
|
428
|
369
|
|
370 Some example descriptions :
|
440
|
371
|
814
|
372 struct Lisp_String
|
|
373 {
|
|
374 struct lrecord_header lheader;
|
|
375 Bytecount size;
|
867
|
376 Ibyte *data;
|
814
|
377 Lisp_Object plist;
|
|
378 };
|
|
379
|
428
|
380 static const struct lrecord_description cons_description[] = {
|
440
|
381 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
|
|
382 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
|
428
|
383 { XD_END }
|
|
384 };
|
|
385
|
440
|
386 Which means "two lisp objects starting at the 'car' and 'cdr' elements"
|
428
|
387
|
814
|
388 static const struct lrecord_description string_description[] = {
|
|
389 { XD_BYTECOUNT, offsetof (Lisp_String, size) },
|
|
390 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) },
|
|
391 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
|
|
392 { XD_END }
|
|
393 };
|
|
394
|
|
395 "A pointer to string data at 'data', the size of the pointed array being
|
|
396 the value of the size variable plus 1, and one lisp object at 'plist'"
|
|
397
|
|
398 If your object has a pointer to an array of Lisp_Objects in it, something
|
|
399 like this:
|
|
400
|
|
401 struct Lisp_Foo
|
|
402 {
|
|
403 ...;
|
|
404 int count;
|
|
405 Lisp_Object *objects;
|
|
406 ...;
|
|
407 }
|
|
408
|
|
409 You'd use XD_STRUCT_PTR, something like:
|
|
410
|
|
411 static const struct lrecord_description lo_description_1[] = {
|
|
412 { XD_LISP_OBJECT, 0 },
|
|
413 { XD_END }
|
|
414 };
|
|
415
|
|
416 static const struct struct_description lo_description = {
|
|
417 sizeof (Lisp_Object),
|
|
418 lo_description_1
|
|
419 };
|
|
420
|
|
421 static const struct lrecord_description foo_description[] = {
|
|
422 ...
|
|
423 { XD_INT, offsetof (Lisp_Foo, count) },
|
|
424 { XD_STRUCT_PTR, offsetof (Lisp_Foo, objects),
|
|
425 XD_INDIRECT (0, 0), &lo_description },
|
|
426 ...
|
|
427 };
|
|
428
|
|
429
|
|
430 Another example of XD_STRUCT_PTR:
|
428
|
431
|
814
|
432 typedef struct hentry
|
|
433 {
|
|
434 Lisp_Object key;
|
|
435 Lisp_Object value;
|
|
436 } hentry;
|
|
437
|
|
438 struct Lisp_Hash_Table
|
|
439 {
|
|
440 struct lcrecord_header header;
|
|
441 Elemcount size;
|
|
442 Elemcount count;
|
|
443 Elemcount rehash_count;
|
|
444 double rehash_size;
|
|
445 double rehash_threshold;
|
|
446 Elemcount golden_ratio;
|
|
447 hash_table_hash_function_t hash_function;
|
|
448 hash_table_test_function_t test_function;
|
|
449 hentry *hentries;
|
|
450 enum hash_table_weakness weakness;
|
|
451 Lisp_Object next_weak; // Used to chain together all of the weak
|
|
452 // hash tables. Don't mark through this.
|
|
453 };
|
|
454
|
|
455 static const struct lrecord_description hentry_description_1[] = {
|
|
456 { XD_LISP_OBJECT, offsetof (hentry, key) },
|
|
457 { XD_LISP_OBJECT, offsetof (hentry, value) },
|
|
458 { XD_END }
|
|
459 };
|
|
460
|
|
461 static const struct struct_description hentry_description = {
|
|
462 sizeof (hentry),
|
|
463 hentry_description_1
|
|
464 };
|
|
465
|
|
466 const struct lrecord_description hash_table_description[] = {
|
|
467 { XD_ELEMCOUNT, offsetof (Lisp_Hash_Table, size) },
|
|
468 { XD_STRUCT_PTR, offsetof (Lisp_Hash_Table, hentries), XD_INDIRECT(0, 1),
|
|
469 &hentry_description },
|
|
470 { XD_LO_LINK, offsetof (Lisp_Hash_Table, next_weak) },
|
|
471 { XD_END }
|
|
472 };
|
|
473
|
|
474 Note that we don't need to declare all the elements in the structure, just
|
|
475 the ones that need to be relocated (Lisp_Objects and structures) or that
|
|
476 need to be referenced as counts for relocated objects.
|
|
477
|
|
478
|
|
479 The existing types :
|
|
480
|
|
481
|
428
|
482 XD_LISP_OBJECT
|
440
|
483 A Lisp object. This is also the type to use for pointers to other lrecords.
|
428
|
484
|
440
|
485 XD_LISP_OBJECT_ARRAY
|
771
|
486 An array of Lisp objects or (equivalently) pointers to lrecords.
|
|
487 The parameter (i.e. third element) is the count. This would be declared
|
|
488 as Lisp_Object foo[666]. For something declared as Lisp_Object *foo,
|
|
489 use XD_STRUCT_PTR, whose description parameter is a struct_description
|
|
490 consisting of only XD_LISP_OBJECT and XD_END.
|
440
|
491
|
428
|
492 XD_LO_LINK
|
771
|
493 Weak link in a linked list of objects of the same type. This is a
|
|
494 link that does NOT generate a GC reference. Thus the pdumper will
|
|
495 not automatically add the referenced object to the table of all
|
|
496 objects to be dumped, and when storing and loading the dumped data
|
|
497 will automatically prune unreferenced objects in the chain and link
|
|
498 each referenced object to the next referenced object, even if it's
|
|
499 many links away. We also need to special handling of a similar
|
|
500 nature for the root of the chain, which will be a staticpro()ed
|
|
501 object.
|
432
|
502
|
428
|
503 XD_OPAQUE_PTR
|
|
504 Pointer to undumpable data. Must be NULL when dumping.
|
|
505
|
|
506 XD_STRUCT_PTR
|
771
|
507 Pointer to block of described memory. (This is misnamed: It is NOT
|
|
508 necessarily a pointer to a struct foo.) Parameters are number of
|
|
509 contiguous blocks and struct_description.
|
|
510
|
|
511 XD_STRUCT_ARRAY
|
|
512 Array of blocks of described memory. Parameters are number of
|
|
513 structures and struct_description. This differs from XD_STRUCT_PTR
|
|
514 in that the parameter is declared as struct foo[666] instead of
|
|
515 struct *foo. In other words, the block of memory holding the
|
|
516 structures is within the containing structure, rather than being
|
|
517 elsewhere, with a pointer in the containing structure.
|
428
|
518
|
|
519 XD_OPAQUE_DATA_PTR
|
|
520 Pointer to dumpable opaque data. Parameter is the size of the data.
|
|
521 Pointed data must be relocatable without changes.
|
|
522
|
771
|
523 XD_UNION
|
|
524 Union of two or more different types of data. Parameters are a
|
|
525 constant which determines which type the data is (this is usually an
|
|
526 XD_INDIRECT, referring to one of the fields in the structure), and
|
|
527 an array of struct_descriptions, whose values are used as follows,
|
|
528 which is *DIFFERENT* from their usage in XD_STRUCT_PTR: the first
|
|
529 field is a constant, which is compared to the first parameter of the
|
|
530 XD_UNION descriptor to determine if this description applies to the
|
|
531 data at the given offset, and the second is a pointer to a *SINGLE*
|
|
532 lrecord_description structure, describing the data being pointed at
|
|
533 when the associated constant matches. You can go ahead and create
|
|
534 an array of lrecord_description structures and put an XD_END on it,
|
|
535 but only the first one is used. If the data being pointed at is a
|
|
536 structure, you *MAY NOT* substitute an array of lrecord_description
|
|
537 structures describing the structure; instead, use a single
|
|
538 lrecord_description structure with an XD_STRUCT_PTR in it, and point
|
|
539 it in turn to the description of the structure. See charset.h for a
|
|
540 description of how to use XD_UNION. (In other words, if the constant
|
|
541 matches, the lrecord_description pointed at will in essence be
|
|
542 substituted for the XD_UNION declaration.)
|
|
543
|
428
|
544 XD_C_STRING
|
|
545 Pointer to a C string.
|
|
546
|
|
547 XD_DOC_STRING
|
|
548 Pointer to a doc string (C string if positive, opaque value if negative)
|
|
549
|
|
550 XD_INT_RESET
|
|
551 An integer which will be reset to a given value in the dump file.
|
|
552
|
771
|
553
|
665
|
554 XD_ELEMCOUNT
|
|
555 Elemcount value. Used for counts.
|
647
|
556
|
665
|
557 XD_BYTECOUNT
|
|
558 Bytecount value. Used for counts.
|
647
|
559
|
665
|
560 XD_HASHCODE
|
|
561 Hashcode value. Used for the results of hashing functions.
|
428
|
562
|
|
563 XD_INT
|
|
564 int value. Used for counts.
|
|
565
|
|
566 XD_LONG
|
|
567 long value. Used for counts.
|
|
568
|
771
|
569 XD_BYTECOUNT
|
|
570 bytecount value. Used for counts.
|
|
571
|
428
|
572 XD_END
|
|
573 Special type indicating the end of the array.
|
|
574
|
|
575 XD_SPECIFIER_END
|
|
576 Special type indicating the end of the array for a specifier. Extra
|
771
|
577 description, describing the specifier-type-specific data at the end
|
|
578 of the specifier object, is going to be fetched from the specifier
|
|
579 methods. This should occur exactly once, in the description of the
|
|
580 specifier object, and the dump code knows how to special-case this
|
|
581 by fetching the specifier_methods pointer from the appropriate place
|
|
582 in the memory block (which will, of course, be a struct
|
|
583 Lisp_Specifier), fetching the description of the
|
|
584 specifier-type-specific data from this, and continuing processing
|
|
585 the memory block.
|
|
586
|
|
587 XD_CODING_SYSTEM_END
|
|
588 Special type indicating the end of the array for a coding system.
|
|
589 Extra description is going to be fetched from the coding system
|
|
590 methods. Works just like XD_SPECIFIER_END.
|
428
|
591
|
|
592
|
|
593 Special macros:
|
|
594 XD_INDIRECT(line, delta)
|
|
595 Usable where a "count" or "size" is requested. Gives the value of
|
|
596 the element which is at line number 'line' in the description (count
|
|
597 starts at zero) and adds delta to it.
|
|
598 */
|
|
599
|
647
|
600 enum lrecord_description_type
|
|
601 {
|
440
|
602 XD_LISP_OBJECT_ARRAY,
|
428
|
603 XD_LISP_OBJECT,
|
|
604 XD_LO_LINK,
|
|
605 XD_OPAQUE_PTR,
|
|
606 XD_STRUCT_PTR,
|
771
|
607 XD_STRUCT_ARRAY,
|
428
|
608 XD_OPAQUE_DATA_PTR,
|
771
|
609 XD_UNION,
|
428
|
610 XD_C_STRING,
|
|
611 XD_DOC_STRING,
|
|
612 XD_INT_RESET,
|
665
|
613 XD_BYTECOUNT,
|
|
614 XD_ELEMCOUNT,
|
|
615 XD_HASHCODE,
|
428
|
616 XD_INT,
|
|
617 XD_LONG,
|
|
618 XD_END,
|
771
|
619 XD_SPECIFIER_END,
|
|
620 XD_CODING_SYSTEM_END
|
428
|
621 };
|
|
622
|
647
|
623 struct lrecord_description
|
|
624 {
|
428
|
625 enum lrecord_description_type type;
|
|
626 int offset;
|
|
627 EMACS_INT data1;
|
|
628 const struct struct_description *data2;
|
|
629 };
|
|
630
|
647
|
631 struct struct_description
|
|
632 {
|
665
|
633 Bytecount size;
|
428
|
634 const struct lrecord_description *description;
|
|
635 };
|
|
636
|
|
637 #define XD_INDIRECT(val, delta) (-1-((val)|(delta<<8)))
|
|
638
|
|
639 #define XD_IS_INDIRECT(code) (code<0)
|
|
640 #define XD_INDIRECT_VAL(code) ((-1-code) & 255)
|
|
641 #define XD_INDIRECT_DELTA(code) (((-1-code)>>8) & 255)
|
|
642
|
|
643 #define XD_DYNARR_DESC(base_type, sub_desc) \
|
440
|
644 { XD_STRUCT_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), sub_desc }, \
|
|
645 { XD_INT, offsetof (base_type, cur) }, \
|
|
646 { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) }
|
428
|
647
|
|
648 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
|
|
649 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
|
|
650 */
|
|
651
|
800
|
652 #if defined (ERROR_CHECK_TYPES)
|
|
653 # define DECLARE_ERROR_CHECK_TYPES(c_name, structtype)
|
428
|
654 #else
|
800
|
655 # define DECLARE_ERROR_CHECK_TYPES(c_name, structtype)
|
428
|
656 #endif
|
|
657
|
934
|
658
|
|
659 #ifdef USE_KKCC
|
|
660 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
661 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
662
|
|
663 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
664 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
|
|
665
|
|
666 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
667 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
668
|
|
669 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
670 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
|
671
|
|
672 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
673 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
674
|
|
675 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
676 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
|
|
677
|
|
678 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
|
679 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
|
|
680
|
|
681 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
|
682 DECLARE_ERROR_CHECK_TYPES(c_name, structtype) \
|
|
683 const struct lrecord_implementation lrecord_##c_name = \
|
|
684 { name, dumpable, marker, printer, nuker, equal, hash, desc, \
|
|
685 getprop, putprop, remprop, plist, size, sizer, \
|
|
686 lrecord_type_##c_name, basic_p }
|
|
687
|
|
688 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
689 DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
690
|
|
691 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
692 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
|
693
|
|
694 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
695 DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
696
|
|
697 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
|
698 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
|
|
699
|
|
700 #define MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
|
701 DECLARE_ERROR_CHECK_TYPES(c_name, structtype) \
|
|
702 int lrecord_type_##c_name; \
|
|
703 struct lrecord_implementation lrecord_##c_name = \
|
|
704 { name, dumpable, marker, printer, nuker, equal, hash, desc, \
|
|
705 getprop, putprop, remprop, plist, size, sizer, \
|
|
706 lrecord_type_last_built_in_type, basic_p }
|
|
707
|
|
708 #else /* not USE_KKCC */
|
|
709
|
428
|
710 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
711 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
712
|
442
|
713 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
934
|
714 MAKE_LRECORD_IMPLEMENTATION(name,c_name,0,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
|
428
|
715
|
|
716 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
717 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
718
|
442
|
719 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
934
|
720 MAKE_LRECORD_IMPLEMENTATION(name,c_name,0,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
428
|
721
|
|
722 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
723 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
724
|
442
|
725 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
934
|
726 MAKE_LRECORD_IMPLEMENTATION(name,c_name,0,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
|
428
|
727
|
442
|
728 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
934
|
729 MAKE_LRECORD_IMPLEMENTATION(name,c_name,0,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
|
442
|
730
|
934
|
731 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
800
|
732 DECLARE_ERROR_CHECK_TYPES(c_name, structtype) \
|
442
|
733 const struct lrecord_implementation lrecord_##c_name = \
|
934
|
734 { name, dumpable, marker, printer, nuker, equal, hash, desc, \
|
442
|
735 getprop, putprop, remprop, plist, size, sizer, \
|
|
736 lrecord_type_##c_name, basic_p }
|
|
737
|
|
738 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
739 DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
740
|
|
741 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
934
|
742 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,0,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
442
|
743
|
|
744 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
745 DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
746
|
|
747 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
934
|
748 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,0,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
|
442
|
749
|
934
|
750 #define MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
800
|
751 DECLARE_ERROR_CHECK_TYPES(c_name, structtype) \
|
647
|
752 int lrecord_type_##c_name; \
|
444
|
753 struct lrecord_implementation lrecord_##c_name = \
|
934
|
754 { name, dumpable, marker, printer, nuker, equal, hash, desc, \
|
442
|
755 getprop, putprop, remprop, plist, size, sizer, \
|
444
|
756 lrecord_type_last_built_in_type, basic_p }
|
934
|
757 #endif /* not USE_KKCC */
|
442
|
758
|
|
759 extern Lisp_Object (*lrecord_markers[]) (Lisp_Object);
|
|
760
|
|
761 #define INIT_LRECORD_IMPLEMENTATION(type) do { \
|
|
762 lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
|
|
763 lrecord_markers[lrecord_type_##type] = \
|
|
764 lrecord_implementations_table[lrecord_type_##type]->marker; \
|
|
765 } while (0)
|
428
|
766
|
444
|
767 #define INIT_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
|
|
768 lrecord_type_##type = lrecord_type_count++; \
|
|
769 lrecord_##type.lrecord_type_index = lrecord_type_##type; \
|
|
770 INIT_LRECORD_IMPLEMENTATION(type); \
|
|
771 } while (0)
|
|
772
|
996
|
773 #ifdef HAVE_SHLIB
|
|
774 /* Allow undefining types in order to support module unloading. */
|
|
775
|
|
776 #define UNDEF_LRECORD_IMPLEMENTATION(type) do { \
|
|
777 lrecord_implementations_table[lrecord_type_##type] = NULL; \
|
|
778 lrecord_markers[lrecord_type_##type] = NULL; \
|
|
779 } while (0)
|
|
780
|
|
781 #define UNDEF_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
|
|
782 if (lrecord_##type.lrecord_type_index == lrecord_type_count - 1) { \
|
|
783 /* This is the most recently defined type. Clean up nicely. */ \
|
|
784 lrecord_type_##type = lrecord_type_count--; \
|
|
785 } /* Else we can't help leaving a hole with this implementation. */ \
|
|
786 UNDEF_LRECORD_IMPLEMENTATION(type); \
|
|
787 } while (0)
|
|
788
|
|
789 #endif /* HAVE_SHLIB */
|
|
790
|
428
|
791 #define LRECORDP(a) (XTYPE (a) == Lisp_Type_Record)
|
|
792 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
|
|
793
|
|
794 #define RECORD_TYPEP(x, ty) \
|
647
|
795 (LRECORDP (x) && (XRECORD_LHEADER (x)->type == (unsigned int) (ty)))
|
442
|
796
|
|
797 /* Steps to create a new object:
|
|
798
|
|
799 1. Declare the struct for your object in a header file somewhere.
|
|
800 Remember that it must begin with
|
|
801
|
|
802 struct lcrecord_header header;
|
|
803
|
793
|
804 2. Put the "standard junk" (DECLARE_RECORD()/XFOO/etc.) below the
|
617
|
805 struct definition -- see below.
|
442
|
806
|
|
807 3. Add this header file to inline.c.
|
|
808
|
|
809 4. Create the methods for your object. Note that technically you don't
|
|
810 need any, but you will almost always want at least a mark method.
|
|
811
|
|
812 5. Define your object with DEFINE_LRECORD_IMPLEMENTATION() or some
|
|
813 variant.
|
|
814
|
|
815 6. Include the header file in the .c file where you defined the object.
|
|
816
|
|
817 7. Put a call to INIT_LRECORD_IMPLEMENTATION() for the object in the
|
|
818 .c file's syms_of_foo() function.
|
|
819
|
|
820 8. Add a type enum for the object to enum lrecord_type, earlier in this
|
|
821 file.
|
|
822
|
|
823 An example:
|
428
|
824
|
442
|
825 ------------------------------ in toolbar.h -----------------------------
|
|
826
|
|
827 struct toolbar_button
|
|
828 {
|
|
829 struct lcrecord_header header;
|
|
830
|
|
831 Lisp_Object next;
|
|
832 Lisp_Object frame;
|
|
833
|
|
834 Lisp_Object up_glyph;
|
|
835 Lisp_Object down_glyph;
|
|
836 Lisp_Object disabled_glyph;
|
|
837
|
|
838 Lisp_Object cap_up_glyph;
|
|
839 Lisp_Object cap_down_glyph;
|
|
840 Lisp_Object cap_disabled_glyph;
|
|
841
|
|
842 Lisp_Object callback;
|
|
843 Lisp_Object enabled_p;
|
|
844 Lisp_Object help_string;
|
|
845
|
|
846 char enabled;
|
|
847 char down;
|
|
848 char pushright;
|
|
849 char blank;
|
|
850
|
|
851 int x, y;
|
|
852 int width, height;
|
|
853 int dirty;
|
|
854 int vertical;
|
|
855 int border_width;
|
|
856 };
|
428
|
857
|
617
|
858 [[ the standard junk: ]]
|
|
859
|
442
|
860 DECLARE_LRECORD (toolbar_button, struct toolbar_button);
|
|
861 #define XTOOLBAR_BUTTON(x) XRECORD (x, toolbar_button, struct toolbar_button)
|
617
|
862 #define wrap_toolbar_button(p) wrap_record (p, toolbar_button)
|
442
|
863 #define TOOLBAR_BUTTONP(x) RECORDP (x, toolbar_button)
|
|
864 #define CHECK_TOOLBAR_BUTTON(x) CHECK_RECORD (x, toolbar_button)
|
|
865 #define CONCHECK_TOOLBAR_BUTTON(x) CONCHECK_RECORD (x, toolbar_button)
|
|
866
|
|
867 ------------------------------ in toolbar.c -----------------------------
|
|
868
|
|
869 #include "toolbar.h"
|
|
870
|
|
871 ...
|
|
872
|
|
873 static Lisp_Object
|
|
874 mark_toolbar_button (Lisp_Object obj)
|
|
875 {
|
|
876 struct toolbar_button *data = XTOOLBAR_BUTTON (obj);
|
|
877 mark_object (data->next);
|
|
878 mark_object (data->frame);
|
|
879 mark_object (data->up_glyph);
|
|
880 mark_object (data->down_glyph);
|
|
881 mark_object (data->disabled_glyph);
|
|
882 mark_object (data->cap_up_glyph);
|
|
883 mark_object (data->cap_down_glyph);
|
|
884 mark_object (data->cap_disabled_glyph);
|
|
885 mark_object (data->callback);
|
|
886 mark_object (data->enabled_p);
|
|
887 return data->help_string;
|
|
888 }
|
|
889
|
617
|
890 [[ If your object should never escape to Lisp, declare its print method
|
|
891 as internal_object_printer instead of 0. ]]
|
|
892
|
442
|
893 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-button", toolbar_button,
|
617
|
894 mark_toolbar_button, 0,
|
|
895 0, 0, 0, 0, struct toolbar_button);
|
442
|
896
|
|
897 ...
|
|
898
|
|
899 void
|
|
900 syms_of_toolbar (void)
|
|
901 {
|
|
902 INIT_LRECORD_IMPLEMENTATION (toolbar_button);
|
|
903
|
|
904 ...;
|
|
905 }
|
|
906
|
|
907 ------------------------------ in inline.c -----------------------------
|
|
908
|
|
909 #ifdef HAVE_TOOLBARS
|
|
910 #include "toolbar.h"
|
|
911 #endif
|
|
912
|
|
913 ------------------------------ in lrecord.h -----------------------------
|
|
914
|
|
915 enum lrecord_type
|
|
916 {
|
|
917 ...
|
|
918 lrecord_type_toolbar_button,
|
|
919 ...
|
|
920 };
|
|
921
|
|
922 */
|
|
923
|
|
924 /*
|
|
925
|
|
926 Note: Object types defined in external dynamically-loaded modules (not
|
|
927 part of the XEmacs main source code) should use DECLARE_EXTERNAL_LRECORD
|
|
928 and DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION rather than DECLARE_LRECORD
|
|
929 and DEFINE_LRECORD_IMPLEMENTATION.
|
|
930
|
|
931 */
|
|
932
|
428
|
933
|
800
|
934 #ifdef ERROR_CHECK_TYPES
|
428
|
935
|
788
|
936 # define DECLARE_LRECORD(c_name, structtype) \
|
|
937 extern const struct lrecord_implementation lrecord_##c_name; \
|
826
|
938 DECLARE_INLINE_HEADER ( \
|
|
939 structtype * \
|
788
|
940 error_check_##c_name (Lisp_Object obj, const char *file, int line) \
|
826
|
941 ) \
|
788
|
942 { \
|
|
943 assert_at_line (RECORD_TYPEP (obj, lrecord_type_##c_name), file, line); \
|
|
944 return (structtype *) XPNTR (obj); \
|
|
945 } \
|
428
|
946 extern Lisp_Object Q##c_name##p
|
|
947
|
788
|
948 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
|
|
949 extern int lrecord_type_##c_name; \
|
|
950 extern struct lrecord_implementation lrecord_##c_name; \
|
826
|
951 DECLARE_INLINE_HEADER ( \
|
|
952 structtype * \
|
788
|
953 error_check_##c_name (Lisp_Object obj, const char *file, int line) \
|
826
|
954 ) \
|
788
|
955 { \
|
|
956 assert_at_line (RECORD_TYPEP (obj, lrecord_type_##c_name), file, line); \
|
|
957 return (structtype *) XPNTR (obj); \
|
|
958 } \
|
444
|
959 extern Lisp_Object Q##c_name##p
|
442
|
960
|
788
|
961 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
826
|
962 DECLARE_INLINE_HEADER ( \
|
|
963 structtype * \
|
788
|
964 error_check_##c_name (Lisp_Object obj, const char *file, int line) \
|
826
|
965 ) \
|
788
|
966 { \
|
|
967 assert_at_line (XTYPE (obj) == type_enum, file, line); \
|
|
968 return (structtype *) XPNTR (obj); \
|
|
969 } \
|
428
|
970 extern Lisp_Object Q##c_name##p
|
|
971
|
788
|
972 # define XRECORD(x, c_name, structtype) \
|
|
973 error_check_##c_name (x, __FILE__, __LINE__)
|
|
974 # define XNONRECORD(x, c_name, type_enum, structtype) \
|
|
975 error_check_##c_name (x, __FILE__, __LINE__)
|
428
|
976
|
826
|
977 DECLARE_INLINE_HEADER (
|
|
978 Lisp_Object
|
800
|
979 wrap_record_1 (const void *ptr, enum lrecord_type ty, const char *file,
|
|
980 int line)
|
826
|
981 )
|
617
|
982 {
|
793
|
983 Lisp_Object obj = wrap_pointer_1 (ptr);
|
|
984
|
788
|
985 assert_at_line (RECORD_TYPEP (obj, ty), file, line);
|
617
|
986 return obj;
|
|
987 }
|
|
988
|
788
|
989 #define wrap_record(ptr, ty) \
|
|
990 wrap_record_1 (ptr, lrecord_type_##ty, __FILE__, __LINE__)
|
617
|
991
|
800
|
992 #else /* not ERROR_CHECK_TYPES */
|
428
|
993
|
|
994 # define DECLARE_LRECORD(c_name, structtype) \
|
|
995 extern Lisp_Object Q##c_name##p; \
|
442
|
996 extern const struct lrecord_implementation lrecord_##c_name
|
|
997 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
|
|
998 extern Lisp_Object Q##c_name##p; \
|
647
|
999 extern int lrecord_type_##c_name; \
|
444
|
1000 extern struct lrecord_implementation lrecord_##c_name
|
428
|
1001 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
|
1002 extern Lisp_Object Q##c_name##p
|
|
1003 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
|
|
1004 # define XNONRECORD(x, c_name, type_enum, structtype) \
|
|
1005 ((structtype *) XPNTR (x))
|
617
|
1006 /* wrap_pointer_1 is so named as a suggestion not to use it unless you
|
|
1007 know what you're doing. */
|
|
1008 #define wrap_record(ptr, ty) wrap_pointer_1 (ptr)
|
428
|
1009
|
800
|
1010 #endif /* not ERROR_CHECK_TYPES */
|
428
|
1011
|
442
|
1012 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_type_##c_name)
|
428
|
1013
|
|
1014 /* Note: we now have two different kinds of type-checking macros.
|
|
1015 The "old" kind has now been renamed CONCHECK_foo. The reason for
|
|
1016 this is that the CONCHECK_foo macros signal a continuable error,
|
|
1017 allowing the user (through debug-on-error) to substitute a different
|
|
1018 value and return from the signal, which causes the lvalue argument
|
|
1019 to get changed. Quite a lot of code would crash if that happened,
|
|
1020 because it did things like
|
|
1021
|
|
1022 foo = XCAR (list);
|
|
1023 CHECK_STRING (foo);
|
|
1024
|
|
1025 and later on did XSTRING (XCAR (list)), assuming that the type
|
|
1026 is correct (when it might be wrong, if the user substituted a
|
|
1027 correct value in the debugger).
|
|
1028
|
|
1029 To get around this, I made all the CHECK_foo macros signal a
|
|
1030 non-continuable error. Places where a continuable error is OK
|
|
1031 (generally only when called directly on the argument of a Lisp
|
|
1032 primitive) should be changed to use CONCHECK().
|
|
1033
|
|
1034 FSF Emacs does not have this problem because RMS took the cheesy
|
|
1035 way out and disabled returning from a signal entirely. */
|
|
1036
|
|
1037 #define CONCHECK_RECORD(x, c_name) do { \
|
442
|
1038 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
|
428
|
1039 x = wrong_type_argument (Q##c_name##p, x); \
|
|
1040 } while (0)
|
|
1041 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
|
|
1042 if (XTYPE (x) != lisp_enum) \
|
|
1043 x = wrong_type_argument (predicate, x); \
|
|
1044 } while (0)
|
|
1045 #define CHECK_RECORD(x, c_name) do { \
|
442
|
1046 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
|
428
|
1047 dead_wrong_type_argument (Q##c_name##p, x); \
|
|
1048 } while (0)
|
|
1049 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
|
|
1050 if (XTYPE (x) != lisp_enum) \
|
|
1051 dead_wrong_type_argument (predicate, x); \
|
|
1052 } while (0)
|
|
1053
|
826
|
1054 /* Various ways of allocating lcrecords. All bytes (except lcrecord
|
|
1055 header) are zeroed in returned structure. */
|
|
1056
|
665
|
1057 void *alloc_lcrecord (Bytecount size,
|
647
|
1058 const struct lrecord_implementation *);
|
428
|
1059
|
771
|
1060 void *alloc_automanaged_lcrecord (Bytecount size,
|
|
1061 const struct lrecord_implementation *);
|
|
1062
|
|
1063 #define alloc_unmanaged_lcrecord_type(type, lrecord_implementation) \
|
|
1064 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
|
|
1065
|
428
|
1066 #define alloc_lcrecord_type(type, lrecord_implementation) \
|
771
|
1067 ((type *) alloc_automanaged_lcrecord (sizeof (type), lrecord_implementation))
|
|
1068
|
|
1069 void free_lcrecord (Lisp_Object rec);
|
|
1070
|
428
|
1071
|
|
1072 /* Copy the data from one lcrecord structure into another, but don't
|
|
1073 overwrite the header information. */
|
|
1074
|
771
|
1075 #define copy_sized_lcrecord(dst, src, size) \
|
430
|
1076 memcpy ((char *) (dst) + sizeof (struct lcrecord_header), \
|
|
1077 (char *) (src) + sizeof (struct lcrecord_header), \
|
771
|
1078 (size) - sizeof (struct lcrecord_header))
|
|
1079
|
|
1080 #define copy_lcrecord(dst, src) copy_sized_lcrecord (dst, src, sizeof (*(dst)))
|
428
|
1081
|
771
|
1082 #define zero_sized_lcrecord(lcr, size) \
|
430
|
1083 memset ((char *) (lcr) + sizeof (struct lcrecord_header), 0, \
|
771
|
1084 (size) - sizeof (struct lcrecord_header))
|
|
1085
|
|
1086 #define zero_lcrecord(lcr) zero_sized_lcrecord(lcr, sizeof (*(lcr)))
|
428
|
1087
|
440
|
1088 #endif /* INCLUDED_lrecord_h_ */
|