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