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