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