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