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