428
|
1 /* The "lrecord" structure (header of a compound lisp object).
|
|
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1996 Ben Wing.
|
|
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
|
440
|
24 #ifndef INCLUDED_lrecord_h_
|
|
25 #define INCLUDED_lrecord_h_
|
428
|
26
|
|
27 /* The "lrecord" type of Lisp object is used for all object types
|
|
28 other than a few simple ones. This allows many types to be
|
442
|
29 implemented but only a few bits required in a Lisp object for type
|
|
30 information. (The tradeoff is that each object has its type marked
|
|
31 in it, thereby increasing its size.) All lrecords begin with a
|
|
32 `struct lrecord_header', which identifies the lisp object type, by
|
|
33 providing an index into a table of `struct lrecord_implementation',
|
|
34 which describes the behavior of the lisp object. It also contains
|
|
35 some other data bits.
|
428
|
36
|
|
37 Lrecords are of two types: straight lrecords, and lcrecords.
|
|
38 Straight lrecords are used for those types of objects that have
|
|
39 their own allocation routines (typically allocated out of 2K chunks
|
|
40 of memory called `frob blocks'). These objects have a `struct
|
|
41 lrecord_header' at the top, containing only the bits needed to find
|
|
42 the lrecord_implementation for the object. There are special
|
|
43 routines in alloc.c to deal with each such object type.
|
|
44
|
442
|
45 Lcrecords are used for less common sorts of objects that don't do
|
|
46 their own allocation. Each such object is malloc()ed individually,
|
|
47 and the objects are chained together through a `next' pointer.
|
|
48 Lcrecords have a `struct lcrecord_header' at the top, which
|
|
49 contains a `struct lrecord_header' and a `next' pointer, and are
|
|
50 allocated using alloc_lcrecord().
|
428
|
51
|
|
52 Creating a new lcrecord type is fairly easy; just follow the
|
|
53 lead of some existing type (e.g. hash tables). Note that you
|
|
54 do not need to supply all the methods (see below); reasonable
|
|
55 defaults are provided for many of them. Alternatively, if you're
|
|
56 just looking for a way of encapsulating data (which possibly
|
|
57 could contain Lisp_Objects in it), you may well be able to use
|
|
58 the opaque type. */
|
|
59
|
|
60 struct lrecord_header
|
|
61 {
|
|
62 /* index into lrecord_implementations_table[] */
|
442
|
63 unsigned int type :8;
|
|
64
|
|
65 /* If `mark' is 0 after the GC mark phase, the object will be freed
|
|
66 during the GC sweep phase. There are 2 ways that `mark' can be 1:
|
|
67 - by being referenced from other objects during the GC mark phase
|
|
68 - because it is permanently on, for c_readonly objects */
|
|
69 unsigned int mark :1;
|
|
70
|
|
71 /* 1 if the object resides in logically read-only space, and does not
|
|
72 reference other non-c_readonly objects.
|
|
73 Invariant: if (c_readonly == 1), then (mark == 1 && lisp_readonly == 1) */
|
|
74 unsigned int c_readonly :1;
|
|
75
|
428
|
76 /* 1 if the object is readonly from lisp */
|
442
|
77 unsigned int lisp_readonly :1;
|
428
|
78 };
|
|
79
|
|
80 struct lrecord_implementation;
|
442
|
81 int lrecord_type_index (const struct lrecord_implementation *implementation);
|
428
|
82
|
430
|
83 #define set_lheader_implementation(header,imp) do { \
|
428
|
84 struct lrecord_header* SLI_header = (header); \
|
442
|
85 SLI_header->type = (imp)->lrecord_type_index; \
|
430
|
86 SLI_header->mark = 0; \
|
|
87 SLI_header->c_readonly = 0; \
|
|
88 SLI_header->lisp_readonly = 0; \
|
428
|
89 } while (0)
|
|
90
|
|
91 struct lcrecord_header
|
|
92 {
|
|
93 struct lrecord_header lheader;
|
|
94
|
442
|
95 /* The `next' field is normally used to chain all lcrecords together
|
428
|
96 so that the GC can find (and free) all of them.
|
442
|
97 `alloc_lcrecord' threads lcrecords together.
|
428
|
98
|
|
99 The `next' field may be used for other purposes as long as some
|
|
100 other mechanism is provided for letting the GC do its work.
|
|
101
|
|
102 For example, the event and marker object types allocate members
|
|
103 out of memory chunks, and are able to find all unmarked members
|
|
104 by sweeping through the elements of the list of chunks. */
|
|
105 struct lcrecord_header *next;
|
|
106
|
|
107 /* The `uid' field is just for debugging/printing convenience.
|
|
108 Having this slot doesn't hurt us much spacewise, since an
|
|
109 lcrecord already has the above slots plus malloc overhead. */
|
|
110 unsigned int uid :31;
|
|
111
|
|
112 /* The `free' field is a flag that indicates whether this lcrecord
|
|
113 is on a "free list". Free lists are used to minimize the number
|
|
114 of calls to malloc() when we're repeatedly allocating and freeing
|
|
115 a number of the same sort of lcrecord. Lcrecords on a free list
|
|
116 always get marked in a different fashion, so we can use this flag
|
|
117 as a sanity check to make sure that free lists only have freed
|
|
118 lcrecords and there are no freed lcrecords elsewhere. */
|
|
119 unsigned int free :1;
|
|
120 };
|
|
121
|
|
122 /* Used for lcrecords in an lcrecord-list. */
|
|
123 struct free_lcrecord_header
|
|
124 {
|
|
125 struct lcrecord_header lcheader;
|
|
126 Lisp_Object chain;
|
|
127 };
|
|
128
|
442
|
129 enum lrecord_type
|
|
130 {
|
|
131 /* Symbol value magic types come first to make SYMBOL_VALUE_MAGIC_P fast.
|
|
132 #### This should be replaced by a symbol_value_magic_p flag
|
|
133 in the Lisp_Symbol lrecord_header. */
|
|
134 lrecord_type_symbol_value_forward,
|
|
135 lrecord_type_symbol_value_varalias,
|
|
136 lrecord_type_symbol_value_lisp_magic,
|
|
137 lrecord_type_symbol_value_buffer_local,
|
|
138 lrecord_type_max_symbol_value_magic = lrecord_type_symbol_value_buffer_local,
|
|
139
|
|
140 lrecord_type_symbol,
|
|
141 lrecord_type_subr,
|
|
142 lrecord_type_cons,
|
|
143 lrecord_type_vector,
|
|
144 lrecord_type_string,
|
|
145 lrecord_type_lcrecord_list,
|
|
146 lrecord_type_compiled_function,
|
|
147 lrecord_type_weak_list,
|
|
148 lrecord_type_bit_vector,
|
|
149 lrecord_type_float,
|
|
150 lrecord_type_hash_table,
|
|
151 lrecord_type_lstream,
|
|
152 lrecord_type_process,
|
|
153 lrecord_type_charset,
|
|
154 lrecord_type_coding_system,
|
|
155 lrecord_type_char_table,
|
|
156 lrecord_type_char_table_entry,
|
|
157 lrecord_type_range_table,
|
|
158 lrecord_type_opaque,
|
|
159 lrecord_type_opaque_ptr,
|
|
160 lrecord_type_buffer,
|
|
161 lrecord_type_extent,
|
|
162 lrecord_type_extent_info,
|
|
163 lrecord_type_extent_auxiliary,
|
|
164 lrecord_type_marker,
|
|
165 lrecord_type_event,
|
|
166 lrecord_type_keymap,
|
|
167 lrecord_type_command_builder,
|
|
168 lrecord_type_timeout,
|
|
169 lrecord_type_specifier,
|
|
170 lrecord_type_console,
|
|
171 lrecord_type_device,
|
|
172 lrecord_type_frame,
|
|
173 lrecord_type_window,
|
617
|
174 lrecord_type_window_mirror,
|
442
|
175 lrecord_type_window_configuration,
|
|
176 lrecord_type_gui_item,
|
|
177 lrecord_type_popup_data,
|
|
178 lrecord_type_toolbar_button,
|
617
|
179 lrecord_type_scrollbar_instance,
|
442
|
180 lrecord_type_color_instance,
|
|
181 lrecord_type_font_instance,
|
|
182 lrecord_type_image_instance,
|
|
183 lrecord_type_glyph,
|
|
184 lrecord_type_face,
|
|
185 lrecord_type_database,
|
|
186 lrecord_type_tooltalk_message,
|
|
187 lrecord_type_tooltalk_pattern,
|
|
188 lrecord_type_ldap,
|
|
189 lrecord_type_pgconn,
|
|
190 lrecord_type_pgresult,
|
|
191 lrecord_type_devmode,
|
|
192 lrecord_type_mswindows_dialog_id,
|
446
|
193 lrecord_type_case_table,
|
462
|
194 lrecord_type_emacs_ffi,
|
|
195 lrecord_type_emacs_gtk_object,
|
|
196 lrecord_type_emacs_gtk_boxed,
|
454
|
197 lrecord_type_free, /* only used for "free" lrecords */
|
|
198 lrecord_type_undefined, /* only used for debugging */
|
442
|
199 lrecord_type_last_built_in_type /* must be last */
|
|
200 };
|
|
201
|
647
|
202 extern int lrecord_type_count;
|
428
|
203
|
|
204 struct lrecord_implementation
|
|
205 {
|
442
|
206 const char *name;
|
|
207
|
|
208 /* `marker' is called at GC time, to make sure that all Lisp_Objects
|
428
|
209 pointed to by this object get properly marked. It should call
|
|
210 the mark_object function on all Lisp_Objects in the object. If
|
|
211 the return value is non-nil, it should be a Lisp_Object to be
|
|
212 marked (don't call the mark_object function explicitly on it,
|
|
213 because the GC routines will do this). Doing it this way reduces
|
|
214 recursion, so the object returned should preferably be the one
|
|
215 with the deepest level of Lisp_Object pointers. This function
|
|
216 can be NULL, meaning no GC marking is necessary. */
|
|
217 Lisp_Object (*marker) (Lisp_Object);
|
442
|
218
|
|
219 /* `printer' converts the object to a printed representation.
|
|
220 This can be NULL; in this case default_object_printer() will be
|
|
221 used instead. */
|
428
|
222 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
|
442
|
223
|
|
224 /* `finalizer' is called at GC time when the object is about to
|
428
|
225 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
|
|
226 case). It should perform any necessary cleanup (e.g. freeing
|
442
|
227 malloc()ed memory). This can be NULL, meaning no special
|
428
|
228 finalization is necessary.
|
|
229
|
442
|
230 WARNING: remember that `finalizer' is called at dump time even
|
428
|
231 though the object is not being freed. */
|
|
232 void (*finalizer) (void *header, int for_disksave);
|
442
|
233
|
428
|
234 /* This can be NULL, meaning compare objects with EQ(). */
|
|
235 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
|
442
|
236
|
|
237 /* `hash' generates hash values for use with hash tables that have
|
|
238 `equal' as their test function. This can be NULL, meaning use
|
|
239 the Lisp_Object itself as the hash. But, you must still satisfy
|
|
240 the constraint that if two objects are `equal', then they *must*
|
|
241 hash to the same value in order for hash tables to work properly.
|
|
242 This means that `hash' can be NULL only if the `equal' method is
|
|
243 also NULL. */
|
428
|
244 unsigned long (*hash) (Lisp_Object, int);
|
|
245
|
|
246 /* External data layout description */
|
|
247 const struct lrecord_description *description;
|
|
248
|
442
|
249 /* These functions allow any object type to have builtin property
|
|
250 lists that can be manipulated from the lisp level with
|
|
251 `get', `put', `remprop', and `object-plist'. */
|
428
|
252 Lisp_Object (*getprop) (Lisp_Object obj, Lisp_Object prop);
|
|
253 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
|
|
254 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
|
|
255 Lisp_Object (*plist) (Lisp_Object obj);
|
|
256
|
442
|
257 /* Only one of `static_size' and `size_in_bytes_method' is non-0.
|
|
258 If both are 0, this type is not instantiable by alloc_lcrecord(). */
|
665
|
259 Bytecount static_size;
|
|
260 Bytecount (*size_in_bytes_method) (const void *header);
|
442
|
261
|
|
262 /* The (constant) index into lrecord_implementations_table */
|
|
263 enum lrecord_type lrecord_type_index;
|
|
264
|
428
|
265 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
|
|
266 one that does not have an lcrecord_header at the front and which
|
|
267 is (usually) allocated in frob blocks. We only use this flag for
|
|
268 some consistency checking, and that only when error-checking is
|
|
269 enabled. */
|
442
|
270 unsigned int basic_p :1;
|
428
|
271 };
|
|
272
|
617
|
273 /* All the built-in lisp object types are enumerated in `enum lrecord_type'.
|
442
|
274 Additional ones may be defined by a module (none yet). We leave some
|
|
275 room in `lrecord_implementations_table' for such new lisp object types. */
|
|
276 #define MODULE_DEFINABLE_TYPE_COUNT 32
|
|
277
|
647
|
278 extern const struct lrecord_implementation *lrecord_implementations_table[lrecord_type_last_built_in_type + MODULE_DEFINABLE_TYPE_COUNT];
|
428
|
279
|
|
280 #define XRECORD_LHEADER_IMPLEMENTATION(obj) \
|
442
|
281 LHEADER_IMPLEMENTATION (XRECORD_LHEADER (obj))
|
|
282 #define LHEADER_IMPLEMENTATION(lh) lrecord_implementations_table[(lh)->type]
|
428
|
283
|
|
284 extern int gc_in_progress;
|
|
285
|
442
|
286 #define MARKED_RECORD_P(obj) (XRECORD_LHEADER (obj)->mark)
|
428
|
287 #define MARKED_RECORD_HEADER_P(lheader) ((lheader)->mark)
|
|
288 #define MARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 1))
|
|
289 #define UNMARK_RECORD_HEADER(lheader) ((void) ((lheader)->mark = 0))
|
|
290
|
|
291 #define C_READONLY_RECORD_HEADER_P(lheader) ((lheader)->c_readonly)
|
|
292 #define LISP_READONLY_RECORD_HEADER_P(lheader) ((lheader)->lisp_readonly)
|
442
|
293 #define SET_C_READONLY_RECORD_HEADER(lheader) do { \
|
|
294 struct lrecord_header *SCRRH_lheader = (lheader); \
|
|
295 SCRRH_lheader->c_readonly = 1; \
|
|
296 SCRRH_lheader->lisp_readonly = 1; \
|
|
297 SCRRH_lheader->mark = 1; \
|
|
298 } while (0)
|
428
|
299 #define SET_LISP_READONLY_RECORD_HEADER(lheader) \
|
|
300 ((void) ((lheader)->lisp_readonly = 1))
|
442
|
301 #define RECORD_MARKER(lheader) lrecord_markers[(lheader)->type]
|
428
|
302
|
|
303 /* External description stuff
|
|
304
|
|
305 A lrecord external description is an array of values. The first
|
|
306 value of each line is a type, the second the offset in the lrecord
|
|
307 structure. Following values are parameters, their presence, type
|
442
|
308 and number is type-dependent.
|
428
|
309
|
|
310 The description ends with a "XD_END" or "XD_SPECIFIER_END" record.
|
|
311
|
|
312 Some example descriptions :
|
440
|
313
|
428
|
314 static const struct lrecord_description cons_description[] = {
|
440
|
315 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car) },
|
|
316 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr) },
|
428
|
317 { XD_END }
|
|
318 };
|
|
319
|
440
|
320 Which means "two lisp objects starting at the 'car' and 'cdr' elements"
|
428
|
321
|
|
322 static const struct lrecord_description string_description[] = {
|
440
|
323 { XD_BYTECOUNT, offsetof (Lisp_String, size) },
|
|
324 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data), XD_INDIRECT(0, 1) },
|
|
325 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
|
428
|
326 { XD_END }
|
|
327 };
|
|
328 "A pointer to string data at 'data', the size of the pointed array being the value
|
|
329 of the size variable plus 1, and one lisp object at 'plist'"
|
|
330
|
|
331 The existing types :
|
|
332 XD_LISP_OBJECT
|
440
|
333 A Lisp object. This is also the type to use for pointers to other lrecords.
|
428
|
334
|
440
|
335 XD_LISP_OBJECT_ARRAY
|
|
336 An array of Lisp objects or pointers to lrecords.
|
|
337 The third element is the count.
|
|
338
|
428
|
339 XD_LO_LINK
|
|
340 Link in a linked list of objects of the same type.
|
432
|
341
|
428
|
342 XD_OPAQUE_PTR
|
|
343 Pointer to undumpable data. Must be NULL when dumping.
|
|
344
|
|
345 XD_STRUCT_PTR
|
|
346 Pointer to described struct. Parameters are number of structures and
|
|
347 struct_description.
|
|
348
|
|
349 XD_OPAQUE_DATA_PTR
|
|
350 Pointer to dumpable opaque data. Parameter is the size of the data.
|
|
351 Pointed data must be relocatable without changes.
|
|
352
|
|
353 XD_C_STRING
|
|
354 Pointer to a C string.
|
|
355
|
|
356 XD_DOC_STRING
|
|
357 Pointer to a doc string (C string if positive, opaque value if negative)
|
|
358
|
|
359 XD_INT_RESET
|
|
360 An integer which will be reset to a given value in the dump file.
|
|
361
|
665
|
362
|
|
363 XD_CHARCOUNT
|
|
364 Charcount value. Used for counts.
|
|
365
|
|
366 XD_ELEMCOUNT
|
|
367 Elemcount value. Used for counts.
|
647
|
368
|
665
|
369 XD_BYTECOUNT
|
|
370 Bytecount value. Used for counts.
|
647
|
371
|
665
|
372 XD_HASHCODE
|
|
373 Hashcode value. Used for the results of hashing functions.
|
428
|
374
|
|
375 XD_INT
|
|
376 int value. Used for counts.
|
|
377
|
|
378 XD_LONG
|
|
379 long value. Used for counts.
|
|
380
|
|
381 XD_END
|
|
382 Special type indicating the end of the array.
|
|
383
|
|
384 XD_SPECIFIER_END
|
|
385 Special type indicating the end of the array for a specifier. Extra
|
|
386 description is going to be fetched from the specifier methods.
|
|
387
|
|
388
|
|
389 Special macros:
|
|
390 XD_INDIRECT(line, delta)
|
|
391 Usable where a "count" or "size" is requested. Gives the value of
|
|
392 the element which is at line number 'line' in the description (count
|
|
393 starts at zero) and adds delta to it.
|
|
394 */
|
|
395
|
647
|
396 enum lrecord_description_type
|
|
397 {
|
440
|
398 XD_LISP_OBJECT_ARRAY,
|
428
|
399 XD_LISP_OBJECT,
|
|
400 XD_LO_LINK,
|
|
401 XD_OPAQUE_PTR,
|
|
402 XD_STRUCT_PTR,
|
|
403 XD_OPAQUE_DATA_PTR,
|
|
404 XD_C_STRING,
|
|
405 XD_DOC_STRING,
|
|
406 XD_INT_RESET,
|
665
|
407 XD_CHARCOUNT,
|
|
408 XD_BYTECOUNT,
|
|
409 XD_ELEMCOUNT,
|
|
410 XD_HASHCODE,
|
428
|
411 XD_INT,
|
|
412 XD_LONG,
|
|
413 XD_END,
|
|
414 XD_SPECIFIER_END
|
|
415 };
|
|
416
|
647
|
417 struct lrecord_description
|
|
418 {
|
428
|
419 enum lrecord_description_type type;
|
|
420 int offset;
|
|
421 EMACS_INT data1;
|
|
422 const struct struct_description *data2;
|
|
423 };
|
|
424
|
647
|
425 struct struct_description
|
|
426 {
|
665
|
427 Bytecount size;
|
428
|
428 const struct lrecord_description *description;
|
|
429 };
|
|
430
|
|
431 #define XD_INDIRECT(val, delta) (-1-((val)|(delta<<8)))
|
|
432
|
|
433 #define XD_IS_INDIRECT(code) (code<0)
|
|
434 #define XD_INDIRECT_VAL(code) ((-1-code) & 255)
|
|
435 #define XD_INDIRECT_DELTA(code) (((-1-code)>>8) & 255)
|
|
436
|
|
437 #define XD_DYNARR_DESC(base_type, sub_desc) \
|
440
|
438 { XD_STRUCT_PTR, offsetof (base_type, base), XD_INDIRECT(1, 0), sub_desc }, \
|
|
439 { XD_INT, offsetof (base_type, cur) }, \
|
|
440 { XD_INT_RESET, offsetof (base_type, max), XD_INDIRECT(1, 0) }
|
428
|
441
|
|
442 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
|
|
443 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
|
|
444 */
|
|
445
|
|
446 #if defined (ERROR_CHECK_TYPECHECK)
|
|
447 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
|
|
448 #else
|
|
449 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
|
|
450 #endif
|
|
451
|
|
452 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
453 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
454
|
442
|
455 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
456 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof(structtype),0,1,structtype)
|
428
|
457
|
|
458 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
459 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
460
|
442
|
461 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
462 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
428
|
463
|
|
464 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
465 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
466
|
442
|
467 #define DEFINE_BASIC_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
468 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,0,sizer,1,structtype)
|
428
|
469
|
442
|
470 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
|
471 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype) \
|
|
472
|
|
473 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
428
|
474 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
442
|
475 const struct lrecord_implementation lrecord_##c_name = \
|
428
|
476 { name, marker, printer, nuker, equal, hash, desc, \
|
442
|
477 getprop, putprop, remprop, plist, size, sizer, \
|
|
478 lrecord_type_##c_name, basic_p }
|
|
479
|
|
480 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,structtype) \
|
|
481 DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,structtype)
|
|
482
|
|
483 #define DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,structtype) \
|
|
484 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizeof (structtype),0,0,structtype)
|
|
485
|
|
486 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,sizer,structtype) \
|
|
487 DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,0,0,0,0,sizer,structtype)
|
|
488
|
|
489 #define DEFINE_EXTERNAL_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,sizer,structtype) \
|
|
490 MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,0,sizer,0,structtype)
|
|
491
|
|
492 #define MAKE_EXTERNAL_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,desc,getprop,putprop,remprop,plist,size,sizer,basic_p,structtype) \
|
|
493 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
|
647
|
494 int lrecord_type_##c_name; \
|
444
|
495 struct lrecord_implementation lrecord_##c_name = \
|
442
|
496 { name, marker, printer, nuker, equal, hash, desc, \
|
|
497 getprop, putprop, remprop, plist, size, sizer, \
|
444
|
498 lrecord_type_last_built_in_type, basic_p }
|
442
|
499
|
|
500
|
|
501 extern Lisp_Object (*lrecord_markers[]) (Lisp_Object);
|
|
502
|
|
503 #define INIT_LRECORD_IMPLEMENTATION(type) do { \
|
|
504 lrecord_implementations_table[lrecord_type_##type] = &lrecord_##type; \
|
|
505 lrecord_markers[lrecord_type_##type] = \
|
|
506 lrecord_implementations_table[lrecord_type_##type]->marker; \
|
|
507 } while (0)
|
428
|
508
|
444
|
509 #define INIT_EXTERNAL_LRECORD_IMPLEMENTATION(type) do { \
|
|
510 lrecord_type_##type = lrecord_type_count++; \
|
|
511 lrecord_##type.lrecord_type_index = lrecord_type_##type; \
|
|
512 INIT_LRECORD_IMPLEMENTATION(type); \
|
|
513 } while (0)
|
|
514
|
428
|
515 #define LRECORDP(a) (XTYPE (a) == Lisp_Type_Record)
|
|
516 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
|
|
517
|
|
518 #define RECORD_TYPEP(x, ty) \
|
647
|
519 (LRECORDP (x) && (XRECORD_LHEADER (x)->type == (unsigned int) (ty)))
|
442
|
520
|
|
521 /* Steps to create a new object:
|
|
522
|
|
523 1. Declare the struct for your object in a header file somewhere.
|
|
524 Remember that it must begin with
|
|
525
|
|
526 struct lcrecord_header header;
|
|
527
|
617
|
528 2. Put the "standard junk" (DECLARE_RECORD()/XFOO/XSETFOO/etc.) below the
|
|
529 struct definition -- see below.
|
442
|
530
|
|
531 3. Add this header file to inline.c.
|
|
532
|
|
533 4. Create the methods for your object. Note that technically you don't
|
|
534 need any, but you will almost always want at least a mark method.
|
|
535
|
|
536 5. Define your object with DEFINE_LRECORD_IMPLEMENTATION() or some
|
|
537 variant.
|
|
538
|
|
539 6. Include the header file in the .c file where you defined the object.
|
|
540
|
|
541 7. Put a call to INIT_LRECORD_IMPLEMENTATION() for the object in the
|
|
542 .c file's syms_of_foo() function.
|
|
543
|
|
544 8. Add a type enum for the object to enum lrecord_type, earlier in this
|
|
545 file.
|
|
546
|
|
547 An example:
|
428
|
548
|
442
|
549 ------------------------------ in toolbar.h -----------------------------
|
|
550
|
|
551 struct toolbar_button
|
|
552 {
|
|
553 struct lcrecord_header header;
|
|
554
|
|
555 Lisp_Object next;
|
|
556 Lisp_Object frame;
|
|
557
|
|
558 Lisp_Object up_glyph;
|
|
559 Lisp_Object down_glyph;
|
|
560 Lisp_Object disabled_glyph;
|
|
561
|
|
562 Lisp_Object cap_up_glyph;
|
|
563 Lisp_Object cap_down_glyph;
|
|
564 Lisp_Object cap_disabled_glyph;
|
|
565
|
|
566 Lisp_Object callback;
|
|
567 Lisp_Object enabled_p;
|
|
568 Lisp_Object help_string;
|
|
569
|
|
570 char enabled;
|
|
571 char down;
|
|
572 char pushright;
|
|
573 char blank;
|
|
574
|
|
575 int x, y;
|
|
576 int width, height;
|
|
577 int dirty;
|
|
578 int vertical;
|
|
579 int border_width;
|
|
580 };
|
428
|
581
|
617
|
582 [[ the standard junk: ]]
|
|
583
|
442
|
584 DECLARE_LRECORD (toolbar_button, struct toolbar_button);
|
|
585 #define XTOOLBAR_BUTTON(x) XRECORD (x, toolbar_button, struct toolbar_button)
|
|
586 #define XSETTOOLBAR_BUTTON(x, p) XSETRECORD (x, p, toolbar_button)
|
617
|
587 #define wrap_toolbar_button(p) wrap_record (p, toolbar_button)
|
442
|
588 #define TOOLBAR_BUTTONP(x) RECORDP (x, toolbar_button)
|
|
589 #define CHECK_TOOLBAR_BUTTON(x) CHECK_RECORD (x, toolbar_button)
|
|
590 #define CONCHECK_TOOLBAR_BUTTON(x) CONCHECK_RECORD (x, toolbar_button)
|
|
591
|
|
592 ------------------------------ in toolbar.c -----------------------------
|
|
593
|
|
594 #include "toolbar.h"
|
|
595
|
|
596 ...
|
|
597
|
|
598 static Lisp_Object
|
|
599 mark_toolbar_button (Lisp_Object obj)
|
|
600 {
|
|
601 struct toolbar_button *data = XTOOLBAR_BUTTON (obj);
|
|
602 mark_object (data->next);
|
|
603 mark_object (data->frame);
|
|
604 mark_object (data->up_glyph);
|
|
605 mark_object (data->down_glyph);
|
|
606 mark_object (data->disabled_glyph);
|
|
607 mark_object (data->cap_up_glyph);
|
|
608 mark_object (data->cap_down_glyph);
|
|
609 mark_object (data->cap_disabled_glyph);
|
|
610 mark_object (data->callback);
|
|
611 mark_object (data->enabled_p);
|
|
612 return data->help_string;
|
|
613 }
|
|
614
|
617
|
615 [[ If your object should never escape to Lisp, declare its print method
|
|
616 as internal_object_printer instead of 0. ]]
|
|
617
|
442
|
618 DEFINE_LRECORD_IMPLEMENTATION ("toolbar-button", toolbar_button,
|
617
|
619 mark_toolbar_button, 0,
|
|
620 0, 0, 0, 0, struct toolbar_button);
|
442
|
621
|
|
622 ...
|
|
623
|
|
624 void
|
|
625 syms_of_toolbar (void)
|
|
626 {
|
|
627 INIT_LRECORD_IMPLEMENTATION (toolbar_button);
|
|
628
|
|
629 ...;
|
|
630 }
|
|
631
|
|
632 ------------------------------ in inline.c -----------------------------
|
|
633
|
|
634 #ifdef HAVE_TOOLBARS
|
|
635 #include "toolbar.h"
|
|
636 #endif
|
|
637
|
|
638 ------------------------------ in lrecord.h -----------------------------
|
|
639
|
|
640 enum lrecord_type
|
|
641 {
|
|
642 ...
|
|
643 lrecord_type_toolbar_button,
|
|
644 ...
|
|
645 };
|
|
646
|
|
647 */
|
|
648
|
|
649 /*
|
|
650
|
|
651 Note: Object types defined in external dynamically-loaded modules (not
|
|
652 part of the XEmacs main source code) should use DECLARE_EXTERNAL_LRECORD
|
|
653 and DEFINE_EXTERNAL_LRECORD_IMPLEMENTATION rather than DECLARE_LRECORD
|
|
654 and DEFINE_LRECORD_IMPLEMENTATION.
|
|
655
|
|
656 */
|
|
657
|
428
|
658
|
|
659 #ifdef ERROR_CHECK_TYPECHECK
|
|
660
|
|
661 # define DECLARE_LRECORD(c_name, structtype) \
|
442
|
662 extern const struct lrecord_implementation lrecord_##c_name; \
|
|
663 INLINE_HEADER structtype * \
|
|
664 error_check_##c_name (Lisp_Object obj); \
|
|
665 INLINE_HEADER structtype * \
|
428
|
666 error_check_##c_name (Lisp_Object obj) \
|
|
667 { \
|
442
|
668 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
|
428
|
669 return (structtype *) XPNTR (obj); \
|
|
670 } \
|
|
671 extern Lisp_Object Q##c_name##p
|
|
672
|
442
|
673 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
|
647
|
674 extern int lrecord_type_##c_name; \
|
444
|
675 extern struct lrecord_implementation lrecord_##c_name; \
|
|
676 INLINE_HEADER structtype * \
|
|
677 error_check_##c_name (Lisp_Object obj); \
|
|
678 INLINE_HEADER structtype * \
|
|
679 error_check_##c_name (Lisp_Object obj) \
|
|
680 { \
|
|
681 assert (RECORD_TYPEP (obj, lrecord_type_##c_name)); \
|
|
682 return (structtype *) XPNTR (obj); \
|
|
683 } \
|
|
684 extern Lisp_Object Q##c_name##p
|
442
|
685
|
428
|
686 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
442
|
687 INLINE_HEADER structtype * \
|
|
688 error_check_##c_name (Lisp_Object obj); \
|
|
689 INLINE_HEADER structtype * \
|
428
|
690 error_check_##c_name (Lisp_Object obj) \
|
|
691 { \
|
|
692 assert (XTYPE (obj) == type_enum); \
|
|
693 return (structtype *) XPNTR (obj); \
|
|
694 } \
|
|
695 extern Lisp_Object Q##c_name##p
|
|
696
|
|
697 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
|
|
698 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
|
|
699
|
|
700 # define XSETRECORD(var, p, c_name) do \
|
|
701 { \
|
442
|
702 XSETOBJ (var, p); \
|
|
703 assert (RECORD_TYPEP (var, lrecord_type_##c_name)); \
|
428
|
704 } while (0)
|
|
705
|
617
|
706 INLINE_HEADER Lisp_Object wrap_record_1 (void *ptr, enum lrecord_type ty);
|
|
707 INLINE_HEADER Lisp_Object
|
|
708 wrap_record_1 (void *ptr, enum lrecord_type ty)
|
|
709 {
|
|
710 Lisp_Object obj;
|
|
711 XSETOBJ (obj, ptr);
|
|
712 assert (RECORD_TYPEP (obj, ty));
|
|
713 return obj;
|
|
714 }
|
|
715
|
|
716 #define wrap_record(ptr, ty) wrap_record_1 (ptr, lrecord_type_##ty)
|
|
717
|
428
|
718 #else /* not ERROR_CHECK_TYPECHECK */
|
|
719
|
|
720 # define DECLARE_LRECORD(c_name, structtype) \
|
|
721 extern Lisp_Object Q##c_name##p; \
|
442
|
722 extern const struct lrecord_implementation lrecord_##c_name
|
|
723 # define DECLARE_EXTERNAL_LRECORD(c_name, structtype) \
|
|
724 extern Lisp_Object Q##c_name##p; \
|
647
|
725 extern int lrecord_type_##c_name; \
|
444
|
726 extern struct lrecord_implementation lrecord_##c_name
|
428
|
727 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
|
|
728 extern Lisp_Object Q##c_name##p
|
|
729 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
|
|
730 # define XNONRECORD(x, c_name, type_enum, structtype) \
|
|
731 ((structtype *) XPNTR (x))
|
442
|
732 # define XSETRECORD(var, p, c_name) XSETOBJ (var, p)
|
617
|
733 /* wrap_pointer_1 is so named as a suggestion not to use it unless you
|
|
734 know what you're doing. */
|
|
735 #define wrap_record(ptr, ty) wrap_pointer_1 (ptr)
|
428
|
736
|
|
737 #endif /* not ERROR_CHECK_TYPECHECK */
|
|
738
|
442
|
739 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_type_##c_name)
|
428
|
740
|
|
741 /* Note: we now have two different kinds of type-checking macros.
|
|
742 The "old" kind has now been renamed CONCHECK_foo. The reason for
|
|
743 this is that the CONCHECK_foo macros signal a continuable error,
|
|
744 allowing the user (through debug-on-error) to substitute a different
|
|
745 value and return from the signal, which causes the lvalue argument
|
|
746 to get changed. Quite a lot of code would crash if that happened,
|
|
747 because it did things like
|
|
748
|
|
749 foo = XCAR (list);
|
|
750 CHECK_STRING (foo);
|
|
751
|
|
752 and later on did XSTRING (XCAR (list)), assuming that the type
|
|
753 is correct (when it might be wrong, if the user substituted a
|
|
754 correct value in the debugger).
|
|
755
|
|
756 To get around this, I made all the CHECK_foo macros signal a
|
|
757 non-continuable error. Places where a continuable error is OK
|
|
758 (generally only when called directly on the argument of a Lisp
|
|
759 primitive) should be changed to use CONCHECK().
|
|
760
|
|
761 FSF Emacs does not have this problem because RMS took the cheesy
|
|
762 way out and disabled returning from a signal entirely. */
|
|
763
|
|
764 #define CONCHECK_RECORD(x, c_name) do { \
|
442
|
765 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
|
428
|
766 x = wrong_type_argument (Q##c_name##p, x); \
|
|
767 } while (0)
|
|
768 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
|
|
769 if (XTYPE (x) != lisp_enum) \
|
|
770 x = wrong_type_argument (predicate, x); \
|
|
771 } while (0)
|
|
772 #define CHECK_RECORD(x, c_name) do { \
|
442
|
773 if (!RECORD_TYPEP (x, lrecord_type_##c_name)) \
|
428
|
774 dead_wrong_type_argument (Q##c_name##p, x); \
|
|
775 } while (0)
|
|
776 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
|
|
777 if (XTYPE (x) != lisp_enum) \
|
|
778 dead_wrong_type_argument (predicate, x); \
|
|
779 } while (0)
|
|
780
|
665
|
781 void *alloc_lcrecord (Bytecount size,
|
647
|
782 const struct lrecord_implementation *);
|
428
|
783
|
|
784 #define alloc_lcrecord_type(type, lrecord_implementation) \
|
|
785 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
|
|
786
|
|
787 /* Copy the data from one lcrecord structure into another, but don't
|
|
788 overwrite the header information. */
|
|
789
|
|
790 #define copy_lcrecord(dst, src) \
|
430
|
791 memcpy ((char *) (dst) + sizeof (struct lcrecord_header), \
|
|
792 (char *) (src) + sizeof (struct lcrecord_header), \
|
|
793 sizeof (*(dst)) - sizeof (struct lcrecord_header))
|
428
|
794
|
|
795 #define zero_lcrecord(lcr) \
|
430
|
796 memset ((char *) (lcr) + sizeof (struct lcrecord_header), 0, \
|
|
797 sizeof (*(lcr)) - sizeof (struct lcrecord_header))
|
428
|
798
|
440
|
799 #endif /* INCLUDED_lrecord_h_ */
|