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