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