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