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