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