annotate src/lrecord.h @ 428:3ecd8885ac67 r21-2-22

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