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