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