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