annotate src/lrecord.h @ 316:512e409c26a2 r21-0b56

Import from CVS: tag r21-0b56
author cvs
date Mon, 13 Aug 2007 10:44:46 +0200
parents c5d627a313b1
children 8626e4521993
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* The "lrecord" structure (header of a compound lisp object).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 #ifndef _XEMACS_LRECORD_H_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 #define _XEMACS_LRECORD_H_
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 /* The "lrecord" type of Lisp object is used for all object types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 other than a few simple ones. This allows many types to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 implemented but only a few bits required in a Lisp object for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 type information. (The tradeoff is that each object has its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 type marked in it, thereby increasing its size.) The first
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
32 four bytes of all lrecords is either a pointer to a struct
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
33 lrecord_implementation, which contains methods describing how
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
34 to process this object, or an index into an array of pointers
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
35 to struct lrecord_implementations plus some other data bits.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
37 Lrecords are of two types: straight lrecords, and lcrecords.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
38 Straight lrecords are used for those types of objects that have
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
39 their own allocation routines (typically allocated out of 2K chunks
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
40 of memory called `frob blocks'). These objects have a `struct
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
41 lrecord_header' at the top, containing only the bits needed to find
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
42 the lrecord_implementation for the object. There are special
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
43 routines in alloc.c to deal with each such object type.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 Lcrecords are used for less common sorts of objects that don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 do their own allocation. Each such object is malloc()ed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 individually, and the objects are chained together through
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 a `next' pointer. Lcrecords have a `struct lcrecord_header'
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
49 at the top, which contains a `struct lrecord_header' and
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 a `next' pointer, and are allocated using alloc_lcrecord().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 Creating a new lcrecord type is fairly easy; just follow the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 lead of some existing type (e.g. hashtables). Note that you
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 do not need to supply all the methods (see below); reasonable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 defaults are provided for many of them. Alternatively, if you're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 just looking for a way of encapsulating data (which possibly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 could contain Lisp_Objects in it), you may well be able to use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 the opaque type. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 struct lrecord_header
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 /* It would be better to put the mark-bit together with the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 following datatype identification field in an 8- or 16-bit
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
64 integer rather than playing funny games with changing
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
65 header->implementation and "wasting" 32 bits on the below
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
66 pointer. The type-id would then be a 7 or 15 bit index into a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
67 table of lrecord-implementations rather than a direct pointer.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
68 There would be 24 (or 16) bits left over for datatype-specific
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
69 per-instance flags.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
70
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
71 The below is the simplest thing to do for the present,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
72 and doesn't incur that much overhead as most Emacs records
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
73 are of such a size that the overhead isn't too bad.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
74 (The marker datatype is the worst case.)
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
75
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
76 It also has the very very very slight advantage that type-checking
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
77 involves one memory read (of the "implementation" slot) and a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 comparison against a link-time constant address rather than a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
79 read and a comparison against a variable value. (Variable since
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
80 it is a very good idea to assign the indices into the hypothetical
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
81 type-code table dynamically rather that pre-defining them.)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
82 I think I remember that Elk Lisp does something like this.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
83 Gee, I wonder if some cretin has patented it? */
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
84
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
85 /*
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
86 * If USE_INDEXED_LRECORD_IMPLEMENTATION is defined, we are
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
87 * implementing the scheme described in the 'It would be better
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
88 * ...' paragraph above.
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
89 */
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
90 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
91 /* index into lrecord_implementations_table[] */
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
92 unsigned type:8;
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
93 /* 1 if the object is marked during GC, 0 otherwise. */
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
94 unsigned mark:1;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
95 /* 1 if the object resides in pure (read-only) space */
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
96 unsigned pure:1;
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
97 #else
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
98 CONST struct lrecord_implementation *implementation;
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
99 #endif
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
100 };
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
101
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 213
diff changeset
102 struct lrecord_implementation;
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 213
diff changeset
103 int lrecord_type_index (CONST struct lrecord_implementation *implementation);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
104
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
105 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
106 # define set_lheader_implementation(header,imp) do \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
107 { \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
108 (header)->type = lrecord_type_index (imp); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
109 (header)->mark = 0; \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
110 (header)->pure = 0; \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
111 } while (0)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
112 #else
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
113 # define set_lheader_implementation(header,imp) \
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
114 ((void) ((header)->implementation = (imp)))
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
115 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 struct lcrecord_header
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
118 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
119 struct lrecord_header lheader;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
120 /* The "next" field is normally used to chain all lrecords together
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
121 so that the GC can find (and free) all of them.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
122 "alloc_lcrecord" threads records together.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
123
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
124 The "next" field may be used for other purposes as long as some
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
125 other mechanism is provided for letting the GC do its work. (For
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
126 example, the event and marker datatypes allocate members out of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
127 memory chunks, and are able to find all unmarked members by
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
128 sweeping through the elements of the list of chunks) */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
129 struct lcrecord_header *next;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
130 /* This is just for debugging/printing convenience.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
131 Having this slot doesn't hurt us much spacewise, since an lcrecord
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
132 already has the above slots together with malloc overhead. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
133 unsigned int uid :31;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
134 /* A flag that indicates whether this lcrecord is on a "free list".
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
135 Free lists are used to minimize the number of calls to malloc()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
136 when we're repeatedly allocating and freeing a number of the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
137 same sort of lcrecord. Lcrecords on a free list always get
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
138 marked in a different fashion, so we can use this flag as a
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
139 sanity check to make sure that free lists only have freed lcrecords
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
140 and there are no freed lcrecords elsewhere. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
141 unsigned int free :1;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
142 };
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 /* Used for lcrecords in an lcrecord-list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 struct free_lcrecord_header
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
146 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
147 struct lcrecord_header lcheader;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
148 Lisp_Object chain;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
149 };
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
151 /* This as the value of lheader->implementation->finalizer
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 * means that this record is already marked */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
153 void this_marks_a_marked_record (void *, int);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 /* see alloc.c for an explanation */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
156 Lisp_Object this_one_is_unmarkable (Lisp_Object obj,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
157 void (*markobj) (Lisp_Object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 struct lrecord_implementation
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
160 {
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
161 CONST char *name;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
162 /* This function is called at GC time, to make sure that all Lisp_Objects
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
163 pointed to by this object get properly marked. It should call
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
164 the mark_object function on all Lisp_Objects in the object. If
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
165 the return value is non-nil, it should be a Lisp_Object to be
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
166 marked (don't call the mark_object function explicitly on it,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
167 because the GC routines will do this). Doing it this way reduces
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
168 recursion, so the object returned should preferably be the one
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
169 with the deepest level of Lisp_Object pointers. This function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
170 can be NULL, meaning no GC marking is necessary. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
171 Lisp_Object (*marker) (Lisp_Object, void (*mark_object) (Lisp_Object));
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
172 /* This can be NULL if the object is an lcrecord; the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
173 default_object_printer() in print.c will be used. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
174 void (*printer) (Lisp_Object, Lisp_Object printcharfun, int escapeflag);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
175 /* This function is called at GC time when the object is about to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
176 be freed, and at dump time (FOR_DISKSAVE will be non-zero in this
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
177 case). It should perform any necessary cleanup (e.g. freeing
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
178 malloc()ed memory. This can be NULL, meaning no special
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
179 finalization is necessary.
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
180
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
181 WARNING: remember that the finalizer is called at dump time even
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
182 though the object is not being freed. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
183 void (*finalizer) (void *header, int for_disksave);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
184 /* This can be NULL, meaning compare objects with EQ(). */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
185 int (*equal) (Lisp_Object obj1, Lisp_Object obj2, int depth);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
186 /* This can be NULL, meaning use the Lisp_Object itself as the hash;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
187 but *only* if the `equal' function is EQ (if two objects are
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
188 `equal', they *must* hash to the same value or the hashing won't
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
189 work). */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
190 unsigned long (*hash) (Lisp_Object, int);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
191 Lisp_Object (*getprop) (Lisp_Object obj, Lisp_Object prop);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
192 int (*putprop) (Lisp_Object obj, Lisp_Object prop, Lisp_Object val);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
193 int (*remprop) (Lisp_Object obj, Lisp_Object prop);
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
194 Lisp_Object (*plist) (Lisp_Object obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
196 /* Only one of these is non-0. If both are 0, it means that this type
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
197 is not instantiable by alloc_lcrecord(). */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
198 size_t static_size;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
199 size_t (*size_in_bytes_method) (CONST void *header);
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
200 /* A unique subtag-code (dynamically) assigned to this datatype. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
201 /* (This is a pointer so the rest of this structure can be read-only.) */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
202 int *lrecord_type_index;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
203 /* A "basic" lrecord is any lrecord that's not an lcrecord, i.e.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
204 one that does not have an lcrecord_header at the front and which
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
205 is (usually) allocated in frob blocks. We only use this flag for
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
206 some consistency checking, and that only when error-checking is
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
207 enabled. */
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
208 int basic_p;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
209 };
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
211 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
212 extern CONST struct lrecord_implementation *lrecord_implementations_table[];
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
213
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
214 # define XRECORD_LHEADER_IMPLEMENTATION(obj) \
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
215 (lrecord_implementations_table[XRECORD_LHEADER (obj)->type])
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
216 # define LHEADER_IMPLEMENTATION(lh) (lrecord_implementations_table[(lh)->type])
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
217 #else
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
218 # define XRECORD_LHEADER_IMPLEMENTATION(obj) \
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
219 (XRECORD_LHEADER (obj)->implementation)
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
220 # define LHEADER_IMPLEMENTATION(lh) ((lh)->implementation)
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
221 #endif
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
222
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 extern int gc_in_progress;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
225 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
226 # define MARKED_RECORD_P(obj) (gc_in_progress && XRECORD_LHEADER (obj)->mark)
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
227 #else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
228 # define MARKED_RECORD_P(obj) (gc_in_progress && \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
229 XRECORD_LHEADER (obj)->implementation->finalizer == \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 this_marks_a_marked_record)
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
231 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
233 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 185
diff changeset
234
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
235 # define MARKED_RECORD_HEADER_P(lheader) (lheader)->mark
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
236 # define MARK_RECORD_HEADER(lheader) (lheader)->mark = 1
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
237 # define UNMARK_RECORD_HEADER(lheader) (lheader)->mark = 0
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
238
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
239 #else /* ! USE_INDEXED_LRECORD_IMPLEMENTATION */
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
240
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
241 # define MARKED_RECORD_HEADER_P(lheader) \
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 185
diff changeset
242 (((lheader)->implementation->finalizer) == this_marks_a_marked_record)
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
243 # define MARK_RECORD_HEADER(lheader) \
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 185
diff changeset
244 do { (((lheader)->implementation)++); } while (0)
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
245 # define UNMARK_RECORD_HEADER(lheader) \
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 185
diff changeset
246 do { (((lheader)->implementation)--); } while (0)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 185
diff changeset
247
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
248 #endif /* ! USE_INDEXED_LRECORD_IMPLEMENTATION */
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
249
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
250 #define UNMARKABLE_RECORD_HEADER_P(lheader) \
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
251 ((LHEADER_IMPLEMENTATION (lheader)->marker) \
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
252 == this_one_is_unmarkable)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 185
diff changeset
253
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 /* Declaring the following structures as const puts them in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 text (read-only) segment, which makes debugging inconvenient
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 because this segment is not mapped when processing a core-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 dump file */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 #ifdef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 #define CONST_IF_NOT_DEBUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 #define CONST_IF_NOT_DEBUG CONST
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 /* DEFINE_LRECORD_IMPLEMENTATION is for objects with constant size.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION is for objects whose size varies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 #if defined (ERROR_CHECK_TYPECHECK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 # define DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,structtype) \
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
276 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,0,0,0,0,structtype)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 #define DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,structtype) \
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
279 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,sizeof(structtype),0,1,structtype)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 #define DEFINE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,structtype) \
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
282 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,0,0,0,0,structtype)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 #define DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,structtype) \
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
285 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,sizeof (structtype),0,0,structtype)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,sizer,structtype) \
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
288 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,0,0,0,0,sizer,structtype)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
289
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
290 #define DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION_WITH_PROPS(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,sizer,structtype) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
291 MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,0,sizer,0,structtype) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
292
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
293 #define MAKE_LRECORD_IMPLEMENTATION(name,c_name,marker,printer,nuker,equal,hash,getprop,putprop,remprop,props,size,sizer,basic_p,structtype) \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 DECLARE_ERROR_CHECK_TYPECHECK(c_name, structtype) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 static int lrecord_##c_name##_lrecord_type_index; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 CONST_IF_NOT_DEBUG struct lrecord_implementation lrecord_##c_name[2] = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 { { name, marker, printer, nuker, equal, hash, \
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
298 getprop, putprop, remprop, props, size, sizer, \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
299 &(lrecord_##c_name##_lrecord_type_index), basic_p }, \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
300 { 0, 0, 0, this_marks_a_marked_record, 0, 0, 0, 0, 0, 0, 0, 0, 0, basic_p } }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
302 #define LRECORDP(a) (XTYPE ((a)) == Lisp_Type_Record)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 #define XRECORD_LHEADER(a) ((struct lrecord_header *) XPNTR (a))
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
304
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
305 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
306 # define RECORD_TYPEP(x, ty) \
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
307 (LRECORDP (x) && \
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
308 lrecord_implementations_table[XRECORD_LHEADER (x)->type] == (ty))
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
309 #else
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
310 # define RECORD_TYPEP(x, ty) \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (LRECORDP (x) && XRECORD_LHEADER (x)->implementation == (ty))
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
312 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 /* NOTE: the DECLARE_LRECORD() must come before the associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 DEFINE_LRECORD_*() or you will get compile errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 Furthermore, you always need to put the DECLARE_LRECORD() in a header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 file, and make sure the header file is included in inline.c, even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 if the type is private to a particular file. Otherwise, you will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 get undefined references for the error_check_foo() inline function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 under GCC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 #ifdef ERROR_CHECK_TYPECHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
325 # define DECLARE_LRECORD(c_name, structtype) \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
326 extern CONST_IF_NOT_DEBUG struct lrecord_implementation \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
327 lrecord_##c_name[]; \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
328 INLINE structtype *error_check_##c_name (Lisp_Object _obj); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
329 INLINE structtype * \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
330 error_check_##c_name (Lisp_Object _obj) \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
331 { \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
332 XUNMARK (_obj); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
333 assert (RECORD_TYPEP (_obj, lrecord_##c_name) || \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
334 MARKED_RECORD_P (_obj)); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
335 return (structtype *) XPNTR (_obj); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
336 } \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 extern Lisp_Object Q##c_name##p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
339 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
340 INLINE structtype *error_check_##c_name (Lisp_Object _obj); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
341 INLINE structtype * \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
342 error_check_##c_name (Lisp_Object _obj) \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
343 { \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
344 XUNMARK (_obj); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
345 assert (XGCTYPE (_obj) == type_enum); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
346 return (structtype *) XPNTR (_obj); \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
347 } \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 extern Lisp_Object Q##c_name##p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 # define XRECORD(x, c_name, structtype) error_check_##c_name (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 # define XNONRECORD(x, c_name, type_enum, structtype) error_check_##c_name (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
353 # define XSETRECORD(var, p, c_name) do \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
354 { \
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
355 XSETOBJ (var, Lisp_Type_Record, p); \
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
356 assert (RECORD_TYPEP (var, lrecord_##c_name) || \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
357 MARKED_RECORD_P (var)); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 #else /* not ERROR_CHECK_TYPECHECK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
362 # define DECLARE_LRECORD(c_name, structtype) \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
363 extern Lisp_Object Q##c_name##p; \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
364 extern CONST_IF_NOT_DEBUG struct lrecord_implementation \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 lrecord_##c_name[]
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
366 # define DECLARE_NONRECORD(c_name, type_enum, structtype) \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 extern Lisp_Object Q##c_name##p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 # define XRECORD(x, c_name, structtype) ((structtype *) XPNTR (x))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
369 # define XNONRECORD(x, c_name, type_enum, structtype) \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ((structtype *) XPNTR (x))
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
371 # define XSETRECORD(var, p, c_name) XSETOBJ (var, Lisp_Type_Record, p)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 #endif /* not ERROR_CHECK_TYPECHECK */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 #define RECORDP(x, c_name) RECORD_TYPEP (x, lrecord_##c_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 #define GC_RECORDP(x, c_name) gc_record_type_p (x, lrecord_##c_name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 /* Note: we now have two different kinds of type-checking macros.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 The "old" kind has now been renamed CONCHECK_foo. The reason for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 this is that the CONCHECK_foo macros signal a continuable error,
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
381 allowing the user (through debug-on-error) to substitute a different
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 value and return from the signal, which causes the lvalue argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 to get changed. Quite a lot of code would crash if that happened,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 because it did things like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 foo = XCAR (list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 CHECK_STRING (foo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 and later on did XSTRING (XCAR (list)), assuming that the type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 is correct (when it might be wrong, if the user substituted a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 correct value in the debugger).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 To get around this, I made all the CHECK_foo macros signal a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 non-continuable error. Places where a continuable error is OK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (generally only when called directly on the argument of a Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 primitive) should be changed to use CONCHECK().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 FSF Emacs does not have this problem because RMS took the cheesy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 way out and disabled returning from a signal entirely. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
401 #define CONCHECK_RECORD(x, c_name) do { \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
402 if (!RECORD_TYPEP (x, lrecord_##c_name)) \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
403 x = wrong_type_argument (Q##c_name##p, x); \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
404 } while (0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
405 #define CONCHECK_NONRECORD(x, lisp_enum, predicate) do {\
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
406 if (XTYPE (x) != lisp_enum) \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
407 x = wrong_type_argument (predicate, x); \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
408 } while (0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
409 #define CHECK_RECORD(x, c_name) do { \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
410 if (!RECORD_TYPEP (x, lrecord_##c_name)) \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
411 dead_wrong_type_argument (Q##c_name##p, x); \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
412 } while (0)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
413 #define CHECK_NONRECORD(x, lisp_enum, predicate) do { \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
414 if (XTYPE (x) != lisp_enum) \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
415 dead_wrong_type_argument (predicate, x); \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
416 } while (0)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 243
diff changeset
418 void *alloc_lcrecord (size_t size, CONST struct lrecord_implementation *);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
420 #define alloc_lcrecord_type(type, lrecord_implementation) \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
421 ((type *) alloc_lcrecord (sizeof (type), lrecord_implementation))
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 2
diff changeset
422
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 int gc_record_type_p (Lisp_Object frob,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 CONST struct lrecord_implementation *type);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 /* Copy the data from one lcrecord structure into another, but don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 overwrite the header information. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
429 #define copy_lcrecord(dst, src) \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
430 memcpy ((char *) dst + sizeof (struct lcrecord_header), \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
431 (char *) src + sizeof (struct lcrecord_header), \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 sizeof (*dst) - sizeof (struct lcrecord_header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
434 #define zero_lcrecord(lcr) \
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
435 memset ((char *) lcr + sizeof (struct lcrecord_header), 0, \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 sizeof (*lcr) - sizeof (struct lcrecord_header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 #endif /* _XEMACS_LRECORD_H_ */