annotate src/opaque.c @ 369:1d62742628b6 r21-1-14

Import from CVS: tag r21-1-14
author cvs
date Mon, 13 Aug 2007 11:01:51 +0200
parents fbbf69b4e8a7
children cc15677e0335
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 /* Opaque Lisp objects.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1993, 1994, 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995, 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 /* Written by Ben Wing, October 1993. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* "Opaque" is used internally to hold keep track of allocated memory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 so it gets GC'd properly, and to store arbitrary data in places
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 where a Lisp_Object is required and which may get GC'd. (e.g. as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 the argument to record_unwind_protect()). Once created in C,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 opaque objects cannot be resized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 OPAQUE OBJECTS SHOULD NEVER ESCAPE TO THE LISP LEVEL. Some code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 depends on this. As such, opaque objects are a generalization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 of the Qunbound marker.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 "Opaque lists" are used to keep track of lots of opaque objects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 of a particular size so that they can be efficiently "freed" and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 re-used again without actually entering the Lisp allocation system
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (and consequently doing a malloc()).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include "opaque.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 Lisp_Object Qopaquep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 static int in_opaque_list_marking;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 /* Holds freed opaque objects created with make_opaque_ptr().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 We do this quite often so it's a noticeable win if we don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 create GC junk. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 Lisp_Object Vopaque_ptr_free_list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 mark_opaque (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 {
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
58 struct Lisp_Opaque *p = XOPAQUE (obj);
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
59 /* Egcs 1.1.1 sometimes crashes on INTP (p->size_or_chain) */
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
60 Lisp_Object size_or_chain = p->size_or_chain;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 if (!in_opaque_list_marking)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 /* size is non-int for objects on an opaque free list. We sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 as hell better not be marking any of these objects unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 we're marking an opaque list. */
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
66 assert (GC_INTP (size_or_chain));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 /* marking an opaque on the free list doesn't do any recursive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 markings, so we better not have non-freed opaques on a free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 list. */
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
71 assert (!GC_INTP (size_or_chain));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #endif
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
73 if (GC_INTP (size_or_chain) && OPAQUE_MARKFUN (p))
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
74 return OPAQUE_MARKFUN (p) (obj, markobj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 else
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
76 return size_or_chain;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 /* Should never, ever be called. (except by an external debugger) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 print_opaque (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 {
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
83 CONST struct Lisp_Opaque *p = XOPAQUE (obj);
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
84 /* Egcs 1.1.1 sometimes crashes on INTP (p->size_or_chain) */
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
85 Lisp_Object size_or_chain = p->size_or_chain;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 char buf[200];
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
87 if (GC_INTP (size_or_chain))
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 231
diff changeset
88 sprintf (buf, "#<INTERNAL EMACS BUG (opaque, size=%ld) 0x%lx>",
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
89 (long) OPAQUE_SIZE (p), (unsigned long) XPNTR (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 else
267
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 231
diff changeset
91 sprintf (buf, "#<INTERNAL EMACS BUG (opaque, freed) 0x%lx>",
966663fcf606 Import from CVS: tag r20-5b32
cvs
parents: 231
diff changeset
92 (unsigned long) XPNTR (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
96 static size_t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 sizeof_opaque (CONST void *header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 CONST struct Lisp_Opaque *p = (CONST struct Lisp_Opaque *) header;
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
100 /* Egcs 1.1.1 sometimes crashes on INTP (p->size_or_chain) */
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
101 Lisp_Object size_or_chain = p->size_or_chain;
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
102 if (!GC_INTP (size_or_chain))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 return sizeof (*p);
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
104 return sizeof (*p) + XINT (size_or_chain) - sizeof (int);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 make_opaque (int size, CONST void *data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
110 struct Lisp_Opaque *p = (struct Lisp_Opaque *)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
111 alloc_lcrecord (sizeof (*p) + size - sizeof (int), lrecord_opaque);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 p->markfun = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 p->size_or_chain = make_int (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 if (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 memcpy (p->data, data, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 memset (p->data, 0, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 XSETOPAQUE (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
124 /* This will not work correctly for opaques with subobjects! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
125
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
126 static int
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
127 equal_opaque (Lisp_Object obj1, Lisp_Object obj2, int depth)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
128 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
129 #ifdef DEBUG_XEMACS
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
130 {
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
131 /* Egcs 1.1.1 sometimes crashes on INTP (p->size_or_chain) */
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
132 Lisp_Object size_or_chain_1 = XOPAQUE (obj1)->size_or_chain;
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
133 Lisp_Object size_or_chain_2 = XOPAQUE (obj2)->size_or_chain;
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
134 assert (INTP (size_or_chain_1));
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
135 assert (INTP (size_or_chain_2));
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
136 assert (!XOPAQUE_MARKFUN (obj1) && !XOPAQUE_MARKFUN (obj2));
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
137 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
138 #endif
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
139 {
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
140 size_t size;
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
141 return ((size = XOPAQUE_SIZE (obj1)) == XOPAQUE_SIZE (obj2) &&
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
142 !memcmp (XOPAQUE_DATA (obj1), XOPAQUE_DATA (obj2), size));
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
143 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
144 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
145
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
146 /* This will not work correctly for opaques with subobjects! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
147
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
148 static unsigned long
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
149 hash_opaque (Lisp_Object obj, int depth)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
150 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
151 #ifdef DEBUG_XEMACS
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
152 {
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
153 /* Egcs 1.1.1 sometimes crashes on INTP (p->size_or_chain) */
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
154 Lisp_Object size_or_chain = XOPAQUE (obj)->size_or_chain;
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
155 assert (INTP (size_or_chain));
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
156 assert (!XOPAQUE_MARKFUN (obj));
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
157 }
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
158 #endif
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
159 if (XOPAQUE_SIZE (obj) == sizeof (unsigned long))
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
160 return *((unsigned long *) XOPAQUE_DATA (obj));
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
161 else
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
162 return memory_hash (XOPAQUE_DATA (obj), XOPAQUE_SIZE (obj));
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
163 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
164
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
165 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("opaque", opaque,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
166 mark_opaque, print_opaque, 0,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
167 equal_opaque, hash_opaque,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
168 sizeof_opaque, struct Lisp_Opaque);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 mark_opaque_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 in_opaque_list_marking++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (markobj) (XOPAQUE_LIST (obj)->free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 in_opaque_list_marking--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 make_opaque_list (int size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 Lisp_Object (*markfun) (Lisp_Object obj,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 void (*markobj) (Lisp_Object)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
184 Lisp_Object val;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
185 struct Lisp_Opaque_List *p =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
186 alloc_lcrecord_type (struct Lisp_Opaque_List, lrecord_opaque_list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 p->markfun = markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 p->size = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 p->free = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 XSETOPAQUE_LIST (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
195 DEFINE_LRECORD_IMPLEMENTATION ("opaque-list", opaque_list,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
196 mark_opaque_list, internal_object_printer,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
197 0, 0, 0, struct Lisp_Opaque_List);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 267
diff changeset
198
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 allocate_managed_opaque (Lisp_Object opaque_list, CONST void *data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 struct Lisp_Opaque_List *li = XOPAQUE_LIST (opaque_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (!NILP (li->free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 val = li->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 li->free = XOPAQUE (val)->size_or_chain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 assert (NILP (li->free) || OPAQUEP (li->free));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 XOPAQUE (val)->size_or_chain = make_int (li->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 if (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 memcpy (XOPAQUE (val)->data, data, li->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 memset (XOPAQUE (val)->data, 0, li->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 val = make_opaque (li->size, data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 XOPAQUE (val)->markfun = li->markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 free_managed_opaque (Lisp_Object opaque_list, Lisp_Object opaque)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 struct Lisp_Opaque_List *li = XOPAQUE_LIST (opaque_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 #ifdef ERROR_CHECK_GC
337
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
230 {
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
231 /* Egcs 1.1.1 sometimes crashes on INTP (p->size_or_chain) */
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
232 Lisp_Object size_or_chain = XOPAQUE (opaque)->size_or_chain;
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
233 assert (INTP (size_or_chain));
fbbf69b4e8a7 Import from CVS: tag r21-0-66
cvs
parents: 272
diff changeset
234 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 XOPAQUE (opaque)->size_or_chain = li->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 li->free = opaque;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 /* stuff to handle opaque pointers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 make_opaque_ptr (CONST void *val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 return allocate_managed_opaque (Vopaque_ptr_free_list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (CONST void *) &val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 /* Be wery wery careful with this. Same admonitions as with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 free_cons() apply. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 free_opaque_ptr (Lisp_Object ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 free_managed_opaque (Vopaque_ptr_free_list, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 make_opaque_long (long val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 return make_opaque (sizeof (val), (void *) &val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 init_opaque_once_early (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 Vopaque_ptr_free_list = make_opaque_list (sizeof (void *), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 staticpro (&Vopaque_ptr_free_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 }