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