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