428
|
1 /* The "lrecord" structure (header of a compound lisp object).
|
|
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
2367
|
3 Copyright (C) 1996, 2001, 2002, 2004 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
|
2367
|
24 /* This file has been Mule-ized, Ben Wing, 10-13-04. */
|
|
25
|
440
|
26 #ifndef INCLUDED_lrecord_h_
|
|
27 #define INCLUDED_lrecord_h_
|
428
|
28
|
|
29 /* The "lrecord" type of Lisp object is used for all object types
|
|
30 other than a few simple ones. This allows many types to be
|
442
|
31 implemented but only a few bits required in a Lisp object for type
|
|
32 information. (The tradeoff is that each object has its type marked
|
|
33 in it, thereby increasing its size.) All lrecords begin with a
|
|
34 `struct lrecord_header', which identifies the lisp object type, by
|
|
35 providing an index into a table of `struct lrecord_implementation',
|
|
36 which describes the behavior of the lisp object. It also contains
|
|
37 some other data bits.
|
428
|
38
|
|
39 Lrecords are of two types: straight lrecords, and lcrecords.
|
|
40 Straight lrecords are used for those types of objects that have
|
|
41 their own allocation routines (typically allocated out of 2K chunks
|
|
42 of memory called `frob blocks'). These objects have a `struct
|
|
43 lrecord_header' at the top, containing only the bits needed to find
|
|
44 the lrecord_implementation for the object. There are special
|
1204
|
45 routines in alloc.c to create an object of each such type.
|
428
|
46
|
442
|
47 Lcrecords are used for less common sorts of objects that don't do
|
|
48 their own allocation. Each such object is malloc()ed individually,
|
|
49 and the objects are chained together through a `next' pointer.
|
|
50 Lcrecords have a `struct lcrecord_header' at the top, which
|
|
51 contains a `struct lrecord_header' and a `next' pointer, and are
|
1204
|
52 allocated using alloc_lcrecord_type() or its variants.
|
428
|
53
|
|
54 Creating a new lcrecord type is fairly easy; just follow the
|
|
55 lead of some existing type (e.g. hash tables). Note that you
|
|
56 do not need to supply all the methods (see below); reasonable
|
|
57 defaults are provided for many of them. Alternatively, if you're
|
|
58 just looking for a way of encapsulating data (which possibly
|
|
59 could contain Lisp_Objects in it), you may well be able to use
|
1204
|
60 the opaque type. --ben
|
|
61 */
|
428
|
62
|
1743
|
63 BEGIN_C_DECLS
|
1650
|
64
|
428
|
65 struct lrecord_header
|
|
66 {
|
1204
|
67 /* Index into lrecord_implementations_table[]. Objects that have been
|
|
68 explicitly freed using e.g. free_cons() have lrecord_type_free in this
|
|
69 field. */
|
442
|
70 unsigned int type :8;
|
|
71
|
|
72 /* If `mark' is 0 after the GC mark phase, the object will be freed
|
|
73 during the GC sweep phase. There are 2 ways that `mark' can be 1:
|
|
74 - by being referenced from other objects during the GC mark phase
|
|
75 - because it is permanently on, for c_readonly objects */
|
|
76 unsigned int mark :1;
|
|
77
|
|
78 /* 1 if the object resides in logically read-only space, and does not
|
|
79 reference other non-c_readonly objects.
|
|
80 Invariant: if (c_readonly == 1), then (mark == 1 && lisp_readonly == 1) */
|
|
81 unsigned int c_readonly :1;
|
|
82
|
428
|
83 /* 1 if the object is readonly from lisp */
|
442
|
84 unsigned int lisp_readonly :1;
|
771
|
85
|
|
86 unsigned int unused :21;
|
934
|
87
|
428
|
88 };
|
|
89
|
|
90 struct lrecord_implementation;
|
442
|
91 int lrecord_type_index (const struct lrecord_implementation *implementation);
|
428
|
92
|
430
|
93 #define set_lheader_implementation(header,imp) do { \
|
428
|
94 struct lrecord_header* SLI_header = (header); \
|
442
|
95 SLI_header->type = (imp)->lrecord_type_index; \
|
430
|
96 SLI_header->mark = 0; \
|
|
97 SLI_header->c_readonly = 0; \
|
|
98 SLI_header->lisp_readonly = 0; \
|
428
|
99 } while (0)
|
|
100
|
|
101 struct lcrecord_header
|
|
102 {
|
|
103 struct lrecord_header lheader;
|
|
104
|
442
|
105 /* The `next' field is normally used to chain all lcrecords together
|
428
|
106 so that the GC can find (and free) all of them.
|
1204
|
107 `basic_alloc_lcrecord' threads lcrecords together.
|
428
|
108
|
|
109 The `next' field may be used for other purposes as long as some
|
|
110 other mechanism is provided for letting the GC do its work.
|
|
111
|
|
112 For example, the event and marker object types allocate members
|
|
113 out of memory chunks, and are able to find all unmarked members
|
|
114 by sweeping through the elements of the list of chunks. */
|
|
115 struct lcrecord_header *next;
|
|
116
|
|
117 /* The `uid' field is just for debugging/printing convenience.
|
|
118 Having this slot doesn't hurt us much spacewise, since an
|
|
119 lcrecord already has the above slots plus malloc overhead. */
|
|
120 unsigned int uid :31;
|
|
121
|
|
122 /* The `free' field is a flag that indicates whether this lcrecord
|
|
123 is on a "free list". Free lists are used to minimize the number
|
|
124 of calls to malloc() when we're repeatedly allocating and freeing
|
|
125 a number of the same sort of lcrecord. Lcrecords on a free list
|
|
126 always get marked in a different fashion, so we can use this flag
|
|
127 as a sanity check to make sure that free lists only have freed
|
|
128 lcrecords and there are no freed lcrecords elsewhere. */
|
|
129 unsigned int free :1;
|
|
130 };
|
|
131
|
|
132 /* Used for lcrecords in an lcrecord-list. */
|
|
133 struct free_lcrecord_header
|
|
134 {
|
|
135 struct lcrecord_header lcheader;
|
|
136 Lisp_Object chain;
|
|
137 };
|
|
138
|
442
|
139 enum lrecord_type
|
|
140 {
|
|
141 /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast.
|
|
142 #### This should be replaced by a symbol_value_magic_p flag
|
|
143 in the Lisp_Symbol lrecord_header. */
|
1204
|
144 lrecord_type_symbol_value_forward, /* 0 */
|
|
145 lrecord_type_symbol_value_varalias, /* 1 */
|
|
146 lrecord_type_symbol_value_lisp_magic, /* 2 */
|
|
147 lrecord_type_symbol_value_buffer_local, /* 3 */
|
442
|
148 lrecord_type_max_symbol_value_magic = lrecord_type_symbol_value_buffer_local,
|
|
149
|
1204
|
150 lrecord_type_symbol, /* 4 */
|
|
151 lrecord_type_subr, /* 5 */
|
|
152 lrecord_type_cons, /* 6 */
|
442
|
153 lrecord_type_vector,
|
|
154 lrecord_type_string,
|
|
155 lrecord_type_lcrecord_list,
|
|
156 lrecord_type_compiled_function,
|
|
157 lrecord_type_weak_list,
|
|
158 lrecord_type_bit_vector,
|
|
159 lrecord_type_float,
|
|
160 lrecord_type_hash_table,
|
|
161 lrecord_type_lstream,
|
|
162 lrecord_type_process,
|
|
163 lrecord_type_charset,
|
|
164 lrecord_type_coding_system,
|
|
165 lrecord_type_char_table,
|
|
166 lrecord_type_char_table_entry,
|
|
167 lrecord_type_range_table,
|
|
168 lrecord_type_opaque,
|
|
169 lrecord_type_opaque_ptr,
|
|
170 lrecord_type_buffer,
|
|
171 lrecord_type_extent,
|
|
172 lrecord_type_extent_info,
|
|
173 lrecord_type_extent_auxiliary,
|
|
174 lrecord_type_marker,
|
|
175 lrecord_type_event,
|
1204
|
176 #ifdef EVENT_DATA_AS_OBJECTS
|
934
|
177 lrecord_type_key_data,
|
|
178 lrecord_type_button_data,
|
|
179 lrecord_type_motion_data,
|
|
180 lrecord_type_process_data,
|
|
181 lrecord_type_timeout_data,
|
|
182 lrecord_type_eval_data,
|
|
183 lrecord_type_misc_user_data,
|
|
184 lrecord_type_magic_eval_data,
|
|
185 lrecord_type_magic_data,
|
1204
|
186 #endif /* EVENT_DATA_AS_OBJECTS */
|
442
|
187 lrecord_type_keymap,
|
|
188 lrecord_type_command_builder,
|
|
189 lrecord_type_timeout,
|
|
190 lrecord_type_specifier,
|
|
191 lrecord_type_console,
|
|
192 lrecord_type_device,
|
|
193 lrecord_type_frame,
|
|
194 lrecord_type_window,
|
617
|
195 lrecord_type_window_mirror,
|
442
|
196 lrecord_type_window_configuration,
|
|
197 lrecord_type_gui_item,
|
|
198 lrecord_type_popup_data,
|
|
199 lrecord_type_toolbar_button,
|
617
|
200 lrecord_type_scrollbar_instance,
|
442
|
201 lrecord_type_color_instance,
|
|
202 lrecord_type_font_instance,
|
|
203 lrecord_type_image_instance,
|
|
204 lrecord_type_glyph,
|
|
205 lrecord_type_face,
|
|
206 lrecord_type_database,
|
|
207 lrecord_type_tooltalk_message,
|
|
208 lrecord_type_tooltalk_pattern,
|
|
209 lrecord_type_ldap,
|
|
210 lrecord_type_pgconn,
|
|
211 lrecord_type_pgresult,
|
|
212 lrecord_type_devmode,
|
|
213 lrecord_type_mswindows_dialog_id,
|
446
|
214 lrecord_type_case_table,
|
462
|
215 lrecord_type_emacs_ffi,
|
|
216 lrecord_type_emacs_gtk_object,
|
|
217 lrecord_type_emacs_gtk_boxed,
|
858
|
218 lrecord_type_weak_box,
|
888
|
219 lrecord_type_ephemeron,
|
1983
|
220 lrecord_type_bignum,
|
|
221 lrecord_type_ratio,
|
|
222 lrecord_type_bigfloat,
|
454
|
223 lrecord_type_free, /* only used for "free" lrecords */
|
|
224 lrecord_type_undefined, /* only used for debugging */
|
442
|
225 lrecord_type_last_built_in_type /* must be last */
|
|
226 };
|
|
227
|
1632
|
228 extern MODULE_API int lrecord_type_count;
|
428
|
229
|
|
230 struct lrecord_implementation
|
|
231 {
|
2367
|
232 const Ascbyte *name;
|
442
|
233
|
934
|
234 /* information for the dumper: is the object dumpable and should it
|
|
235 be dumped. */
|
|
236 unsigned int dumpable :1;
|
|
237
|
442
|
238 /* `marker' is called at GC time, to make sure that all Lisp_Objects
|
428
|
239 pointed to by this object get properly marked. It should call
|
|
240 the mark_object function on all Lisp_Objects in the object. If
|
|
241 the return value is non-nil, it should be a Lisp_Object to be
|
|
242 marked (don't call the mark_object function explicitly on it,
|
|
243 because the GC routines will do this). Doing it this way reduces
|
|
244 recursion, so the object returned should preferably be the one
|
|
245 with the deepest level of Lisp_Object pointers. This function
|
1204
|
246 can be NULL, meaning no GC marking is necessary.
|
|
247
|
|
248 NOTE NOTE NOTE: This is not used by KKCC (which uses the data
|
|
249 description below instead), unless the data description is missing.
|
|
250 Yes, this currently means there is logic duplication. Eventually the
|
|
251 mark methods will be removed. */
|
428
|
252 Lisp_Object (*marker) (Lisp_Object);
|
442
|
253
|
|
254 /* `printer' converts the object to a printed representation.
|
|
255 This can be NULL; in this case default_object_printer() will be
|
|
256 used instead. */
|
428
|
257 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
|
442
|
258
|
|
259 /* `finalizer' is called at GC time when the object is about to
|
428
|
260 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
|
|
261 case). It should perform any necessary cleanup (e.g. freeing
|
442
|
262 malloc()ed memory). This can be NULL, meaning no special
|
428
|
263 finalization is necessary.
|
|
264
|
442
|
265 WARNING: remember that `finalizer' is called at dump time even
|
428
|
266 though the object is not being freed. */
|
|
267 void (*finalizer) (void *header, int for_disksave);
|
442
|
268
|
428
|
269 /* This can be NULL, meaning compare objects with EQ(). */
|
|
270 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
|
442
|
271
|
|
272 /* `hash' generates hash values for use with hash tables that have
|
|
273 `equal' as their test function. This can be NULL, meaning use
|
|
274 the Lisp_Object itself as the hash. But, you must still satisfy
|
|
275 the constraint that if two objects are `equal', then they *must*
|
|
276 hash to the same value in order for hash tables to work properly.
|
|
277 This means that `hash' can be NULL only if the `equal' method is
|
|
278 also NULL. */
|
2515
|
279 Hashcode (*hash) (Lisp_Object, int);
|
428
|
280
|
1204
|
281 /* Data layout description for your object. See long comment below. */
|
|
282 const struct memory_description *description;
|
428
|
283
|
442
|
284 /* These functions allow any object type to have builtin property
|
|
285 lists that can be manipulated from the lisp level with
|
|
286 `get', `put', `remprop', and `object-plist'. */
|
428
|
287 Lisp_Object (*getprop) (Lisp_Object obj, Lisp_Object prop);
|
|
288 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
|
|
289 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
|
|
290 Lisp_Object (*plist) (Lisp_Object obj);
|
|
291
|
442
|
292 /* Only one of `static_size' and `size_in_bytes_method' is non-0.
|
1204
|
293 If both are 0, this type is not instantiable by basic_alloc_lcrecord(). */
|
665
|
294 Bytecount static_size;
|
|
295 Bytecount (*size_in_bytes_method) (const void *header);
|
442
|
296
|
|
297 /* The (constant) index into lrecord_implementations_table */
|
|
298 enum lrecord_type lrecord_type_index;
|
|
299
|
428
|
300 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
|
|
301 one that does not have an lcrecord_header at the front and which
|
1204
|
302 is (usually) allocated in frob blocks. */
|
442
|
303 unsigned int basic_p :1;
|
428
|
304 };
|
|
305
|
617
|
306 /* All the built-in lisp object types are enumerated in `enum lrecord_type'.
|
442
|
307 Additional ones may be defined by a module (none yet). We leave some
|
|
308 room in `lrecord_implementations_table' for such new lisp object types. */
|
|
309 #define MODULE_DEFINABLE_TYPE_COUNT 32
|
|
310
|
1632
|
311 extern MODULE_API const struct lrecord_implementation *
|
|
312 lrecord_implementations_table[lrecord_type_last_built_in_type + MODULE_DEFINABLE_TYPE_COUNT];
|
428
|
313
|
|
314 #define XRECORD_LHEADER_IMPLEMENTATION(obj) \
|
442
|
315 LHEADER_IMPLEMENTATION (XRECORD_LHEADER (obj))
|
|
316 #define LHEADER_IMPLEMENTATION(lh) lrecord_implementations_table[(lh)->type]
|
428
|
317
|
|
318 extern int gc_in_progress;
|
|
319
|
442
|
320 #define MARKED_RECORD_P(obj) (XRECORD_LHEADER (obj)->mark)
|
428
|
321 #define MARKED_RECORD_HEADER_P(lheader) ((lheader)->mark)
|
|
322 #define MARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 1))
|
|
323 #define UNMARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 0))
|
|
324
|
|
325 #define C_READONLY_RECORD_HEADER_P(lheader) ((lheader)->c_readonly)
|
|
326 #define LISP_READONLY_RECORD_HEADER_P(lheader) ((lheader)->lisp_readonly)
|
442
|
327 #define SET_C_READONLY_RECORD_HEADER(lheader) do { \
|
|
328 struct lrecord_header *SCRRH_lheader = (lheader); \
|
|
329 SCRRH_lheader->c_readonly = 1; \
|
|
330 SCRRH_lheader->lisp_readonly = 1; \
|
|
331 SCRRH_lheader->mark = 1; \
|
|
332 } while (0)
|
428
|
333 #define SET_LISP_READONLY_RECORD_HEADER(lheader) \
|
|
334 ((void) ((lheader)->lisp_readonly = 1))
|
1676
|
335
|
|
336 #ifdef USE_KKCC
|
|
337 #define RECORD_DESCRIPTION(lheader) lrecord_memory_descriptions[(lheader)->type]
|
|
338 #else /* not USE_KKCC */
|
442
|
339 #define RECORD_MARKER(lheader) lrecord_markers[(lheader)->type]
|
1676
|
340 #endif /* not USE_KKCC */
|
428
|
341
|
934
|
342 #define RECORD_DUMPABLE(lheader) (lrecord_implementations_table[(lheader)->type])->dumpable
|
1204
|
343
|
|
344 /* Data description stuff
|
934
|
345
|
1204
|
346 Data layout descriptions describe blocks of memory (in particular, Lisp
|
|
347 objects and other objects on the heap, and global objects with pointers
|
|
348 to such heap objects), including their size and a list of the elements
|
|
349 that need relocating, marking or other special handling. They are
|
|
350 currently used in two places: by pdump [the new, portable dumper] and
|
|
351 KKCC [the new garbage collector]. The two subsystems use the
|
|
352 descriptions in different ways, and as a result some of the descriptions
|
|
353 are appropriate only for one or the other, when it is known that only
|
|
354 that subsystem will use the description. (This is particularly the case
|
|
355 with objects that can't be dumped, because pdump needs more info than
|
|
356 KKCC.) However, properly written descriptions are appropriate for both,
|
|
357 and you should strive to write your descriptions that way, since the
|
|
358 dumpable status of an object may change and new uses for the
|
|
359 descriptions may be created. (An example that comes to mind is a
|
|
360 facility for determining the memory usage of XEmacs data structures --
|
|
361 like `buffer-memory-usage', `window-memory-usage', etc. but more
|
|
362 general.)
|
|
363
|
|
364 More specifically:
|
428
|
365
|
1204
|
366 Pdump (the portable dumper) needs to write out all objects in heap
|
|
367 space, and later on (in another invocation of XEmacs) load them back
|
|
368 into the heap, relocating all pointers to the heap objects in the global
|
|
369 data space. ("Heap" means anything malloc()ed, including all Lisp
|
|
370 objects, and "global data" means anything declared globally or
|
|
371 `static'.) Pdump, then, needs to be told about the location of all
|
|
372 global pointers to heap objects, all the description of all such
|
|
373 objects, including their size and any pointers to other heap (aka
|
|
374 "relocatable") objects. (Pdump assumes that the heap may occur in
|
|
375 different places in different invocations -- therefore, it is not enough
|
|
376 simply to write out the entire heap and later reload it at the same
|
|
377 location -- but that global data is always in the same place, and hence
|
|
378 pointers to it do not need to be relocated. This assumption holds true
|
|
379 in general for modern operating systems, but would be broken, for
|
|
380 example, in a system without virtual memory, or when dealing with shared
|
|
381 libraries. Also, unlike unexec, pdump does not usually write out or
|
|
382 restore objects in the global data space, and thus they need to be
|
|
383 initialized every time XEmacs is loaded. This is the purpose of the
|
|
384 reinit_*() functions throughout XEmacs. [It's possible, however, to make
|
|
385 pdump restore global data. This must be done, of course, for heap
|
|
386 pointers, but is also done for other values that are not easy to
|
|
387 recompute -- in particular, values established by the Lisp code loaded
|
|
388 at dump time.]) Note that the data type `Lisp_Object' is basically just
|
|
389 a relocatable pointer disguised as a long, and in general pdump treats
|
|
390 the Lisp_Object values and pointers to Lisp objects (e.g. Lisp_Object
|
|
391 vs. `struct frame *') identically. (NOTE: This equivalence depends
|
|
392 crucially on the current "minimal tagbits" implementation of Lisp_Object
|
|
393 pointers.)
|
428
|
394
|
1204
|
395 Descriptions are used by pdump in three places: (a) descriptions of Lisp
|
|
396 objects, referenced in the DEFINE_*LRECORD_*IMPLEMENTATION*() call; (b)
|
|
397 descriptions of global objects to be dumped, registered by
|
|
398 dump_add_root_block(); (c) descriptions of global pointers to
|
2367
|
399 non-Lisp_Object heap objects, registered by dump_add_root_block_ptr().
|
1204
|
400 The descriptions need to tell pdump which elements of your structure are
|
|
401 Lisp_Objects or structure pointers, plus the descriptions in turn of the
|
|
402 non-Lisp_Object structures pointed to. If these structures are you own
|
|
403 private ones, you will have to write these recursive descriptions
|
|
404 yourself; otherwise, you are reusing a structure already in existence
|
|
405 elsewhere and there is probably already a description for it.
|
|
406
|
|
407 Pdump does not care about Lisp objects that cannot be dumped (the
|
|
408 dumpable flag to DEFINE_*LRECORD_*IMPLEMENTATION*() is 0).
|
|
409
|
|
410 KKCC also uses data layout descriptions, but differently. It cares
|
|
411 about all objects, dumpable or not, but specifically only wants to know
|
|
412 about Lisp_Objects in your object and in structures pointed to. Thus,
|
|
413 it doesn't care about things like pointers to structures ot other blocks
|
|
414 of memory with no Lisp Objects in them, which pdump would care a lot
|
|
415 about.
|
|
416
|
|
417 Technically, then, you could write your description differently
|
|
418 depending on whether your object is dumpable -- the full pdump
|
|
419 description if so, the abbreviated KKCC description if not. In fact,
|
|
420 some descriptions are written this way. This is dangerous, though,
|
|
421 because another use might come along for the data descriptions, that
|
|
422 doesn't care about the dumper flag and makes use of some of the stuff
|
|
423 normally omitted from the "abbreviated" description -- see above.
|
|
424
|
|
425 A memory_description is an array of values. (This is actually
|
771
|
426 misnamed, in that it does not just describe lrecords, but any
|
|
427 blocks of memory.) The first value of each line is a type, the
|
|
428 second the offset in the lrecord structure. The third and
|
|
429 following elements are parameters; their presence, type and number
|
|
430 is type-dependent.
|
|
431
|
1204
|
432 The description ends with an "XD_END" record.
|
771
|
433
|
|
434 The top-level description of an lrecord or lcrecord does not need
|
|
435 to describe every element, just the ones that need to be relocated,
|
|
436 since the size of the lrecord is known. (The same goes for nested
|
|
437 structures, whenever the structure size is given, rather than being
|
|
438 defaulted by specifying 0 for the size.)
|
|
439
|
1204
|
440 A sized_memory_description is a memory_description plus the size of the
|
|
441 block of memory. The size field in a sized_memory_description can be
|
|
442 given as zero, i.e. unspecified, meaning that the last element in the
|
|
443 structure is described in the description and the size of the block can
|
|
444 therefore be computed from it. (This is useful for stretchy arrays.)
|
|
445
|
|
446 memory_descriptions are used to describe lrecords (the size of the
|
|
447 lrecord is elsewhere in its description, attached to its methods, so it
|
|
448 does not need to be given here) and global objects, where the size is an
|
|
449 argument to the call to dump_add_root_block().
|
|
450 sized_memory_descriptions are used for pointers and arrays in
|
2367
|
451 memory_descriptions and for calls to dump_add_root_block_ptr(). (####
|
1204
|
452 It is not obvious why this is so in the latter case. Probably, calls to
|
2367
|
453 dump_add_root_block_ptr() should use plain memory_descriptions and have
|
1204
|
454 the size be an argument to the call.)
|
|
455
|
|
456 NOTE: Anywhere that a sized_memory_description occurs inside of a plain
|
|
457 memory_description, a "description map" can be substituted. Rather than
|
|
458 being an actual description, this describes how to find the description
|
|
459 by looking inside of the object being described. This is a convenient
|
|
460 way to describe Lisp objects with subtypes and corresponding
|
|
461 type-specific data.
|
428
|
462
|
|
463 Some example descriptions :
|
440
|
464
|
814
|
465 struct Lisp_String
|
|
466 {
|
|
467 struct lrecord_header lheader;
|
|
468 Bytecount size;
|
867
|
469 Ibyte *data;
|
814
|
470 Lisp_Object plist;
|
|
471 };
|
|
472
|
1204
|
473 static const struct memory_description cons_description[] = {
|
440
|
474 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
|
|
475 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
|
428
|
476 { XD_END }
|
|
477 };
|
|
478
|
440
|
479 Which means "two lisp objects starting at the 'car' and 'cdr' elements"
|
428
|
480
|
1204
|
481 static const struct memory_description string_description[] = {
|
814
|
482 { XD_BYTECOUNT, offsetof (Lisp_String, size) },
|
1204
|
483 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT (0, 1) },
|
814
|
484 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
|
|
485 { XD_END }
|
|
486 };
|
|
487
|
|
488 "A pointer to string data at 'data', the size of the pointed array being
|
|
489 the value of the size variable plus 1, and one lisp object at 'plist'"
|
|
490
|
|
491 If your object has a pointer to an array of Lisp_Objects in it, something
|
|
492 like this:
|
|
493
|
|
494 struct Lisp_Foo
|
|
495 {
|
|
496 ...;
|
|
497 int count;
|
|
498 Lisp_Object *objects;
|
|
499 ...;
|
|
500 }
|
|
501
|
2367
|
502 You'd use XD_BLOCK_PTR, something like:
|
814
|
503
|
1204
|
504 static const struct memory_description foo_description[] = {
|
|
505 ...
|
|
506 { XD_INT, offsetof (Lisp_Foo, count) },
|
2367
|
507 { XD_BLOCK_PTR, offsetof (Lisp_Foo, objects),
|
2551
|
508 XD_INDIRECT (0, 0), { &lisp_object_description } },
|
1204
|
509 ...
|
|
510 };
|
|
511
|
|
512 lisp_object_description is declared in alloc.c, like this:
|
|
513
|
|
514 static const struct memory_description lisp_object_description_1[] = {
|
814
|
515 { XD_LISP_OBJECT, 0 },
|
|
516 { XD_END }
|
|
517 };
|
|
518
|
1204
|
519 const struct sized_memory_description lisp_object_description = {
|
814
|
520 sizeof (Lisp_Object),
|
1204
|
521 lisp_object_description_1
|
814
|
522 };
|
|
523
|
2367
|
524 Another example of XD_BLOCK_PTR:
|
428
|
525
|
1204
|
526 typedef struct htentry
|
814
|
527 {
|
|
528 Lisp_Object key;
|
|
529 Lisp_Object value;
|
1204
|
530 } htentry;
|
814
|
531
|
|
532 struct Lisp_Hash_Table
|
|
533 {
|
|
534 struct lcrecord_header header;
|
|
535 Elemcount size;
|
|
536 Elemcount count;
|
|
537 Elemcount rehash_count;
|
|
538 double rehash_size;
|
|
539 double rehash_threshold;
|
|
540 Elemcount golden_ratio;
|
|
541 hash_table_hash_function_t hash_function;
|
|
542 hash_table_test_function_t test_function;
|
1204
|
543 htentry *hentries;
|
814
|
544 enum hash_table_weakness weakness;
|
|
545 Lisp_Object next_weak; // Used to chain together all of the weak
|
|
546 // hash tables. Don't mark through this.
|
|
547 };
|
|
548
|
1204
|
549 static const struct memory_description htentry_description_1[] = {
|
|
550 { XD_LISP_OBJECT, offsetof (htentry, key) },
|
|
551 { XD_LISP_OBJECT, offsetof (htentry, value) },
|
814
|
552 { XD_END }
|
|
553 };
|
|
554
|
1204
|
555 static const struct sized_memory_description htentry_description = {
|
|
556 sizeof (htentry),
|
|
557 htentry_description_1
|
814
|
558 };
|
|
559
|
1204
|
560 const struct memory_description hash_table_description[] = {
|
814
|
561 { XD_ELEMCOUNT, offsetof (Lisp_Hash_Table, size) },
|
2367
|
562 { XD_BLOCK_PTR, offsetof (Lisp_Hash_Table, hentries), XD_INDIRECT (0, 1),
|
2551
|
563 { &htentry_description } },
|
814
|
564 { XD_LO_LINK, offsetof (Lisp_Hash_Table, next_weak) },
|
|
565 { XD_END }
|
|
566 };
|
|
567
|
|
568 Note that we don't need to declare all the elements in the structure, just
|
|
569 the ones that need to be relocated (Lisp_Objects and structures) or that
|
|
570 need to be referenced as counts for relocated objects.
|
|
571
|
1204
|
572 A description map looks like this:
|
|
573
|
|
574 static const struct sized_memory_description specifier_extra_description_map [] = {
|
|
575 { offsetof (Lisp_Specifier, methods) },
|
|
576 { offsetof (struct specifier_methods, extra_description) },
|
|
577 { -1 }
|
|
578 };
|
|
579
|
|
580 const struct memory_description specifier_description[] = {
|
|
581 ...
|
2367
|
582 { XD_BLOCK_ARRAY, offset (Lisp_Specifier, data), 1,
|
2551
|
583 { specifier_extra_description_map } },
|
1204
|
584 ...
|
|
585 { XD_END }
|
|
586 };
|
|
587
|
|
588 This would be appropriate for an object that looks like this:
|
|
589
|
|
590 struct specifier_methods
|
|
591 {
|
|
592 ...
|
|
593 const struct sized_memory_description *extra_description;
|
|
594 ...
|
|
595 };
|
|
596
|
|
597 struct Lisp_Specifier
|
|
598 {
|
|
599 struct lcrecord_header header;
|
|
600 struct specifier_methods *methods;
|
|
601
|
|
602 ...
|
|
603 // type-specific extra data attached to a specifier
|
|
604 max_align_t data[1];
|
|
605 };
|
|
606
|
|
607 The description map means "retrieve a pointer into the object at offset
|
|
608 `offsetof (Lisp_Specifier, methods)' , then in turn retrieve a pointer
|
|
609 into that object at offset `offsetof (struct specifier_methods,
|
|
610 extra_description)', and that is the sized_memory_description to use."
|
|
611 There can be any number of indirections, which can be either into
|
|
612 straight pointers or Lisp_Objects. The way that description maps are
|
|
613 distinguished from normal sized_memory_descriptions is that in the
|
|
614 former, the memory_description pointer is NULL.
|
|
615
|
|
616 --ben
|
|
617
|
814
|
618
|
|
619 The existing types :
|
|
620
|
|
621
|
428
|
622 XD_LISP_OBJECT
|
1204
|
623
|
|
624 A Lisp object. This is also the type to use for pointers to other lrecords
|
|
625 (e.g. struct frame *).
|
428
|
626
|
440
|
627 XD_LISP_OBJECT_ARRAY
|
1204
|
628
|
771
|
629 An array of Lisp objects or (equivalently) pointers to lrecords.
|
|
630 The parameter (i.e. third element) is the count. This would be declared
|
|
631 as Lisp_Object foo[666]. For something declared as Lisp_Object *foo,
|
2367
|
632 use XD_BLOCK_PTR, whose description parameter is a sized_memory_description
|
771
|
633 consisting of only XD_LISP_OBJECT and XD_END.
|
440
|
634
|
428
|
635 XD_LO_LINK
|
1204
|
636
|
771
|
637 Weak link in a linked list of objects of the same type. This is a
|
|
638 link that does NOT generate a GC reference. Thus the pdumper will
|
|
639 not automatically add the referenced object to the table of all
|
|
640 objects to be dumped, and when storing and loading the dumped data
|
|
641 will automatically prune unreferenced objects in the chain and link
|
|
642 each referenced object to the next referenced object, even if it's
|
|
643 many links away. We also need to special handling of a similar
|
|
644 nature for the root of the chain, which will be a staticpro()ed
|
|
645 object.
|
432
|
646
|
428
|
647 XD_OPAQUE_PTR
|
1204
|
648
|
428
|
649 Pointer to undumpable data. Must be NULL when dumping.
|
|
650
|
2551
|
651 XD_OPAQUE_PTR_CONVERTIBLE
|
|
652
|
|
653 Pointer to data which is not directly dumpable but can be converted
|
|
654 to a dumpable, opaque external representation. The parameter is
|
|
655 a pointer to an opaque_convert_functions struct.
|
|
656
|
|
657 XD_OPAQUE_DATA_CONVERTIBLE
|
|
658
|
|
659 Data which is not directly dumpable but can be converted to a
|
|
660 dumpable, opaque external representation. The parameter is a
|
|
661 pointer to an opaque_convert_functions struct.
|
|
662
|
2367
|
663 XD_BLOCK_PTR
|
1204
|
664
|
771
|
665 Pointer to block of described memory. (This is misnamed: It is NOT
|
|
666 necessarily a pointer to a struct foo.) Parameters are number of
|
1204
|
667 contiguous blocks and sized_memory_description.
|
771
|
668
|
2367
|
669 XD_BLOCK_ARRAY
|
1204
|
670
|
771
|
671 Array of blocks of described memory. Parameters are number of
|
2367
|
672 structures and sized_memory_description. This differs from XD_BLOCK_PTR
|
771
|
673 in that the parameter is declared as struct foo[666] instead of
|
|
674 struct *foo. In other words, the block of memory holding the
|
|
675 structures is within the containing structure, rather than being
|
|
676 elsewhere, with a pointer in the containing structure.
|
428
|
677
|
1204
|
678 NOTE NOTE NOTE: Be sure that you understand the difference between
|
2367
|
679 XD_BLOCK_PTR and XD_BLOCK_ARRAY:
|
1204
|
680 - struct foo bar[666], i.e. 666 inline struct foos
|
2367
|
681 --> XD_BLOCK_ARRAY, argument 666, pointing to a description of
|
1204
|
682 struct foo
|
|
683 - struct foo *bar, i.e. pointer to a block of 666 struct foos
|
2367
|
684 --> XD_BLOCK_PTR, argument 666, pointing to a description of
|
1204
|
685 struct foo
|
|
686 - struct foo *bar[666], i.e. 666 pointers to separate blocks of struct foos
|
2367
|
687 --> XD_BLOCK_ARRAY, argument 666, pointing to a description of
|
1204
|
688 a single pointer to struct foo; the description is a single
|
2367
|
689 XD_BLOCK_PTR, argument 1, which in turn points to a description
|
1204
|
690 of struct foo.
|
|
691
|
2367
|
692 NOTE also that an XD_BLOCK_PTR of 666 foos is equivalent to an
|
|
693 XD_BLOCK_PTR of 1 bar, where the description of `bar' is an
|
|
694 XD_BLOCK_ARRAY of 666 foos.
|
|
695
|
428
|
696 XD_OPAQUE_DATA_PTR
|
1204
|
697
|
428
|
698 Pointer to dumpable opaque data. Parameter is the size of the data.
|
|
699 Pointed data must be relocatable without changes.
|
|
700
|
771
|
701 XD_UNION
|
1204
|
702
|
|
703 Union of two or more different types of data. Parameters are a constant
|
|
704 which determines which type the data is (this is usually an XD_INDIRECT,
|
|
705 referring to one of the fields in the structure), and a "sizing lobby" (a
|
|
706 sized_memory_description, which points to a memory_description and
|
|
707 indicates its size). The size field in the sizing lobby describes the
|
|
708 size of the union field in the object, and the memory_description in it
|
|
709 is referred to as a "union map" and has a special interpretation: The
|
|
710 offset field is replaced by a constant, which is compared to the first
|
|
711 parameter of the XD_UNION descriptor to determine if this description
|
|
712 applies to the union data, and XD_INDIRECT references refer to the
|
|
713 containing object and description. Note that the description applies
|
2367
|
714 "inline" to the union data, like XD_BLOCK_ARRAY and not XD_BLOCK_PTR.
|
1204
|
715 If the union data is a pointer to different types of structures, each
|
2367
|
716 element in the memory_description should be an XD_BLOCK_PTR. See
|
1204
|
717 unicode.c, redisplay.c and objects.c for examples of XD_UNION.
|
|
718
|
|
719 XD_UNION_DYNAMIC_SIZE
|
|
720
|
|
721 Same as XD_UNION except that this is used for objects where the size of
|
|
722 the object containing the union varies depending on the particular value
|
|
723 of the union constant. That is, an object with plain XD_UNION typically
|
|
724 has the union declared as `union foo' or as `void *', where an object
|
|
725 with XD_UNION_DYNAMIC_SIZE typically has the union as the last element,
|
2367
|
726 and declared as something like Rawbyte foo[1]. With plain XD_UNION, the
|
1204
|
727 object is (usually) of fixed size and always contains enough space for
|
|
728 the data associated with all possible union constants, and thus the union
|
|
729 constant can potentially change during the lifetime of the object. With
|
|
730 XD_UNION_DYNAMIC_SIZE, however, the union constant is fixed at the time
|
|
731 of creation of the object, and the size of the object is computed
|
|
732 dynamically at creation time based on the size of the data associated
|
|
733 with the union constant. Currently, the only difference between XD_UNION
|
|
734 and XD_UNION_DYNAMIC_SIZE is how the size of the union data is
|
|
735 calculated, when (a) the structure containing the union has no size
|
|
736 given; (b) the union occurs as the last element in the structure; and (c)
|
|
737 the union has no size given (in the first-level sized_memory_description
|
|
738 pointed to). In this circumstance, the size of XD_UNION comes from the
|
|
739 max size of the data associated with all possible union constants,
|
|
740 whereas the size of XD_UNION_DYNAMIC_SIZE comes from the size of the data
|
|
741 associated with the currently specified (and unchangeable) union
|
|
742 constant.
|
771
|
743
|
2367
|
744 XD_ASCII_STRING
|
1204
|
745
|
2367
|
746 Pointer to a C string, purely ASCII.
|
428
|
747
|
|
748 XD_DOC_STRING
|
1204
|
749
|
2367
|
750 Pointer to a doc string (C string in pure ASCII if positive,
|
|
751 opaque value if negative)
|
428
|
752
|
|
753 XD_INT_RESET
|
1204
|
754
|
428
|
755 An integer which will be reset to a given value in the dump file.
|
|
756
|
1204
|
757 XD_ELEMCOUNT
|
771
|
758
|
665
|
759 Elemcount value. Used for counts.
|
647
|
760
|
665
|
761 XD_BYTECOUNT
|
1204
|
762
|
665
|
763 Bytecount value. Used for counts.
|
647
|
764
|
665
|
765 XD_HASHCODE
|
1204
|
766
|
665
|
767 Hashcode value. Used for the results of hashing functions.
|
428
|
768
|
|
769 XD_INT
|
1204
|
770
|
428
|
771 int value. Used for counts.
|
|
772
|
|
773 XD_LONG
|
1204
|
774
|
428
|
775 long value. Used for counts.
|
|
776
|
771
|
777 XD_BYTECOUNT
|
1204
|
778
|
771
|
779 bytecount value. Used for counts.
|
|
780
|
428
|
781 XD_END
|
1204
|
782
|
428
|
783 Special type indicating the end of the array.
|
|
784
|
|
785
|
|
786 Special macros:
|
1204
|
787
|
|
788 XD_INDIRECT (line, delta)
|
|
789 Usable where a count, size, offset or union constant is requested. Gives
|
|
790 the value of the element which is at line number 'line' in the
|
|
791 description (count starts at zero) and adds delta to it, which must
|
|
792 (currently) be positive.
|
428
|
793 */
|
|
794
|
1204
|
795 enum memory_description_type
|
647
|
796 {
|
440
|
797 XD_LISP_OBJECT_ARRAY,
|
428
|
798 XD_LISP_OBJECT,
|
|
799 XD_LO_LINK,
|
|
800 XD_OPAQUE_PTR,
|
2551
|
801 XD_OPAQUE_PTR_CONVERTIBLE,
|
|
802 XD_OPAQUE_DATA_CONVERTIBLE,
|
|
803 XD_OPAQUE_DATA_PTR,
|
2367
|
804 XD_BLOCK_PTR,
|
|
805 XD_BLOCK_ARRAY,
|
771
|
806 XD_UNION,
|
1204
|
807 XD_UNION_DYNAMIC_SIZE,
|
2367
|
808 XD_ASCII_STRING,
|
428
|
809 XD_DOC_STRING,
|
|
810 XD_INT_RESET,
|
665
|
811 XD_BYTECOUNT,
|
|
812 XD_ELEMCOUNT,
|
|
813 XD_HASHCODE,
|
428
|
814 XD_INT,
|
|
815 XD_LONG,
|
1204
|
816 XD_END
|
428
|
817 };
|
|
818
|
1204
|
819 enum data_description_entry_flags
|
647
|
820 {
|
1204
|
821 /* If set, KKCC does not process this entry.
|
|
822
|
|
823 (1) One obvious use is with things that pdump saves but which do not get
|
|
824 marked normally -- for example the next and prev fields in a marker. The
|
|
825 marker chain is weak, with its entries removed when they are finalized.
|
|
826
|
|
827 (2) This can be set on structures not containing any Lisp objects, or (more
|
|
828 usefully) on structures that contain Lisp objects but where the objects
|
|
829 always occur in another structure as well. For example, the extent lists
|
|
830 kept by a buffer keep the extents in two lists, one sorted by the start
|
|
831 of the extent and the other by the end. There's no point in marking
|
|
832 both, since each contains the same objects as the other; but when dumping
|
|
833 (if we were to dump such a structure), when computing memory size, etc.,
|
|
834 it's crucial to tag both sides.
|
|
835 */
|
|
836 XD_FLAG_NO_KKCC = 1,
|
|
837 /* If set, pdump does not process this entry. */
|
|
838 XD_FLAG_NO_PDUMP = 2,
|
|
839 /* Indicates that this is a "default" entry in a union map. */
|
|
840 XD_FLAG_UNION_DEFAULT_ENTRY = 4,
|
|
841 /* Indicates that this is a free Lisp object we're marking.
|
|
842 Only relevant for ERROR_CHECK_GC. This occurs when we're marking
|
|
843 lcrecord-lists, where the objects have had their type changed to
|
|
844 lrecord_type_free and also have had their free bit set, but we mark
|
|
845 them as normal. */
|
1429
|
846 XD_FLAG_FREE_LISP_OBJECT = 8
|
1204
|
847 #if 0
|
1429
|
848 ,
|
1204
|
849 /* Suggestions for other possible flags: */
|
|
850
|
|
851 /* Eliminate XD_UNION_DYNAMIC_SIZE and replace it with a flag, like this. */
|
|
852 XD_FLAG_UNION_DYNAMIC_SIZE = 16,
|
|
853 /* Require that everyone who uses a description map has to flag it, so
|
|
854 that it's easy to tell, when looking through the code, where the
|
|
855 description maps are and who's using them. This might also become
|
|
856 necessary if for some reason the format of the description map is
|
|
857 expanded and we need to stick a pointer in the second slot (although
|
|
858 we could still ensure that the second slot in the first entry was NULL
|
|
859 or <0). */
|
1429
|
860 XD_FLAG_DESCRIPTION_MAP = 32
|
1204
|
861 #endif
|
428
|
862 };
|
|
863
|
2551
|
864 union memory_contents_description
|
|
865 {
|
|
866 /* The first element is used by static initializers only. We always read
|
|
867 from one of the other two pointers. */
|
|
868 const void *write_only;
|
|
869 const struct sized_memory_description *descr;
|
|
870 const struct opaque_convert_functions *funcs;
|
|
871 };
|
|
872
|
1204
|
873 struct memory_description
|
|
874 {
|
|
875 enum memory_description_type type;
|
|
876 Bytecount offset;
|
|
877 EMACS_INT data1;
|
2551
|
878 union memory_contents_description data2;
|
1204
|
879 /* Indicates which subsystems process this entry, plus (potentially) other
|
|
880 flags that apply to this entry. */
|
|
881 int flags;
|
|
882 };
|
428
|
883
|
1204
|
884 struct sized_memory_description
|
|
885 {
|
|
886 Bytecount size;
|
|
887 const struct memory_description *description;
|
|
888 };
|
|
889
|
2551
|
890
|
|
891 struct opaque_convert_functions
|
|
892 {
|
|
893 /* Used by XD_OPAQUE_PTR_CONVERTIBLE and
|
|
894 XD_OPAQUE_DATA_CONVERTIBLE */
|
|
895
|
|
896 /* Converter to external representation, for those objects from
|
|
897 external libraries that can't be directly dumped as opaque data
|
|
898 because they contain pointers. This is called at dump time to
|
|
899 convert to an opaque, pointer-less representation.
|
|
900
|
|
901 This function must put a pointer to the opaque result in *data
|
|
902 and its size in *size. */
|
|
903 void (*convert)(const void *object, void **data, Bytecount *size);
|
|
904
|
|
905 /* Post-conversion cleanup. Optional (null if not provided).
|
|
906
|
|
907 When provided it will be called post-dumping to free any storage
|
|
908 allocated for the conversion results. */
|
|
909 void (*convert_free)(const void *object, void *data, Bytecount size);
|
|
910
|
|
911 /* De-conversion.
|
|
912
|
|
913 At reload time, rebuilds the object from the converted form.
|
|
914 "object" is 0 for the PTR case, return is ignored in the DATA
|
|
915 case. */
|
|
916 void *(*deconvert)(void *object, void *data, Bytecount size);
|
|
917
|
|
918 };
|
|
919
|
1204
|
920 extern const struct sized_memory_description lisp_object_description;
|
|
921
|
|
922 #define XD_INDIRECT(val, delta) (-1 - (Bytecount) ((val) | ((delta) << 8)))
|
428
|
923
|
1204
|
924 #define XD_IS_INDIRECT(code) ((code) < 0)
|
|
925 #define XD_INDIRECT_VAL(code) ((-1 - (code)) & 255)
|
|
926 #define XD_INDIRECT_DELTA(code) ((-1 - (code)) >> 8)
|
|
927
|
|
928 #define XD_DYNARR_DESC(base_type, sub_desc) \
|
2551
|
929 { XD_BLOCK_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), {sub_desc} },\
|
1204
|
930 { XD_INT, offsetof (base_type, cur) }, \
|
|
931 { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) } \
|
|
932
|
428
|
933 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
|
|
934 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
|
|
935 */
|
|
936
|
800
|
937 #if defined (ERROR_CHECK_TYPES)
|
|
938 # define DECLARE_ERROR_CHECK_TYPES(c_name, structtype)
|
428
|
939 #else
|
800
|
940 # define DECLARE_ERROR_CHECK_TYPES(c_name, structtype)
|
428
|
941 #endif
|
|
942
|
934
|
943
|
|
944 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
945 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
946
|
|
947 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
948 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
|
|
949
|
|
950 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
951 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
952
|
|
953 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
954 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
|
955
|
|
956 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
957 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
958
|
|
959 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
960 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
|
|
961
|
|
962 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
|
963 MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
|
|
964
|
|
965 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
1204
|
966 DECLARE_ERROR_CHECK_TYPES(c_name, structtype) \
|
934
|
967 const struct lrecord_implementation lrecord_##c_name = \
|
|
968 { name, dumpable, marker, printer, nuker, equal, hash, desc, \
|
|
969 getprop, putprop, remprop, plist, size, sizer, \
|
|
970 lrecord_type_##c_name, basic_p }
|
|
971
|
|
972 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
973 DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
974
|
|
975 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
976 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
|
977
|
|
978 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
979 DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
980
|
|
981 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
|
982 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
|
|
983
|
|
984 #define MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,dumpable,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
1204
|
985 DECLARE_ERROR_CHECK_TYPES(c_name, structtype) \
|
934
|
986 int lrecord_type_##c_name; \
|
|
987 struct lrecord_implementation lrecord_##c_name = \
|
|
988 { name, dumpable, marker, printer, nuker, equal, hash, desc, \
|
|
989 getprop, putprop, remprop, plist, size, sizer, \
|
|
990 lrecord_type_last_built_in_type, basic_p }
|
|
991
|
1676
|
992 #ifdef USE_KKCC
|
|
993 extern MODULE_API const struct memory_description *lrecord_memory_descriptions[];
|
|
994
|
|
995 #define INIT_LRECORD_IMPLEMENTATION(type) do { \
|
|
996 lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
|
|
997 lrecord_memory_descriptions[lrecord_type_##type] = \
|
|
998 lrecord_implementations_table[lrecord_type_##type]->description; \
|
|
999 } while (0)
|
|
1000 #else /* not USE_KKCC */
|
1632
|
1001 extern MODULE_API Lisp_Object (*lrecord_markers[]) (Lisp_Object);
|
442
|
1002
|
|
1003 #define INIT_LRECORD_IMPLEMENTATION(type) do { \
|
|
1004 lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
|
|
1005 lrecord_markers[lrecord_type_##type] = \
|
|
1006 lrecord_implementations_table[lrecord_type_##type]->marker; \
|
|
1007 } while (0)
|
1676
|
1008 #endif /* not USE_KKCC */
|
428
|
1009
|
444
|
1010 #define INIT_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
|
|
1011 lrecord_type_##type = lrecord_type_count++; \
|
|
1012 lrecord_##type.lrecord_type_index = lrecord_type_##type; \
|
|
1013 INIT_LRECORD_IMPLEMENTATION(type); \
|
|
1014 } while (0)
|
|
1015
|
996
|
1016 #ifdef HAVE_SHLIB
|
|
1017 /* Allow undefining types in order to support module unloading. */
|
|
1018
|
1676
|
1019 #ifdef USE_KKCC
|
|
1020 #define UNDEF_LRECORD_IMPLEMENTATION(type) do { \
|
|
1021 lrecord_implementations_table[lrecord_type_##type] = NULL; \
|
|
1022 lrecord_memory_descriptions[lrecord_type_##type] = NULL; \
|
|
1023 } while (0)
|
|
1024 #else /* not USE_KKCC */
|
996
|
1025 #define UNDEF_LRECORD_IMPLEMENTATION(type) do { \
|
|
1026 lrecord_implementations_table[lrecord_type_##type] = NULL; \
|
|
1027 lrecord_markers[lrecord_type_##type] = NULL; \
|
|
1028 } while (0)
|
1676
|
1029 #endif /* not USE_KKCC */
|
996
|
1030
|
|
1031 #define UNDEF_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
|
|
1032 if (lrecord_##type.lrecord_type_index == lrecord_type_count - 1) { \
|
|
1033 /* This is the most recently defined type. Clean up nicely. */ \
|
|
1034 lrecord_type_##type = lrecord_type_count--; \
|
|
1035 } /* Else we can't help leaving a hole with this implementation. */ \
|
|
1036 UNDEF_LRECORD_IMPLEMENTATION(type); \
|
|
1037 } while (0)
|
|
1038
|
|
1039 #endif /* HAVE_SHLIB */
|
|
1040
|
428
|
1041 #define LRECORDP(a) (XTYPE (a) == Lisp_Type_Record)
|
|
1042 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
|
|
1043
|
|
1044 #define RECORD_TYPEP(x, ty) \
|
647
|
1045 (LRECORDP (x) && (XRECORD_LHEADER (x)->type == (unsigned int) (ty)))
|
442
|
1046
|
|
1047 /* Steps to create a new object:
|
|
1048
|
|
1049 1. Declare the struct for your object in a header file somewhere.
|
|
1050 Remember that it must begin with
|
|
1051
|
|
1052 struct lcrecord_header header;
|
|
1053
|
793
|
1054 2. Put the "standard junk" (DECLARE_RECORD()/XFOO/etc.) below the
|
617
|
1055 struct definition -- see below.
|
442
|
1056
|
|
1057 3. Add this header file to inline.c.
|
|
1058
|
|
1059 4. Create the methods for your object. Note that technically you don't
|
|
1060 need any, but you will almost always want at least a mark method.
|
|
1061
|
1204
|
1062 4. Create the data layout description for your object. See
|
|
1063 toolbar_button_description below; the comment above in `struct lrecord',
|
|
1064 describing the purpose of the descriptions; and comments elsewhere in
|
|
1065 this file describing the exact syntax of the description structures.
|
|
1066
|
|
1067 6. Define your object with DEFINE_LRECORD_IMPLEMENTATION() or some
|
442
|
1068 variant.
|
|
1069
|
1204
|
1070 7. Include the header file in the .c file where you defined the object.
|
442
|
1071
|
1204
|
1072 8. Put a call to INIT_LRECORD_IMPLEMENTATION() for the object in the
|
442
|
1073 .c file's syms_of_foo() function.
|
|
1074
|
1204
|
1075 9. Add a type enum for the object to enum lrecord_type, earlier in this
|
442
|
1076 file.
|
|
1077
|
1204
|
1078 --ben
|
|
1079
|
442
|
1080 An example:
|
428
|
1081
|
442
|
1082 ------------------------------ in toolbar.h -----------------------------
|
|
1083
|
|
1084 struct toolbar_button
|
|
1085 {
|
|
1086 struct lcrecord_header header;
|
|
1087
|
|
1088 Lisp_Object next;
|
|
1089 Lisp_Object frame;
|
|
1090
|
|
1091 Lisp_Object up_glyph;
|
|
1092 Lisp_Object down_glyph;
|
|
1093 Lisp_Object disabled_glyph;
|
|
1094
|
|
1095 Lisp_Object cap_up_glyph;
|
|
1096 Lisp_Object cap_down_glyph;
|
|
1097 Lisp_Object cap_disabled_glyph;
|
|
1098
|
|
1099 Lisp_Object callback;
|
|
1100 Lisp_Object enabled_p;
|
|
1101 Lisp_Object help_string;
|
|
1102
|
|
1103 char enabled;
|
|
1104 char down;
|
|
1105 char pushright;
|
|
1106 char blank;
|
|
1107
|
|
1108 int x, y;
|
|
1109 int width, height;
|
|
1110 int dirty;
|
|
1111 int vertical;
|
|
1112 int border_width;
|
|
1113 };
|
428
|
1114
|
617
|
1115 [[ the standard junk: ]]
|
|
1116
|
442
|
1117 DECLARE_LRECORD (toolbar_button, struct toolbar_button);
|
|
1118 #define XTOOLBAR_BUTTON(x) XRECORD (x, toolbar_button, struct toolbar_button)
|
617
|
1119 #define wrap_toolbar_button(p) wrap_record (p, toolbar_button)
|
442
|
1120 #define TOOLBAR_BUTTONP(x) RECORDP (x, toolbar_button)
|
|
1121 #define CHECK_TOOLBAR_BUTTON(x) CHECK_RECORD (x, toolbar_button)
|
|
1122 #define CONCHECK_TOOLBAR_BUTTON(x) CONCHECK_RECORD (x, toolbar_button)
|
|
1123
|
|
1124 ------------------------------ in toolbar.c -----------------------------
|
|
1125
|
|
1126 #include "toolbar.h"
|
|
1127
|
|
1128 ...
|
|
1129
|
1204
|
1130 static const struct memory_description toolbar_button_description [] = {
|
|
1131 { XD_LISP_OBJECT, offsetof (struct toolbar_button, next) },
|
|
1132 { XD_LISP_OBJECT, offsetof (struct toolbar_button, frame) },
|
|
1133 { XD_LISP_OBJECT, offsetof (struct toolbar_button, up_glyph) },
|
|
1134 { XD_LISP_OBJECT, offsetof (struct toolbar_button, down_glyph) },
|
|
1135 { XD_LISP_OBJECT, offsetof (struct toolbar_button, disabled_glyph) },
|
|
1136 { XD_LISP_OBJECT, offsetof (struct toolbar_button, cap_up_glyph) },
|
|
1137 { XD_LISP_OBJECT, offsetof (struct toolbar_button, cap_down_glyph) },
|
|
1138 { XD_LISP_OBJECT, offsetof (struct toolbar_button, cap_disabled_glyph) },
|
|
1139 { XD_LISP_OBJECT, offsetof (struct toolbar_button, callback) },
|
|
1140 { XD_LISP_OBJECT, offsetof (struct toolbar_button, enabled_p) },
|
|
1141 { XD_LISP_OBJECT, offsetof (struct toolbar_button, help_string) },
|
|
1142 { XD_END }
|
|
1143 };
|
|
1144
|
442
|
1145 static Lisp_Object
|
|
1146 mark_toolbar_button (Lisp_Object obj)
|
1204
|
1147 \{
|
442
|
1148 struct toolbar_button *data = XTOOLBAR_BUTTON (obj);
|
|
1149 mark_object (data->next);
|
|
1150 mark_object (data->frame);
|
|
1151 mark_object (data->up_glyph);
|
|
1152 mark_object (data->down_glyph);
|
|
1153 mark_object (data->disabled_glyph);
|
|
1154 mark_object (data->cap_up_glyph);
|
|
1155 mark_object (data->cap_down_glyph);
|
|
1156 mark_object (data->cap_disabled_glyph);
|
|
1157 mark_object (data->callback);
|
|
1158 mark_object (data->enabled_p);
|
|
1159 return data->help_string;
|
|
1160 }
|
|
1161
|
617
|
1162 [[ If your object should never escape to Lisp, declare its print method
|
|
1163 as internal_object_printer instead of 0. ]]
|
|
1164
|
442
|
1165 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-button", toolbar_button,
|
1204
|
1166 0, mark_toolbar_button, 0, 0, 0, 0,
|
|
1167 toolbar_button_description,
|
|
1168 struct toolbar_button);
|
442
|
1169
|
|
1170 ...
|
|
1171
|
|
1172 void
|
|
1173 syms_of_toolbar (void)
|
|
1174 {
|
|
1175 INIT_LRECORD_IMPLEMENTATION (toolbar_button);
|
|
1176
|
|
1177 ...;
|
|
1178 }
|
|
1179
|
|
1180 ------------------------------ in inline.c -----------------------------
|
|
1181
|
|
1182 #ifdef HAVE_TOOLBARS
|
|
1183 #include "toolbar.h"
|
|
1184 #endif
|
|
1185
|
|
1186 ------------------------------ in lrecord.h -----------------------------
|
|
1187
|
|
1188 enum lrecord_type
|
|
1189 {
|
|
1190 ...
|
|
1191 lrecord_type_toolbar_button,
|
|
1192 ...
|
|
1193 };
|
|
1194
|
1204
|
1195
|
|
1196 --ben
|
|
1197
|
442
|
1198 */
|
|
1199
|
|
1200 /*
|
|
1201
|
|
1202 Note: Object types defined in external dynamically-loaded modules (not
|
|
1203 part of the XEmacs main source code) should use DECLARE_EXTERNAL_LRECORD
|
|
1204 and DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION rather than DECLARE_LRECORD
|
|
1205 and DEFINE_LRECORD_IMPLEMENTATION.
|
|
1206
|
|
1207 */
|
|
1208
|
428
|
1209
|
800
|
1210 #ifdef ERROR_CHECK_TYPES
|
428
|
1211
|
788
|
1212 # define DECLARE_LRECORD(c_name, structtype) \
|
|
1213 extern const struct lrecord_implementation lrecord_##c_name; \
|
826
|
1214 DECLARE_INLINE_HEADER ( \
|
|
1215 structtype * \
|
2367
|
1216 error_check_##c_name (Lisp_Object obj, const Ascbyte *file, int line) \
|
826
|
1217 ) \
|
788
|
1218 { \
|
|
1219 assert_at_line (RECORD_TYPEP (obj, lrecord_type_##c_name), file, line); \
|
|
1220 return (structtype *) XPNTR (obj); \
|
|
1221 } \
|
428
|
1222 extern Lisp_Object Q##c_name##p
|
|
1223
|
1632
|
1224 # define DECLARE_MODULE_API_LRECORD(c_name, structtype) \
|
|
1225 extern MODULE_API const struct lrecord_implementation lrecord_##c_name; \
|
|
1226 DECLARE_INLINE_HEADER ( \
|
|
1227 structtype * \
|
2367
|
1228 error_check_##c_name (Lisp_Object obj, const Ascbyte *file, int line) \
|
1632
|
1229 ) \
|
|
1230 { \
|
|
1231 assert_at_line (RECORD_TYPEP (obj, lrecord_type_##c_name), file, line); \
|
|
1232 return (structtype *) XPNTR (obj); \
|
|
1233 } \
|
|
1234 extern MODULE_API Lisp_Object Q##c_name##p
|
|
1235
|
788
|
1236 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
|
|
1237 extern int lrecord_type_##c_name; \
|
|
1238 extern struct lrecord_implementation lrecord_##c_name; \
|
826
|
1239 DECLARE_INLINE_HEADER ( \
|
|
1240 structtype * \
|
2367
|
1241 error_check_##c_name (Lisp_Object obj, const Ascbyte *file, int line) \
|
826
|
1242 ) \
|
788
|
1243 { \
|
|
1244 assert_at_line (RECORD_TYPEP (obj, lrecord_type_##c_name), file, line); \
|
|
1245 return (structtype *) XPNTR (obj); \
|
|
1246 } \
|
444
|
1247 extern Lisp_Object Q##c_name##p
|
442
|
1248
|
788
|
1249 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
826
|
1250 DECLARE_INLINE_HEADER ( \
|
|
1251 structtype * \
|
2367
|
1252 error_check_##c_name (Lisp_Object obj, const Ascbyte *file, int line) \
|
826
|
1253 ) \
|
788
|
1254 { \
|
|
1255 assert_at_line (XTYPE (obj) == type_enum, file, line); \
|
|
1256 return (structtype *) XPNTR (obj); \
|
|
1257 } \
|
428
|
1258 extern Lisp_Object Q##c_name##p
|
|
1259
|
788
|
1260 # define XRECORD(x, c_name, structtype) \
|
|
1261 error_check_##c_name (x, __FILE__, __LINE__)
|
|
1262 # define XNONRECORD(x, c_name, type_enum, structtype) \
|
|
1263 error_check_##c_name (x, __FILE__, __LINE__)
|
428
|
1264
|
826
|
1265 DECLARE_INLINE_HEADER (
|
|
1266 Lisp_Object
|
2367
|
1267 wrap_record_1 (const void *ptr, enum lrecord_type ty, const Ascbyte *file,
|
800
|
1268 int line)
|
826
|
1269 )
|
617
|
1270 {
|
793
|
1271 Lisp_Object obj = wrap_pointer_1 (ptr);
|
|
1272
|
788
|
1273 assert_at_line (RECORD_TYPEP (obj, ty), file, line);
|
617
|
1274 return obj;
|
|
1275 }
|
|
1276
|
788
|
1277 #define wrap_record(ptr, ty) \
|
|
1278 wrap_record_1 (ptr, lrecord_type_##ty, __FILE__, __LINE__)
|
617
|
1279
|
800
|
1280 #else /* not ERROR_CHECK_TYPES */
|
428
|
1281
|
|
1282 # define DECLARE_LRECORD(c_name, structtype) \
|
|
1283 extern Lisp_Object Q##c_name##p; \
|
442
|
1284 extern const struct lrecord_implementation lrecord_##c_name
|
1638
|
1285 # define DECLARE_MODULE_API_LRECORD(c_name, structtype) \
|
|
1286 extern MODULE_API Lisp_Object Q##c_name##p; \
|
|
1287 extern MODULE_API const struct lrecord_implementation lrecord_##c_name
|
442
|
1288 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
|
|
1289 extern Lisp_Object Q##c_name##p; \
|
647
|
1290 extern int lrecord_type_##c_name; \
|
444
|
1291 extern struct lrecord_implementation lrecord_##c_name
|
428
|
1292 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
|
1293 extern Lisp_Object Q##c_name##p
|
|
1294 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
|
|
1295 # define XNONRECORD(x, c_name, type_enum, structtype) \
|
|
1296 ((structtype *) XPNTR (x))
|
617
|
1297 /* wrap_pointer_1 is so named as a suggestion not to use it unless you
|
|
1298 know what you're doing. */
|
|
1299 #define wrap_record(ptr, ty) wrap_pointer_1 (ptr)
|
428
|
1300
|
800
|
1301 #endif /* not ERROR_CHECK_TYPES */
|
428
|
1302
|
442
|
1303 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_type_##c_name)
|
428
|
1304
|
|
1305 /* Note: we now have two different kinds of type-checking macros.
|
|
1306 The "old" kind has now been renamed CONCHECK_foo. The reason for
|
|
1307 this is that the CONCHECK_foo macros signal a continuable error,
|
|
1308 allowing the user (through debug-on-error) to substitute a different
|
|
1309 value and return from the signal, which causes the lvalue argument
|
|
1310 to get changed. Quite a lot of code would crash if that happened,
|
|
1311 because it did things like
|
|
1312
|
|
1313 foo = XCAR (list);
|
|
1314 CHECK_STRING (foo);
|
|
1315
|
|
1316 and later on did XSTRING (XCAR (list)), assuming that the type
|
|
1317 is correct (when it might be wrong, if the user substituted a
|
|
1318 correct value in the debugger).
|
|
1319
|
|
1320 To get around this, I made all the CHECK_foo macros signal a
|
|
1321 non-continuable error. Places where a continuable error is OK
|
|
1322 (generally only when called directly on the argument of a Lisp
|
|
1323 primitive) should be changed to use CONCHECK().
|
|
1324
|
|
1325 FSF Emacs does not have this problem because RMS took the cheesy
|
|
1326 way out and disabled returning from a signal entirely. */
|
|
1327
|
|
1328 #define CONCHECK_RECORD(x, c_name) do { \
|
442
|
1329 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
|
428
|
1330 x = wrong_type_argument (Q##c_name##p, x); \
|
|
1331 } while (0)
|
|
1332 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
|
|
1333 if (XTYPE (x) != lisp_enum) \
|
|
1334 x = wrong_type_argument (predicate, x); \
|
|
1335 } while (0)
|
|
1336 #define CHECK_RECORD(x, c_name) do { \
|
442
|
1337 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
|
428
|
1338 dead_wrong_type_argument (Q##c_name##p, x); \
|
|
1339 } while (0)
|
|
1340 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
|
|
1341 if (XTYPE (x) != lisp_enum) \
|
|
1342 dead_wrong_type_argument (predicate, x); \
|
|
1343 } while (0)
|
|
1344
|
1204
|
1345 /*-------------------------- lcrecord-list -----------------------------*/
|
|
1346
|
|
1347 struct lcrecord_list
|
|
1348 {
|
|
1349 struct lcrecord_header header;
|
|
1350 Lisp_Object free;
|
|
1351 Elemcount size;
|
|
1352 const struct lrecord_implementation *implementation;
|
|
1353 };
|
|
1354
|
|
1355 DECLARE_LRECORD (lcrecord_list, struct lcrecord_list);
|
|
1356 #define XLCRECORD_LIST(x) XRECORD (x, lcrecord_list, struct lcrecord_list)
|
|
1357 #define wrap_lcrecord_list(p) wrap_record (p, lcrecord_list)
|
|
1358 #define LCRECORD_LISTP(x) RECORDP (x, lcrecord_list)
|
|
1359 /* #define CHECK_LCRECORD_LIST(x) CHECK_RECORD (x, lcrecord_list)
|
|
1360 Lcrecord lists should never escape to the Lisp level, so
|
|
1361 functions should not be doing this. */
|
|
1362
|
826
|
1363 /* Various ways of allocating lcrecords. All bytes (except lcrecord
|
1204
|
1364 header) are zeroed in returned structure.
|
|
1365
|
|
1366 See above for a discussion of the difference between plain lrecords and
|
|
1367 lrecords. lcrecords themselves are divided into three types: (1)
|
|
1368 auto-managed, (2) hand-managed, and (3) unmanaged. "Managed" refers to
|
|
1369 using a special object called an lcrecord-list to keep track of freed
|
|
1370 lcrecords, which can freed with free_lcrecord() or the like and later be
|
|
1371 recycled when a new lcrecord is required, rather than requiring new
|
|
1372 malloc(). Thus, allocation of lcrecords can be very
|
|
1373 cheap. (Technically, the lcrecord-list manager could divide up large
|
|
1374 chunks of memory and allocate out of that, mimicking what happens with
|
|
1375 lrecords. At that point, however, we'd want to rethink the whole
|
|
1376 division between lrecords and lcrecords.)
|
|
1377
|
|
1378 NOTE: There is a fundamental limitation of lcrecord-lists, which is that
|
|
1379 they only handle blocks of a particular, fixed size. Thus, objects that
|
|
1380 can be of varying sizes need to do various tricks. These considerations
|
|
1381 in particular dictate the various types of management:
|
|
1382
|
|
1383 -- "Auto-managed" means that you just go ahead and allocate the lcrecord
|
|
1384 whenever you want, using alloc_lcrecord_type(), and the appropriate
|
|
1385 lcrecord-list manager is automatically created. To free, you just call
|
|
1386 "free_lcrecord()" and the appropriate lcrecord-list manager is
|
|
1387 automatically located and called. The limitation here of course is that
|
|
1388 all your objects are of the same size. (#### Eventually we should have a
|
|
1389 more sophisticated system that tracks the sizes seen and creates one
|
|
1390 lcrecord list per size, indexed in a hash table. Usually there are only
|
|
1391 a limited number of sizes, so this works well.)
|
826
|
1392
|
1204
|
1393 -- "Hand-managed" exists because we haven't yet written the more
|
|
1394 sophisticated scheme for auto-handling different-sized lcrecords, as
|
|
1395 described in the end of the last paragraph. In this model, you go ahead
|
|
1396 and create the lcrecord-list objects yourself for the sizes you will
|
|
1397 need, using make_lcrecord_list(). Then, create lcrecords using
|
|
1398 alloc_managed_lcrecord(), passing in the lcrecord-list you created, and
|
|
1399 free them with free_managed_lcrecord().
|
|
1400
|
|
1401 -- "Unmanaged" means you simply allocate lcrecords, period. No
|
|
1402 lcrecord-lists, no way to free them. This may be suitable when the
|
|
1403 lcrecords are variable-sized and (a) you're too lazy to write the code
|
|
1404 to hand-manage them, or (b) the objects you create are always or almost
|
|
1405 always Lisp-visible, and thus there's no point in freeing them (and it
|
|
1406 wouldn't be safe to do so). You just create them with
|
|
1407 basic_alloc_lcrecord(), and that's it.
|
|
1408
|
|
1409 --ben
|
|
1410
|
|
1411 Here is an in-depth look at the steps required to create a allocate an
|
|
1412 lcrecord using the hand-managed style. Since this is the most
|
|
1413 complicated, you will learn a lot about the other styles as well. In
|
|
1414 addition, there is useful general information about what freeing an
|
|
1415 lcrecord really entails, and what are the precautions:
|
|
1416
|
|
1417 1) Create an lcrecord-list object using make_lcrecord_list(). This is
|
|
1418 often done at initialization. Remember to staticpro_nodump() this
|
|
1419 object! The arguments to make_lcrecord_list() are the same as would be
|
|
1420 passed to basic_alloc_lcrecord().
|
428
|
1421
|
1204
|
1422 2) Instead of calling basic_alloc_lcrecord(), call alloc_managed_lcrecord()
|
|
1423 and pass the lcrecord-list earlier created.
|
|
1424
|
|
1425 3) When done with the lcrecord, call free_managed_lcrecord(). The
|
|
1426 standard freeing caveats apply: ** make sure there are no pointers to
|
|
1427 the object anywhere! **
|
|
1428
|
|
1429 4) Calling free_managed_lcrecord() is just like kissing the
|
|
1430 lcrecord goodbye as if it were garbage-collected. This means:
|
|
1431 -- the contents of the freed lcrecord are undefined, and the
|
|
1432 contents of something produced by alloc_managed_lcrecord()
|
|
1433 are undefined, just like for basic_alloc_lcrecord().
|
|
1434 -- the mark method for the lcrecord's type will *NEVER* be called
|
|
1435 on freed lcrecords.
|
|
1436 -- the finalize method for the lcrecord's type will be called
|
|
1437 at the time that free_managed_lcrecord() is called.
|
|
1438 */
|
|
1439
|
|
1440 /* UNMANAGED MODEL: */
|
|
1441 void *basic_alloc_lcrecord (Bytecount size,
|
|
1442 const struct lrecord_implementation *);
|
|
1443
|
|
1444 /* HAND-MANAGED MODEL: */
|
|
1445 Lisp_Object make_lcrecord_list (Elemcount size,
|
|
1446 const struct lrecord_implementation
|
|
1447 *implementation);
|
|
1448 Lisp_Object alloc_managed_lcrecord (Lisp_Object lcrecord_list);
|
|
1449 void free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord);
|
|
1450
|
|
1451 /* AUTO-MANAGED MODEL: */
|
1632
|
1452 MODULE_API void *
|
|
1453 alloc_automanaged_lcrecord (Bytecount size,
|
|
1454 const struct lrecord_implementation *);
|
428
|
1455 #define alloc_lcrecord_type(type, lrecord_implementation) \
|
771
|
1456 ((type *) alloc_automanaged_lcrecord (sizeof (type), lrecord_implementation))
|
|
1457 void free_lcrecord (Lisp_Object rec);
|
|
1458
|
428
|
1459
|
|
1460 /* Copy the data from one lcrecord structure into another, but don't
|
|
1461 overwrite the header information. */
|
|
1462
|
771
|
1463 #define copy_sized_lcrecord(dst, src, size) \
|
2367
|
1464 memcpy ((Rawbyte *) (dst) + sizeof (struct lcrecord_header), \
|
|
1465 (Rawbyte *) (src) + sizeof (struct lcrecord_header), \
|
771
|
1466 (size) - sizeof (struct lcrecord_header))
|
|
1467
|
|
1468 #define copy_lcrecord(dst, src) copy_sized_lcrecord (dst, src, sizeof (*(dst)))
|
428
|
1469
|
771
|
1470 #define zero_sized_lcrecord(lcr, size) \
|
2367
|
1471 memset ((Rawbyte *) (lcr) + sizeof (struct lcrecord_header), 0, \
|
771
|
1472 (size) - sizeof (struct lcrecord_header))
|
|
1473
|
1204
|
1474 #define zero_lcrecord(lcr) zero_sized_lcrecord (lcr, sizeof (*(lcr)))
|
|
1475
|
|
1476 DECLARE_INLINE_HEADER (
|
|
1477 Bytecount
|
|
1478 detagged_lisp_object_size (const struct lrecord_header *h)
|
|
1479 )
|
|
1480 {
|
|
1481 const struct lrecord_implementation *imp = LHEADER_IMPLEMENTATION (h);
|
|
1482
|
|
1483 return (imp->size_in_bytes_method ?
|
|
1484 imp->size_in_bytes_method (h) :
|
|
1485 imp->static_size);
|
|
1486 }
|
|
1487
|
|
1488 DECLARE_INLINE_HEADER (
|
|
1489 Bytecount
|
|
1490 lisp_object_size (Lisp_Object o)
|
|
1491 )
|
|
1492 {
|
|
1493 return detagged_lisp_object_size (XRECORD_LHEADER (o));
|
|
1494 }
|
|
1495
|
|
1496
|
|
1497 /************************************************************************/
|
|
1498 /* Dumping */
|
|
1499 /************************************************************************/
|
|
1500
|
2367
|
1501 /* dump_add_root_block_ptr (&var, &desc) dumps the structure pointed to by
|
1204
|
1502 `var'. This is for a single relocatable pointer located in the data
|
2367
|
1503 segment (i.e. the block pointed to is in the heap).
|
|
1504
|
|
1505 If the structure pointed to is not a `struct' but an array, you should
|
|
1506 set the size field of the sized_memory_description to 0, and use
|
|
1507 XD_BLOCK_ARRAY in the inner memory_description.
|
|
1508
|
|
1509 NOTE that a "root struct pointer" could also be described using
|
|
1510 dump_add_root_block(), with SIZE == sizeof (void *), and a description
|
|
1511 containing a single XD_BLOCK_PTR entry, offset 0, size 1, with a
|
|
1512 structure description the same as the value passed to
|
|
1513 dump_add_root_block_ptr(). That would require an extra level of
|
|
1514 description, though, as compared to using dump_add_root_block_ptr(),
|
|
1515 and thus this function is generally more convenient.
|
|
1516 */
|
1204
|
1517 #ifdef PDUMP
|
2367
|
1518 void dump_add_root_block_ptr (void *, const struct sized_memory_description *);
|
1204
|
1519 #else
|
2367
|
1520 #define dump_add_root_block_ptr(varaddr, descaddr) DO_NOTHING
|
1204
|
1521 #endif
|
|
1522
|
|
1523 /* dump_add_opaque (&var, size) dumps the opaque static structure `var'.
|
|
1524 This is for a static block of memory (in the data segment, not the
|
|
1525 heap), with no relocatable pointers in it. */
|
|
1526 #ifdef PDUMP
|
|
1527 #define dump_add_opaque(varaddr,size) dump_add_root_block (varaddr, size, NULL)
|
|
1528 #else
|
|
1529 #define dump_add_opaque(varaddr,size) DO_NOTHING
|
|
1530 #endif
|
|
1531
|
|
1532 /* dump_add_root_block (ptr, size, desc) dumps the static structure
|
|
1533 located at `var' of size SIZE and described by DESC. This is for a
|
|
1534 static block of memory (in the data segment, not the heap), with
|
|
1535 relocatable pointers in it. */
|
|
1536 #ifdef PDUMP
|
|
1537 void dump_add_root_block (const void *ptraddress, Bytecount size,
|
|
1538 const struct memory_description *desc);
|
|
1539 #else
|
2367
|
1540 #define dump_add_root_block(ptraddress, size, desc) DO_NOTHING
|
1204
|
1541 #endif
|
|
1542
|
|
1543 /* Call dump_add_opaque_int (&int_var) to dump `int_var', of type `int'. */
|
|
1544 #ifdef PDUMP
|
|
1545 #define dump_add_opaque_int(int_varaddr) do { \
|
|
1546 int *dao_ = (int_varaddr); /* type check */ \
|
|
1547 dump_add_opaque (dao_, sizeof (*dao_)); \
|
|
1548 } while (0)
|
|
1549 #else
|
|
1550 #define dump_add_opaque_int(int_varaddr) DO_NOTHING
|
|
1551 #endif
|
|
1552
|
|
1553 /* Call dump_add_opaque_fixnum (&fixnum_var) to dump `fixnum_var', of type
|
|
1554 `Fixnum'. */
|
|
1555 #ifdef PDUMP
|
|
1556 #define dump_add_opaque_fixnum(fixnum_varaddr) do { \
|
|
1557 Fixnum *dao_ = (fixnum_varaddr); /* type check */ \
|
|
1558 dump_add_opaque (dao_, sizeof (*dao_)); \
|
|
1559 } while (0)
|
|
1560 #else
|
|
1561 #define dump_add_opaque_fixnum(fixnum_varaddr) DO_NOTHING
|
|
1562 #endif
|
|
1563
|
|
1564 /* Call dump_add_root_lisp_object (&var) to ensure that var is properly
|
|
1565 updated after pdump. */
|
|
1566 #ifdef PDUMP
|
|
1567 void dump_add_root_lisp_object (Lisp_Object *);
|
|
1568 #else
|
|
1569 #define dump_add_root_lisp_object(varaddr) DO_NOTHING
|
|
1570 #endif
|
|
1571
|
|
1572 /* Call dump_add_weak_lisp_object (&var) to ensure that var is properly
|
|
1573 updated after pdump. var must point to a linked list of objects out of
|
|
1574 which some may not be dumped */
|
|
1575 #ifdef PDUMP
|
|
1576 void dump_add_weak_object_chain (Lisp_Object *);
|
|
1577 #else
|
|
1578 #define dump_add_weak_object_chain(varaddr) DO_NOTHING
|
|
1579 #endif
|
|
1580
|
|
1581 /* Nonzero means Emacs has already been initialized.
|
|
1582 Used during startup to detect startup of dumped Emacs. */
|
1632
|
1583 extern MODULE_API int initialized;
|
1204
|
1584
|
|
1585 #ifdef PDUMP
|
1688
|
1586 #include "dumper.h"
|
2367
|
1587 #define DUMPEDP(adr) ((((Rawbyte *) (adr)) < pdump_end) && \
|
|
1588 (((Rawbyte *) (adr)) >= pdump_start))
|
1204
|
1589 #else
|
|
1590 #define DUMPEDP(adr) 0
|
|
1591 #endif
|
|
1592
|
1330
|
1593 #define OBJECT_DUMPED_P(obj) DUMPEDP (XPNTR (obj))
|
|
1594
|
1204
|
1595 /***********************************************************************/
|
|
1596 /* data descriptions */
|
|
1597 /***********************************************************************/
|
|
1598
|
|
1599
|
|
1600 #if defined (USE_KKCC) || defined (PDUMP)
|
|
1601
|
|
1602 extern int in_pdump;
|
|
1603
|
|
1604 EMACS_INT lispdesc_indirect_count_1 (EMACS_INT code,
|
|
1605 const struct memory_description *idesc,
|
|
1606 const void *idata);
|
|
1607 const struct sized_memory_description *lispdesc_indirect_description_1
|
|
1608 (const void *obj, const struct sized_memory_description *sdesc);
|
2367
|
1609 Bytecount lispdesc_block_size_1 (const void *obj, Bytecount size,
|
|
1610 const struct memory_description *desc);
|
|
1611
|
|
1612 DECLARE_INLINE_HEADER (
|
|
1613 Bytecount lispdesc_block_size (const void *obj,
|
|
1614 const struct sized_memory_description *sdesc))
|
|
1615 {
|
|
1616 return lispdesc_block_size_1 (obj, sdesc->size, sdesc->description);
|
|
1617 }
|
1204
|
1618
|
|
1619 DECLARE_INLINE_HEADER (
|
|
1620 EMACS_INT
|
|
1621 lispdesc_indirect_count (EMACS_INT code,
|
|
1622 const struct memory_description *idesc,
|
|
1623 const void *idata)
|
|
1624 )
|
|
1625 {
|
|
1626 if (XD_IS_INDIRECT (code))
|
|
1627 code = lispdesc_indirect_count_1 (code, idesc, idata);
|
|
1628 return code;
|
|
1629 }
|
|
1630
|
|
1631 DECLARE_INLINE_HEADER (
|
|
1632 const struct sized_memory_description *
|
|
1633 lispdesc_indirect_description (const void *obj,
|
|
1634 const struct sized_memory_description *sdesc)
|
|
1635 )
|
|
1636 {
|
|
1637 if (sdesc->description)
|
|
1638 return sdesc;
|
|
1639 else
|
|
1640 return lispdesc_indirect_description_1 (obj, sdesc);
|
|
1641 }
|
|
1642
|
|
1643
|
|
1644 /* Do standard XD_UNION processing. DESC1 is an entry in DESC, which
|
|
1645 describes the entire data structure. Returns NULL (do nothing, nothing
|
|
1646 matched), or a new value for DESC1. In the latter case, assign to DESC1
|
|
1647 in your function and goto union_switcheroo. */
|
|
1648
|
|
1649 DECLARE_INLINE_HEADER (
|
|
1650 const struct memory_description *
|
|
1651 lispdesc_process_xd_union (const struct memory_description *desc1,
|
|
1652 const struct memory_description *desc,
|
|
1653 const void *data)
|
|
1654 )
|
|
1655 {
|
|
1656 int count = 0;
|
|
1657 EMACS_INT variant = lispdesc_indirect_count (desc1->data1, desc,
|
|
1658 data);
|
|
1659 desc1 =
|
2551
|
1660 lispdesc_indirect_description (data, desc1->data2.descr)->description;
|
1204
|
1661
|
|
1662 for (count = 0; desc1[count].type != XD_END; count++)
|
|
1663 {
|
|
1664 if ((desc1[count].flags & XD_FLAG_UNION_DEFAULT_ENTRY) ||
|
|
1665 desc1[count].offset == variant)
|
|
1666 {
|
|
1667 return &desc1[count];
|
|
1668 }
|
|
1669 }
|
|
1670
|
|
1671 return NULL;
|
|
1672 }
|
|
1673
|
|
1674 #endif /* defined (USE_KKCC) || defined (PDUMP) */
|
428
|
1675
|
1743
|
1676 END_C_DECLS
|
1650
|
1677
|
440
|
1678 #endif /* INCLUDED_lrecord_h_ */
|