annotate src/opaque.c @ 266:18d185df8c54

Added tag r20-5b31 for changeset 8efd647ea9ca
author cvs
date Mon, 13 Aug 2007 10:25:39 +0200
parents 557eaa0339bf
children 966663fcf606
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 mark_opaque (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 static unsigned int sizeof_opaque (CONST void *header);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 static void print_opaque (Lisp_Object obj, Lisp_Object printcharfun,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 int escapeflag);
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
59 static int equal_opaque (Lisp_Object obj1, Lisp_Object obj2, int depth);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
60 static unsigned long hash_opaque (Lisp_Object obj, int depth);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
61
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("opaque", opaque,
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
63 mark_opaque, print_opaque, 0,
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
64 equal_opaque, hash_opaque,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 sizeof_opaque, struct Lisp_Opaque);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 mark_opaque (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 if (!in_opaque_list_marking)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 /* size is non-int for objects on an opaque free list. We sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 as hell better not be marking any of these objects unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 we're marking an opaque list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 assert (INTP (XOPAQUE (obj)->size_or_chain));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 /* marking an opaque on the free list doesn't do any recursive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 markings, so we better not have non-freed opaques on a free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 assert (!INTP (XOPAQUE (obj)->size_or_chain));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 if (INTP (XOPAQUE (obj)->size_or_chain) && XOPAQUE_MARKFUN (obj))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
83 return XOPAQUE_MARKFUN (obj) (obj, markobj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 return XOPAQUE (obj)->size_or_chain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 /* Should never, ever be called. (except by an external debugger) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 print_opaque (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 char buf[200];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 if (INTP (XOPAQUE (obj)->size_or_chain))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
94 sprintf (buf, "#<INTERNAL EMACS BUG (opaque, size=%ld) 0x%p>",
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
95 (long) XOPAQUE_SIZE (obj), (void *) XPNTR (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 else
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
97 sprintf (buf, "#<INTERNAL EMACS BUG (opaque, freed) 0x%p>",
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 0
diff changeset
98 (void *) XPNTR (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 static unsigned int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 sizeof_opaque (CONST void *header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 CONST struct Lisp_Opaque *p = (CONST struct Lisp_Opaque *) header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 if (!INTP (p->size_or_chain))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 return sizeof (*p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 return sizeof (*p) + XINT (p->size_or_chain) - sizeof (int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 make_opaque (int size, CONST void *data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
114 struct Lisp_Opaque *p = (struct Lisp_Opaque *)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
115 alloc_lcrecord (sizeof (*p) + size - sizeof (int), lrecord_opaque);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 p->markfun = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 p->size_or_chain = make_int (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 if (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 memcpy (p->data, data, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 memset (p->data, 0, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 XSETOPAQUE (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
231
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
128 /* This will not work correctly for opaques with subobjects! */
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
129
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
130 static int
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
131 equal_opaque (Lisp_Object obj1, Lisp_Object obj2, int depth)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
132 {
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
133 #ifdef DEBUG_XEMACS
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
134 assert (!XOPAQUE_MARKFUN (obj1) && !XOPAQUE_MARKFUN (obj2));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
135 assert (INTP (XOPAQUE(obj1)->size_or_chain));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
136 assert (INTP (XOPAQUE(obj2)->size_or_chain));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
137 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
138 if (XOPAQUE_SIZE(obj1) != XOPAQUE_SIZE(obj2))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
139 return 0;
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
140 return (XOPAQUE_SIZE(obj1) == sizeof(*XOPAQUE_DATA(obj1))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
141 ? *XOPAQUE_DATA(obj1) == *XOPAQUE_DATA(obj2)
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
142 : memcmp (XOPAQUE_DATA(obj1), XOPAQUE_DATA(obj2),
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
143 XOPAQUE_SIZE(obj1)) == 0);
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
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
152 assert (!XOPAQUE_MARKFUN (obj));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
153 assert (INTP (XOPAQUE(obj)->size_or_chain));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
154 #endif
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
155 if (XOPAQUE_SIZE(obj) == sizeof (unsigned long))
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
156 return (unsigned int) *XOPAQUE_DATA(obj);
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
157 else
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
158 return memory_hash (XOPAQUE_DATA(obj), XOPAQUE_SIZE(obj));
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
159 }
557eaa0339bf Import from CVS: tag r20-5b14
cvs
parents: 185
diff changeset
160
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 static Lisp_Object mark_opaque_list (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 DEFINE_LRECORD_IMPLEMENTATION ("opaque-list", opaque_list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 mark_opaque_list, internal_object_printer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 0, 0, 0, struct Lisp_Opaque_List);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 mark_opaque_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 in_opaque_list_marking++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (markobj) (XOPAQUE_LIST (obj)->free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 in_opaque_list_marking--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 make_opaque_list (int size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Lisp_Object (*markfun) (Lisp_Object obj,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 void (*markobj) (Lisp_Object)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 Lisp_Object val = Qnil;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
181 struct Lisp_Opaque_List *p =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 173
diff changeset
182 alloc_lcrecord_type (struct Lisp_Opaque_List, lrecord_opaque_list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 p->markfun = markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 p->size = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 p->free = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 XSETOPAQUE_LIST (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 allocate_managed_opaque (Lisp_Object opaque_list, CONST void *data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 struct Lisp_Opaque_List *li = XOPAQUE_LIST (opaque_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 if (!NILP (li->free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 val = li->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 li->free = XOPAQUE (val)->size_or_chain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 assert (NILP (li->free) || OPAQUEP (li->free));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 XOPAQUE (val)->size_or_chain = make_int (li->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 if (data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 memcpy (XOPAQUE (val)->data, data, li->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 memset (XOPAQUE (val)->data, 0, li->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 val = make_opaque (li->size, data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 XOPAQUE (val)->markfun = li->markfun;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 free_managed_opaque (Lisp_Object opaque_list, Lisp_Object opaque)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 struct Lisp_Opaque_List *li = XOPAQUE_LIST (opaque_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 assert (INTP (XOPAQUE (opaque)->size_or_chain));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 XOPAQUE (opaque)->size_or_chain = li->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 li->free = 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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 /* stuff to handle opaque pointers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 make_opaque_ptr (CONST void *val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 return allocate_managed_opaque (Vopaque_ptr_free_list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (CONST void *) &val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 /* Be wery wery careful with this. Same admonitions as with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 free_cons() apply. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 free_opaque_ptr (Lisp_Object ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 free_managed_opaque (Vopaque_ptr_free_list, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 make_opaque_long (long val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 return make_opaque (sizeof (val), (void *) &val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 }
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 init_opaque_once_early (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 Vopaque_ptr_free_list = make_opaque_list (sizeof (void *), 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 staticpro (&Vopaque_ptr_free_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 }