annotate src/alloc.c @ 321:19dcec799385 r21-0-58

Import from CVS: tag r21-0-58
author cvs
date Mon, 13 Aug 2007 10:46:44 +0200
parents c9fe270a4101
children fbbf69b4e8a7
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 /* Storage allocation and gc for XEmacs Lisp interpreter.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2 Copyright (C) 1985-1998 Free Software Foundation, Inc.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 /* Authorship:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 FSF: Original version; a long time ago.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 Mly: Significantly rewritten to use new 3-bit tags and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 nicely abstracted object definitions, for 19.8.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 JWZ: Improved code to keep track of purespace usage and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 issue nice purespace and GC stats.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 Ben Wing: Cleaned up frob-block lrecord code, added error-checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 and various changes for Mule, for 19.12.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 Added bit vectors for 19.13.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Added lcrecord lists for 19.14.
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
37 slb: Lots of work on the purification and dump time code.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
38 Synched Doug Lea malloc support from Emacs 20.2.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 #include "backtrace.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 #include "buffer.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 #include "bytecode.h"
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
47 #include "chartab.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #include "device.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include "elhash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include "extents.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include "glyphs.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include "redisplay.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #include "specifier.h"
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
56 #include "sysfile.h"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
321
19dcec799385 Import from CVS: tag r21-0-58
cvs
parents: 290
diff changeset
59 #include <stddef.h>
19dcec799385 Import from CVS: tag r21-0-58
cvs
parents: 290
diff changeset
60
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
61 #ifdef DOUG_LEA_MALLOC
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
62 #include <malloc.h>
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
63 #endif
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
64
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
65 EXFUN (Fgarbage_collect, 0);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
66
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 /* #define GDB_SUCKS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
69 #if 0 /* this is _way_ too slow to be part of the standard debug options */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
70 #if defined(DEBUG_XEMACS) && defined(MULE)
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
71 #define VERIFY_STRING_CHARS_INTEGRITY
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
72 #endif
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
73 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 /* Define this to see where all that space is going... */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
76 /* But the length of the printout is obnoxious, so limit it to testers */
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
77 /* If somebody wants to see this they can ask for it.
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
78 #ifdef DEBUG_XEMACS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 #define PURESTAT
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
80 #endif
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
81 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 /* Define this to use malloc/free with no freelist for all datatypes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 the hope being that some debugging tools may help detect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 freed memory references */
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
86 #ifdef USE_DEBUG_MALLOC /* Taking the above comment at face value -slb */
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
87 #include <dmalloc.h>
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
88 #define ALLOC_NO_POOLS
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
89 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 #include "puresize.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 #ifdef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 int debug_allocation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 int debug_allocation_backtrace_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 /* Number of bytes of consing done since the last gc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 EMACS_INT consing_since_gc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 extern void cadillac_record_backtrace ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 #define INCREMENT_CONS_COUNTER_1(size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 consing_since_gc += __sz__; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 cadillac_record_backtrace (2, __sz__); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 #define INCREMENT_CONS_COUNTER_1(size) (consing_since_gc += (size))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
111 #endif /* EMACS_BTL */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 #define debug_allocation_backtrace() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 if (debug_allocation_backtrace_length > 0) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 debug_short_backtrace (debug_allocation_backtrace_length); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 #ifdef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 #define INCREMENT_CONS_COUNTER(foosize, type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 if (debug_allocation) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 stderr_out ("allocating %s (size %ld)\n", type, (long)foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 debug_allocation_backtrace (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 INCREMENT_CONS_COUNTER_1 (foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 if (debug_allocation > 1) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 stderr_out ("allocating noseeum %s (size %ld)\n", type, (long)foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 debug_allocation_backtrace (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 INCREMENT_CONS_COUNTER_1 (foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 #define INCREMENT_CONS_COUNTER(size, type) INCREMENT_CONS_COUNTER_1 (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 #define NOSEEUM_INCREMENT_CONS_COUNTER(size, type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 INCREMENT_CONS_COUNTER_1 (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 #define DECREMENT_CONS_COUNTER(size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 if (consing_since_gc >= __sz__) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 consing_since_gc -= __sz__; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 consing_since_gc = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 /* Number of bytes of consing since gc before another gc should be done. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 EMACS_INT gc_cons_threshold;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 /* Nonzero during gc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 int gc_in_progress;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /* Number of times GC has happened at this level or below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 * Level 0 is most volatile, contrary to usual convention.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 * (Of course, there's only one level at present) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 EMACS_INT gc_generation_number[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 /* This is just for use by the printer, to allow things to print uniquely */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 static int lrecord_uid_counter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 /* Nonzero when calling certain hooks or doing other things where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 a GC would be bad */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 int gc_currently_forbidden;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 /* Hooks. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 Lisp_Object Vpre_gc_hook, Qpre_gc_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 Lisp_Object Vpost_gc_hook, Qpost_gc_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 /* "Garbage collecting" */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 Lisp_Object Vgc_message;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 Lisp_Object Vgc_pointer_glyph;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 static CONST char gc_default_message[] = "Garbage collecting";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 Lisp_Object Qgarbage_collecting;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 #ifndef VIRT_ADDR_VARIES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 extern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 #endif /* VIRT_ADDR_VARIES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 EMACS_INT malloc_sbrk_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 #ifndef VIRT_ADDR_VARIES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 extern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 #endif /* VIRT_ADDR_VARIES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 EMACS_INT malloc_sbrk_unused;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 /* Non-zero means defun should do purecopy on the function definition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 int purify_flag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
194 #ifdef HEAP_IN_DATA
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
195 extern void sheap_adjust_h();
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
196 #endif
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
197
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
198 #define PUREBEG ((char *) pure)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
200 #if 0 /* This is breathing_space in XEmacs */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
201 /* Points to memory space allocated as "spare",
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
202 to be freed if we run out of memory. */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
203 static char *spare_memory;
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
204
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
205 /* Amount of spare memory to keep in reserve. */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
206 #define SPARE_MEMORY (1 << 14)
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
207 #endif
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
208
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 /* Index in pure at which next pure object will be allocated. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
210 static size_t pure_bytes_used;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
211
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
212 #define PURIFIED(ptr) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
213 ((char *) (ptr) >= PUREBEG && \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
214 (char *) (ptr) < PUREBEG + get_PURESIZE())
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
215
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
216 /* Non-zero if pure_bytes_used > get_PURESIZE(); accounts for excess purespace needs. */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
217 static size_t pure_lossage;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 #ifdef ERROR_CHECK_TYPECHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 Error_behavior ERROR_ME, ERROR_ME_NOT, ERROR_ME_WARN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 purified (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
228 return POINTER_TYPE_P (XGCTYPE (obj)) && PURIFIED (XPNTR (obj));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
231 size_t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 purespace_usage (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
234 return pure_bytes_used;
0
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 static int
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
238 check_purespace (size_t size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 if (pure_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 pure_lossage += size;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
243 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
245 else if (pure_bytes_used + size > get_PURESIZE())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 {
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
247 /* This can cause recursive bad behavior, we'll yell at the end */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
248 /* when we're done. */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
249 /* message ("\nERROR: Pure Lisp storage exhausted!\n"); */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 pure_lossage = size;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
251 return 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 else
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
254 return 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 }
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 #ifndef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
261 #define bump_purestat(p,b) DO_NOTHING
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 #else /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 static int purecopying_for_bytecode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
267 static size_t pure_sizeof (Lisp_Object /*, int recurse */);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 /* Keep statistics on how much of what is in purespace */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
270 static struct purestat
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 int nobjects;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 int nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 CONST char *name;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
275 }
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
276 purestat_cons = {0, 0, "cons cells"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
277 purestat_float = {0, 0, "float objects"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
278 purestat_string_pname = {0, 0, "symbol-name strings"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
279 purestat_bytecode = {0, 0, "compiled-function objects"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
280 purestat_string_bytecodes = {0, 0, "byte-code strings"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
281 purestat_vector_bytecode_constants = {0, 0, "byte-constant vectors"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
282 purestat_string_interactive = {0, 0, "interactive strings"},
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 #ifdef I18N3
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
284 purestat_string_domain = {0, 0, "domain strings"},
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 #endif
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
286 purestat_string_documentation = {0, 0, "documentation strings"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
287 purestat_string_other_function = {0, 0, "other function strings"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
288 purestat_vector_other = {0, 0, "other vectors"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
289 purestat_string_other = {0, 0, "other strings"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
290 purestat_string_all = {0, 0, "all strings"},
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
291 purestat_vector_all = {0, 0, "all vectors"};
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 static struct purestat *purestats[] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 &purestat_cons,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 &purestat_float,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 &purestat_string_pname,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 &purestat_bytecode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 &purestat_string_bytecodes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 &purestat_vector_bytecode_constants,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 &purestat_string_interactive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 &purestat_string_domain,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 &purestat_string_documentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 &purestat_string_other_function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 &purestat_vector_other,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 &purestat_string_other,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 &purestat_string_all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 &purestat_vector_all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 static void
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
315 bump_purestat (struct purestat *purestat, size_t nbytes)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 if (pure_lossage) return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 purestat->nobjects += 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 purestat->nbytes += nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 /* Maximum amount of C stack to save when a GC happens. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 #ifndef MAX_SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 #define MAX_SAVE_STACK 16000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 /* Non-zero means ignore malloc warnings. Set during initialization. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 int ignore_malloc_warnings;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 static void *breathing_space;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 release_breathing_space (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
339 if (breathing_space)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 void *tmp = breathing_space;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 breathing_space = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 xfree (tmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 /* malloc calls this if it finds we are near exhausting storage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 malloc_warning (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 if (ignore_malloc_warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 warn_when_safe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (Qmemory, Qcritical,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 "%s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 "Killing some buffers may delay running out of memory.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 "However, certainly by the time you receive the 95%% warning,\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 "you should clean up, kill this Emacs, and start a new one.",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 /* Called if malloc returns zero */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 DOESNT_RETURN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 memory_full (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 /* Force a GC next time eval is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 It's better to loop garbage-collecting (we might reclaim enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 to win) than to loop beeping and barfing "Memory exhausted"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 consing_since_gc = gc_cons_threshold + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 release_breathing_space ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
374 /* Flush some histories which might conceivably contain garbalogical
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
375 inhibitors. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 if (!NILP (Fboundp (Qvalues)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 Fset (Qvalues, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 Vcommand_history = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 error ("Memory exhausted");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 /* like malloc and realloc but check for no memory left, and block input. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
385 #ifdef xmalloc
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
386 #undef xmalloc
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
387 #endif
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
388
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 void *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
390 xmalloc (size_t size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
392 void *val = (void *) malloc (size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 if (!val && (size != 0)) memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 void *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
399 xmalloc_and_zero (size_t size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 void *val = xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 memset (val, 0, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
406 #ifdef xrealloc
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
407 #undef xrealloc
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
408 #endif
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
409
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 void *
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
411 xrealloc (void *block, size_t size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 /* We must call malloc explicitly when BLOCK is 0, since some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 reallocs don't do this. */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
415 void *val = (void *) (block ? realloc (block, size) : malloc (size));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 if (!val && (size != 0)) memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 #ifdef ERROR_CHECK_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 xfree_1 (void *block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 xfree (void *block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 #ifdef ERROR_CHECK_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 error until much later on for many system mallocs, such as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 the one that comes with Solaris 2.3. FMH!! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 assert (block != (void *) 0xDEADBEEF);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 assert (block);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
434 #endif /* ERROR_CHECK_MALLOC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 free (block);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
438 #ifdef ERROR_CHECK_GC
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
439
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
440 #if SIZEOF_INT == 4
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
441 typedef unsigned int four_byte_t;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
442 #elif SIZEOF_LONG == 4
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
443 typedef unsigned long four_byte_t;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
444 #elif SIZEOF_SHORT == 4
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
445 typedef unsigned short four_byte_t;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 What kind of strange-ass system are we running on?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 static void
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
451 deadbeef_memory (void *ptr, size_t size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
453 four_byte_t *ptr4 = (four_byte_t *) ptr;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
454 size_t beefs = size >> 2;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
455
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
456 /* In practice, size will always be a multiple of four. */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
457 while (beefs--)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
458 (*ptr4++) = 0xDEADBEEF;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
461 #else /* !ERROR_CHECK_GC */
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
462
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 #define deadbeef_memory(ptr, size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
466 #endif /* !ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
468 #ifdef xstrdup
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
469 #undef xstrdup
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
470 #endif
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
471
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 xstrdup (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 int len = strlen (str) + 1; /* for stupid terminating 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
477 void *val = xmalloc (len);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 if (val == 0) return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 memcpy (val, str, len);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
480 return (char *) val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 #ifdef NEED_STRDUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 strdup (CONST char *s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 return xstrdup (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 #endif /* NEED_STRDUP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 static void *
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
493 allocate_lisp_storage (size_t size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 void *p = xmalloc (size);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
496 #ifndef USE_MINIMAL_TAGBITS
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 char *lim = ((char *) p) + size;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
498 Lisp_Object val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
500 XSETOBJ (val, Lisp_Type_Record, lim);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
501 if ((char *) XPNTR (val) != lim)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 xfree (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
506 #endif /* ! USE_MINIMAL_TAGBITS */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
507 return p;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 /* lrecords are chained together through their "next.v" field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 * After doing the mark phase, the GC will walk this linked
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
513 * list and free any record which hasn't been marked.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 static struct lcrecord_header *all_lcrecords;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 void *
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
518 alloc_lcrecord (size_t size, CONST struct lrecord_implementation *implementation)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 struct lcrecord_header *lcheader;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 if (size <= 0) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 if (implementation->static_size == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 if (!implementation->size_in_bytes_method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 else if (implementation->static_size != size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
531 lcheader = (struct lcrecord_header *) allocate_lisp_storage (size);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
532 set_lheader_implementation(&(lcheader->lheader), implementation);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 lcheader->next = all_lcrecords;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 #if 1 /* mly prefers to see small ID numbers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 lcheader->uid = lrecord_uid_counter++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 #else /* jwz prefers to see real addrs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 lcheader->uid = (int) &lcheader;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 lcheader->free = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 all_lcrecords = lcheader;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 INCREMENT_CONS_COUNTER (size, implementation->name);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
542 return lcheader;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 #if 0 /* Presently unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 /* Very, very poor man's EGC?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 * This may be slow and thrash pages all over the place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 * Only call it if you really feel you must (and if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 * lrecord was fairly recently allocated).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 * Otherwise, just let the GC do its job -- that's what it's there for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 free_lcrecord (struct lcrecord_header *lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 if (all_lcrecords == lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 all_lcrecords = lcrecord->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 struct lrecord_header *header = all_lcrecords;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 for (;;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 struct lrecord_header *next = header->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 if (next == lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 header->next = lrecord->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 else if (next == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 header = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 if (lrecord->implementation->finalizer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ((lrecord->implementation->finalizer) (lrecord, 0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 xfree (lrecord);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 #endif /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 disksave_object_finalization_1 (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 struct lcrecord_header *header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 for (header = all_lcrecords; header; header = header->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 {
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
591 if (LHEADER_IMPLEMENTATION(&header->lheader)->finalizer &&
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
592 !header->free)
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
593 ((LHEADER_IMPLEMENTATION(&header->lheader)->finalizer)
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
594 (header, 1));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
597
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 /* This must not be called -- it just serves as for EQ test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 * If lheader->implementation->finalizer is this_marks_a_marked_record,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 * then lrecord has been marked by the GC sweeper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 * header->implementation is put back to its correct value by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 * sweep_records */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 this_marks_a_marked_record (void *dummy0, int dummy1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 /* Semi-kludge -- lrecord_symbol_value_forward objects get stuck
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 in CONST space and you get SEGV's if you attempt to mark them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 This sits in lheader->implementation->marker. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 this_one_is_unmarkable (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 /* XGCTYPE for records */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 gc_record_type_p (Lisp_Object frob, CONST struct lrecord_implementation *type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
625 CONST struct lrecord_implementation *imp;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
626
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
627 if (XGCTYPE (frob) != Lisp_Type_Record)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
628 return 0;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
629
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
630 imp = XRECORD_LHEADER_IMPLEMENTATION (frob);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
631 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
632 return imp == type;
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
633 #else
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
634 return imp == type || imp == type + 1;
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
635 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 /**********************************************************************/
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
640 /* Debugger support */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
641 /**********************************************************************/
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
642 /* Give gdb/dbx enough information to decode Lisp Objects.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
643 We make sure certain symbols are defined, so gdb doesn't complain
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
644 about expressions in src/gdbinit. Values are randomly chosen.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
645 See src/gdbinit or src/dbxrc to see how this is used. */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
646
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
647 enum dbg_constants
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
648 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
649 #ifdef USE_MINIMAL_TAGBITS
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
650 dbg_valmask = (EMACS_INT) (((1UL << VALBITS) - 1) << GCBITS),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
651 dbg_typemask = (EMACS_INT) ((1UL << GCTYPEBITS) - 1),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
652 dbg_USE_MINIMAL_TAGBITS = 1,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
653 dbg_Lisp_Type_Int = 100,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
654 #else /* ! USE_MIMIMAL_TAGBITS */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
655 dbg_valmask = (EMACS_INT) ((1UL << VALBITS) - 1),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
656 dbg_typemask = (EMACS_INT) (((1UL << GCTYPEBITS) - 1) << (VALBITS + GCMARKBITS)),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
657 dbg_USE_MINIMAL_TAGBITS = 0,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
658 dbg_Lisp_Type_Int = Lisp_Type_Int,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
659 #endif /* ! USE_MIMIMAL_TAGBITS */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
660 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
661 dbg_USE_INDEXED_LRECORD_IMPLEMENTATION = 1,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
662 #else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
663 dbg_USE_INDEXED_LRECORD_IMPLEMENTATION = 0,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
664 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
665 dbg_Lisp_Type_Char = Lisp_Type_Char,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
666 dbg_Lisp_Type_Record = Lisp_Type_Record,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
667 #ifdef LRECORD_CONS
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
668 dbg_Lisp_Type_Cons = 101,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
669 #else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
670 dbg_Lisp_Type_Cons = Lisp_Type_Cons,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
671 lrecord_cons = 201,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
672 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
673 #ifdef LRECORD_STRING
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
674 dbg_Lisp_Type_String = 102,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
675 #else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
676 dbg_Lisp_Type_String = Lisp_Type_String,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
677 lrecord_string = 202,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
678 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
679 #ifdef LRECORD_VECTOR
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
680 dbg_Lisp_Type_Vector = 103,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
681 #else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
682 dbg_Lisp_Type_Vector = Lisp_Type_Vector,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
683 lrecord_vector = 203,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
684 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
685 #ifdef LRECORD_SYMBOL
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
686 dbg_Lisp_Type_Symbol = 104,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
687 #else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
688 dbg_Lisp_Type_Symbol = Lisp_Type_Symbol,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
689 lrecord_symbol = 204,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
690 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
691 #ifndef MULE
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
692 lrecord_char_table_entry = 205,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
693 lrecord_charset = 206,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
694 lrecord_coding_system = 207,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
695 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
696 #ifndef HAVE_TOOLBARS
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
697 lrecord_toolbar_button = 208,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
698 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
699 #ifndef HAVE_TOOLTALK
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
700 lrecord_tooltalk_message = 210,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
701 lrecord_tooltalk_pattern = 211,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
702 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
703 #ifndef HAVE_DATABASE
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
704 lrecord_database = 212,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
705 #endif
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
706 dbg_valbits = VALBITS,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
707 dbg_gctypebits = GCTYPEBITS
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
708 /* If we don't have an actual object of this enum, pgcc (and perhaps
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
709 other compilers) might optimize away the entire type declaration :-( */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
710 } dbg_dummy;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
711
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
712
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
713 /**********************************************************************/
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 /* Fixed-size type macros */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 /* For fixed-size types that are commonly used, we malloc() large blocks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 of memory at a time and subdivide them into chunks of the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 size for an object of that type. This is more efficient than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 malloc()ing each object separately because we save on malloc() time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 and overhead due to the fewer number of malloc()ed blocks, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 also because we don't need any extra pointers within each object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 to keep them threaded together for GC purposes. For less common
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (and frequently large-size) types, we use lcrecords, which are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 malloc()ed individually and chained together through a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 in the lcrecord header. lcrecords do not need to be fixed-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (i.e. two objects of the same type need not have the same size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 however, the size of a particular object cannot vary dynamically).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 It is also much easier to create a new lcrecord type because no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 additional code needs to be added to alloc.c. Finally, lcrecords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 may be more efficient when there are only a small number of them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 The types that are stored in these large blocks (or "frob blocks")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 are cons, float, compiled-function, symbol, marker, extent, event,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 and string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 Note that strings are special in that they are actually stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 two parts: a structure containing information about the string, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 the actual data associated with the string. The former structure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (a struct Lisp_String) is a fixed-size structure and is managed the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 same way as all the other such types. This structure contains a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 pointer to the actual string data, which is stored in structures of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 type struct string_chars_block. Each string_chars_block consists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 of a pointer to a struct Lisp_String, followed by the data for that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 string, followed by another pointer to a struct Lisp_String,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 followed by the data for that string, etc. At GC time, the data in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 these blocks is compacted by searching sequentially through all the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 blocks and compressing out any holes created by unmarked strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 Strings that are more than a certain size (bigger than the size of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 a string_chars_block, although something like half as big might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 make more sense) are malloc()ed separately and not stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 string_chars_blocks. Furthermore, no one string stretches across
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 two string_chars_blocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 Vectors are each malloc()ed separately, similar to lcrecords.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
756
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 In the following discussion, we use conses, but it applies equally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 well to the other fixed-size types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 We store cons cells inside of cons_blocks, allocating a new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 cons_block with malloc() whenever necessary. Cons cells reclaimed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 by GC are put on a free list to be reallocated before allocating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 any new cons cells from the latest cons_block. Each cons_block is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 the versions in malloc.c and gmalloc.c) really allocates in units
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 of powers of two and uses 4 bytes for its own overhead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 What GC actually does is to search through all the cons_blocks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 from the most recently allocated to the oldest, and put all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 cons cells that are not marked (whether or not they're already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 free) on a cons_free_list. The cons_free_list is a stack, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 so the cons cells in the oldest-allocated cons_block end up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 at the head of the stack and are the first to be reallocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 If any cons_block is entirely free, it is freed with free()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 and its cons cells removed from the cons_free_list. Because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 the cons_free_list ends up basically in memory order, we have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 a high locality of reference (assuming a reasonable turnover
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 of allocating and freeing) and have a reasonable probability
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 of entirely freeing up cons_blocks that have been more recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 allocated. This stage is called the "sweep stage" of GC, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 is executed after the "mark stage", which involves starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 from all places that are known to point to in-use Lisp objects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (e.g. the obarray, where are all symbols are stored; the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 current catches and condition-cases; the backtrace list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 currently executing functions; the gcpro list; etc.) and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 recursively marking all objects that are accessible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 At the beginning of the sweep stage, the conses in the cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 blocks are in one of three states: in use and marked, in use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 but not marked, and not in use (already freed). Any conses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 that are marked have been marked in the mark stage just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 executed, because as part of the sweep stage we unmark any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 marked objects. The way we tell whether or not a cons cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 is in use is through the FREE_STRUCT_P macro. This basically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 looks at the first 4 bytes (or however many bytes a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 fits in) to see if all the bits in those bytes are 1. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 resulting value (0xFFFFFFFF) is not a valid pointer and is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 not a valid Lisp_Object. All current fixed-size types have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 a pointer or Lisp_Object as their first element with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 exception of strings; they have a size value, which can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 never be less than zero, and so 0xFFFFFFFF is invalid for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 strings as well. Now assuming that a cons cell is in use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 the way we tell whether or not it is marked is to look at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 the mark bit of its car (each Lisp_Object has one bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 reserved as a mark bit, in case it's needed). Note that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 different types of objects use different fields to indicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 whether the object is marked, but the principle is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 Conses on the free_cons_list are threaded through a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 stored in the bytes directly after the bytes that are set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 to 0xFFFFFFFF (we cannot overwrite these because the cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 is still in a cons_block and needs to remain marked as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 not in use for the next time that GC happens). This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 implies that all fixed-size types must be at least big
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 enough to store two pointers, which is indeed the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 for all current fixed-size types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 Some types of objects need additional "finalization" done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 when an object is converted from in use to not in use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 this is the purpose of the ADDITIONAL_FREE_type macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 For example, markers need to be removed from the chain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 of markers that is kept in each buffer. This is because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 markers in a buffer automatically disappear if the marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 is no longer referenced anywhere (the same does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 apply to extents, however).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 WARNING: Things are in an extremely bizarre state when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 the ADDITIONAL_FREE_type macros are called, so beware!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 When ERROR_CHECK_GC is defined, we do things differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 so as to maximize our chances of catching places where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 there is insufficient GCPROing. The thing we want to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 avoid is having an object that we're using but didn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 GCPRO get freed by GC and then reallocated while we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 in the process of using it -- this will result in something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 seemingly unrelated getting trashed, and is extremely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 difficult to track down. If the object gets freed but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 not reallocated, we can usually catch this because we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 set all bytes of a freed object to 0xDEADBEEF. (The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 first four bytes, however, are 0xFFFFFFFF, and the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 four are a pointer used to chain freed objects together;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 we play some tricks with this pointer to make it more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 bogus, so crashes are more likely to occur right away.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 We want freed objects to stay free as long as possible,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 so instead of doing what we do above, we maintain the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 free objects in a first-in first-out queue. We also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 don't recompute the free list each GC, unlike above;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 this ensures that the queue ordering is preserved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 [This means that we are likely to have worse locality
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 of reference, and that we can never free a frob block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 once it's allocated. (Even if we know that all cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 in it are free, there's no easy way to remove all those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 cells from the free list because the objects on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 free list are unlikely to be in memory order.)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 Furthermore, we never take objects off the free list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 unless there's a large number (usually 1000, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 varies depending on type) of them already on the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 This way, we ensure that an object that gets freed will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 remain free for the next 1000 (or whatever) times that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 an object of that type is allocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 #ifndef MALLOC_OVERHEAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 #ifdef GNU_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 #define MALLOC_OVERHEAD 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 #elif defined (rcheck)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 #define MALLOC_OVERHEAD 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 #define MALLOC_OVERHEAD 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 #endif
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
872 #endif /* MALLOC_OVERHEAD */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
874 #if !defined(HAVE_MMAP) || defined(DOUG_LEA_MALLOC)
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
875 /* If we released our reserve (due to running out of memory),
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
876 and we have a fair amount free once again,
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
877 try to set aside another reserve in case we run out once more.
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
878
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
879 This is called when a relocatable block is freed in ralloc.c. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
880 void refill_memory_reserve (void);
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
881 void
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
882 refill_memory_reserve ()
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
883 {
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
884 if (breathing_space == 0)
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
885 breathing_space = (char *) malloc (4096 - MALLOC_OVERHEAD);
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
886 }
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
887 #endif
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
888
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 #ifdef ALLOC_NO_POOLS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 # define TYPE_ALLOC_SIZE(type, structtype) 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 # define TYPE_ALLOC_SIZE(type, structtype) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 / sizeof (structtype))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
895 #endif /* ALLOC_NO_POOLS */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 struct type##_block \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 struct type##_block *prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 }; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 static struct type##_block *current_##type##_block; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 static int current_##type##_block_index; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 static structtype *type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 static structtype *type##_free_list_tail; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 static void \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 init_##type##_alloc (void) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 current_##type##_block = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 current_##type##_block_index = countof (current_##type##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 type##_free_list = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 type##_free_list_tail = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 static int gc_count_num_##type##_in_use, gc_count_num_##type##_freelist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 if (current_##type##_block_index \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 == countof (current_##type##_block->block)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 { \
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
927 struct type##_block *__new__ = (struct type##_block *) \
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
928 allocate_lisp_storage (sizeof (struct type##_block)); \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 __new__->prev = current_##type##_block; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 current_##type##_block = __new__; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 current_##type##_block_index = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (result) = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 &(current_##type##_block->block[current_##type##_block_index++]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 /* Allocate an instance of a type that is stored in blocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 TYPE is the "name" of the type, STRUCTTYPE is the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 structure type. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 /* Note: if you get crashes in this function, suspect incorrect calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 to free_cons() and friends. This happened once because the cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 cell was not GC-protected and was getting collected before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 free_cons() was called. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 if (gc_count_num_##type##_freelist > \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 result = type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 /* Before actually using the chain pointer, we complement all its \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 bits; see FREE_FIXED_TYPE(). */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 type##_free_list = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (structtype *) ~(unsigned long) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (* (structtype **) ((char *) result + sizeof (void *))); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 gc_count_num_##type##_freelist--; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 MARK_STRUCT_AS_NOT_FREE (result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
967 #else /* !ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 if (type##_free_list) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 result = type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 type##_free_list = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 * (structtype **) ((char *) result + sizeof (void *)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 MARK_STRUCT_AS_NOT_FREE (result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
983 #endif /* !ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 /* INVALID_POINTER_VALUE should be a value that is invalid as a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 to a Lisp object and invalid as an actual Lisp_Object value. We have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 to make sure that this value cannot be an integer in Lisp_Object form.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 0xFFFFFFFF could be so on a 64-bit system, so we extend it to 64 bits.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 On a 32-bit system, the type bits will be non-zero, making the value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 be a pointer, and the pointer will be misaligned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 Even if Emacs is run on some weirdo system that allows and allocates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 byte-aligned pointers, this pointer is at the very top of the address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 space and so it's almost inconceivable that it could ever be valid. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1009
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 #if INTBITS == 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 # define INVALID_POINTER_VALUE 0xFFFFFFFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 #elif INTBITS == 48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 #elif INTBITS == 64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFFFFFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 You have some weird system and need to supply a reasonable value here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 #define FREE_STRUCT_P(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (* (void **) ptr == (void *) INVALID_POINTER_VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 #define MARK_STRUCT_AS_FREE(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (* (void **) ptr = (void *) INVALID_POINTER_VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 #define MARK_STRUCT_AS_NOT_FREE(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (* (void **) ptr = 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 do { if (type##_free_list_tail) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 /* When we store the chain pointer, we complement all \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 its bits; this should significantly increase its \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 bogosity in case someone tries to use the value, and \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 should make us dump faster if someone stores something \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 over the pointer because when it gets un-complemented in \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 extremely bogus. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 * (structtype **) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ((char *) type##_free_list_tail + sizeof (void *)) = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (structtype *) ~(unsigned long) ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 type##_free_list = ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 type##_free_list_tail = ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1048 #else /* !ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 do { * (structtype **) ((char *) ptr + sizeof (void *)) = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 type##_free_list = ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1056 #endif /* !ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 #define FREE_FIXED_TYPE(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 do { structtype *_weird_ = (ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 ADDITIONAL_FREE_##type (_weird_); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 deadbeef_memory (ptr, sizeof (structtype)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 MARK_STRUCT_AS_FREE (_weird_); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 /* Like FREE_FIXED_TYPE() but used when we are explicitly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 freeing a structure through free_cons(), free_marker(), etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 rather than through the normal process of sweeping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 We attempt to undo the changes made to the allocation counters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 as a result of this structure being allocated. This is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 completely necessary but helps keep things saner: e.g. this way,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 repeatedly allocating and freeing a cons will not result in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 the consing-since-gc counter advancing, which would cause a GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 and somewhat defeat the purpose of explicitly freeing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 do { FREE_FIXED_TYPE (type, structtype, ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 DECREMENT_CONS_COUNTER (sizeof (structtype)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 gc_count_num_##type##_freelist++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 } while (0)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1083
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 /* Cons allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 DECLARE_FIXED_TYPE_ALLOC (cons, struct Lisp_Cons);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 /* conses are used and freed so often that we set this really high */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1095 #ifdef LRECORD_CONS
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1096 static Lisp_Object
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1097 mark_cons (Lisp_Object obj, void (*markobj) (Lisp_Object))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1098 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1099 if (NILP (XCDR (obj)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1100 return XCAR (obj);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1101
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1102 (markobj) (XCAR (obj));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1103 return XCDR (obj);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1104 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1105
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1106 static int
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1107 cons_equal (Lisp_Object ob1, Lisp_Object ob2, int depth)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1108 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1109 while (internal_equal (XCAR (ob1), XCAR (ob2), depth + 1))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1110 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1111 ob1 = XCDR (ob1);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1112 ob2 = XCDR (ob2);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1113 if (! CONSP (ob1) || ! CONSP (ob2))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1114 return internal_equal (ob1, ob2, depth + 1);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1115 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1116 return 0;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1117 }
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1118
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1119 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("cons", cons,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1120 mark_cons, print_cons, 0,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1121 cons_equal,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1122 /*
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1123 * No `hash' method needed.
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1124 * internal_hash knows how to
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1125 * handle conses.
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1126 */
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1127 0,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1128 struct Lisp_Cons);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1129 #endif /* LRECORD_CONS */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1130
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1131 DEFUN ("cons", Fcons, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 Create a new cons, give it CAR and CDR as components, and return it.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1133 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1134 (car, cdr))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 /* This cannot GC. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1137 Lisp_Object val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 struct Lisp_Cons *c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1141 #ifdef LRECORD_CONS
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1142 set_lheader_implementation (&(c->lheader), lrecord_cons);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1143 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 XSETCONS (val, c);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1145 c->car = car;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1146 c->cdr = cdr;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 /* This is identical to Fcons() but it used for conses that we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 going to free later, and is useful when trying to track down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 "real" consing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 noseeum_cons (Lisp_Object car, Lisp_Object cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1156 Lisp_Object val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 struct Lisp_Cons *c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 NOSEEUM_ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1160 #ifdef LRECORD_CONS
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1161 set_lheader_implementation (&(c->lheader), lrecord_cons);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1162 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 XSETCONS (val, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 XCAR (val) = car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 XCDR (val) = cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1169 DEFUN ("list", Flist, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 Return a newly created list with specified arguments as elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 Any number of arguments, even zero arguments, are allowed.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1172 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1173 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 {
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1175 Lisp_Object val = Qnil;
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1176 Lisp_Object *argp = args + nargs;
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1177
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1178 while (nargs-- > 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents: 163
diff changeset
1179 val = Fcons (*--argp, val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 list1 (Lisp_Object obj0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 /* This cannot GC. */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1187 return Fcons (obj0, Qnil);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 list2 (Lisp_Object obj0, Lisp_Object obj1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 /* This cannot GC. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1194 return Fcons (obj0, Fcons (obj1, Qnil));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 /* This cannot GC. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1201 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Qnil)));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1204 Lisp_Object
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 return Fcons (obj0, Fcons (obj1, obj2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 Lisp_Object
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1212 acons (Lisp_Object key, Lisp_Object value, Lisp_Object alist)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1213 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1214 return Fcons (Fcons (key, value), alist);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1215 }
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1216
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1217 Lisp_Object
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 /* This cannot GC. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1221 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Qnil))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 Lisp_Object obj4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 /* This cannot GC. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1229 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Qnil)))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 Lisp_Object obj4, Lisp_Object obj5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 /* This cannot GC. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1237 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Fcons (obj5, Qnil))))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1240 DEFUN ("make-list", Fmake_list, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1241 Return a new list of length LENGTH, with each element being INIT.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1242 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1243 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 CHECK_NATNUM (length);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1246
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1247 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1248 Lisp_Object val = Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1249 int size = XINT (length);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1250
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1251 while (size-- > 0)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1252 val = Fcons (init, val);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1253 return val;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1254 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 /* Float allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 DECLARE_FIXED_TYPE_ALLOC (float, struct Lisp_Float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 make_float (double float_value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 struct Lisp_Float *f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 ALLOCATE_FIXED_TYPE (float, struct Lisp_Float, f);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
1274 set_lheader_implementation (&(f->lheader), lrecord_float);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 float_data (f) = float_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 XSETFLOAT (val, f);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1277 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 /* Vector allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1287 #ifdef LRECORD_VECTOR
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1288 static Lisp_Object
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1289 mark_vector (Lisp_Object obj, void (*markobj) (Lisp_Object))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1290 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1291 struct Lisp_Vector *ptr = XVECTOR (obj);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1292 int len = vector_length (ptr);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1293 int i;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1294
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1295 for (i = 0; i < len - 1; i++)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1296 (markobj) (ptr->contents[i]);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1297 return (len > 0) ? ptr->contents[len - 1] : Qnil;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1298 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1299
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1300 static size_t
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1301 size_vector (CONST void *lheader)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1302 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1303 /* * -1 because struct Lisp_Vector includes 1 slot */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1304 return sizeof (struct Lisp_Vector) +
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1305 ((((struct Lisp_Vector *) lheader)->size - 1) * sizeof (Lisp_Object));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1306 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1307
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1308 static int
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1309 vector_equal (Lisp_Object o1, Lisp_Object o2, int depth)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1310 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1311 int indice;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1312 int len = XVECTOR_LENGTH (o1);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1313 if (len != XVECTOR_LENGTH (o2))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1314 return 0;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1315 for (indice = 0; indice < len; indice++)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1316 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1317 if (!internal_equal (XVECTOR_DATA (o1) [indice],
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1318 XVECTOR_DATA (o2) [indice],
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1319 depth + 1))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1320 return 0;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1321 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1322 return 1;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1323 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1324
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1325 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION("vector", vector,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1326 mark_vector, print_vector, 0,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1327 vector_equal,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1328 /*
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1329 * No `hash' method needed for
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1330 * vectors. internal_hash
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1331 * knows how to handle vectors.
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1332 */
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1333 0,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1334 size_vector, struct Lisp_Vector);
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1335
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1336 /* #### should allocate `small' vectors from a frob-block */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1337 static struct Lisp_Vector *
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1338 make_vector_internal (size_t sizei)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1339 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1340 size_t sizem = (sizeof (struct Lisp_Vector)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1341 /* -1 because struct Lisp_Vector includes 1 slot */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1342 + (sizei - 1) * sizeof (Lisp_Object));
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1343 struct Lisp_Vector *p =
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1344 (struct Lisp_Vector *) alloc_lcrecord (sizem, lrecord_vector);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1345
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1346 p->size = sizei;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1347 return p;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1348 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1349
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1350 #else /* ! LRECORD_VECTOR */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1351
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 static Lisp_Object all_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 /* #### should allocate `small' vectors from a frob-block */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 static struct Lisp_Vector *
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1356 make_vector_internal (size_t sizei)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1358 size_t sizem = (sizeof (struct Lisp_Vector)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1359 /* -1 because struct Lisp_Vector includes 1 slot,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1360 * +1 to account for vector_next */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1361 + (sizei - 1 + 1) * sizeof (Lisp_Object));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1362 struct Lisp_Vector *p = (struct Lisp_Vector *) allocate_lisp_storage (sizem);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 INCREMENT_CONS_COUNTER (sizem, "vector");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 p->size = sizei;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 vector_next (p) = all_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 XSETVECTOR (all_vectors, p);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1369 return p;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
1372 #endif /* ! LRECORD_VECTOR */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
1373
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 make_vector (EMACS_INT length, Lisp_Object init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1377 int elt;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1378 Lisp_Object vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 struct Lisp_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 if (length < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 p = make_vector_internal (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 XSETVECTOR (vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 /* Initialize big arrays full of 0's quickly, for what that's worth */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 char *travesty = (char *) &init;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 for (i = 1; i < sizeof (Lisp_Object); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 if (travesty[i] != travesty[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 goto fill;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 memset (vector_data (p), travesty[0], length * sizeof (Lisp_Object));
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1397 return vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 fill:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 for (elt = 0; elt < length; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 vector_data(p)[elt] = init;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1404 return vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1407 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1408 Return a new vector of length LENGTH, with each element being INIT.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 See also the function `vector'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1410 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1411 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1413 CHECK_NATNUM (length);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1414 return make_vector (XINT (length), init);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1417 DEFUN ("vector", Fvector, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 Return a newly created vector with specified arguments as elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 Any number of arguments, even zero arguments, are allowed.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1420 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1421 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1423 Lisp_Object vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 int elt;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1425 struct Lisp_Vector *p = make_vector_internal (nargs);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 for (elt = 0; elt < nargs; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 vector_data(p)[elt] = args[elt];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1430 XSETVECTOR (vector, p);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1431 return vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 vector1 (Lisp_Object obj0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 return Fvector (1, &obj0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 vector2 (Lisp_Object obj0, Lisp_Object obj1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 Lisp_Object args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 return Fvector (2, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 Lisp_Object args[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 return Fvector (3, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1459 #if 0 /* currently unused */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1460
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 Lisp_Object obj3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 Lisp_Object args[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 return Fvector (4, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 Lisp_Object obj3, Lisp_Object obj4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 Lisp_Object args[5];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 return Fvector (5, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 Lisp_Object args[6];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 args[5] = obj5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 return Fvector (6, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 Lisp_Object obj6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 Lisp_Object args[7];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 args[5] = obj5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 args[6] = obj6;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 return Fvector (7, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 Lisp_Object obj6, Lisp_Object obj7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 Lisp_Object args[8];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 args[5] = obj5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 args[6] = obj6;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 args[7] = obj7;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 return Fvector (8, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1532 #endif /* unused */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 /* Bit Vector allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 static Lisp_Object all_bit_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 /* #### should allocate `small' bit vectors from a frob-block */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 static struct Lisp_Bit_Vector *
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1542 make_bit_vector_internal (size_t sizei)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1544 size_t sizem = sizeof (struct Lisp_Bit_Vector) +
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1545 /* -1 because struct Lisp_Bit_Vector includes 1 slot */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1546 sizeof (long) * (BIT_VECTOR_LONG_STORAGE (sizei) - 1);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1547 struct Lisp_Bit_Vector *p =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1548 (struct Lisp_Bit_Vector *) allocate_lisp_storage (sizem);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 set_lheader_implementation (&(p->lheader), lrecord_bit_vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 INCREMENT_CONS_COUNTER (sizem, "bit-vector");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 bit_vector_length (p) = sizei;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 bit_vector_next (p) = all_bit_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 /* make sure the extra bits in the last long are 0; the calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 functions might not set them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 p->bits[BIT_VECTOR_LONG_STORAGE (sizei) - 1] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 XSETBIT_VECTOR (all_bit_vectors, p);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1559 return p;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 make_bit_vector (EMACS_INT length, Lisp_Object init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1565 Lisp_Object bit_vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 struct Lisp_Bit_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 EMACS_INT num_longs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 CHECK_BIT (init);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 num_longs = BIT_VECTOR_LONG_STORAGE (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 p = make_bit_vector_internal (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 XSETBIT_VECTOR (bit_vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 if (ZEROP (init))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 memset (p->bits, 0, num_longs * sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 EMACS_INT bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 memset (p->bits, ~0, num_longs * sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 /* But we have to make sure that the unused bits in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 last integer are 0, so that equal/hash is easy. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 if (bits_in_last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1587 return bit_vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 make_bit_vector_from_byte_vector (unsigned char *bytevec, EMACS_INT length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1593 Lisp_Object bit_vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 struct Lisp_Bit_Vector *p;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1595 int i;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 if (length < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 p = make_bit_vector_internal (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 XSETBIT_VECTOR (bit_vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 for (i = 0; i < length; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 set_bit_vector_bit (p, i, bytevec[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 return bit_vector;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1609 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1610 Return a new bit vector of length LENGTH. with each bit being INIT.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 Each element is set to INIT. See also the function `bit-vector'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1612 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1613 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1615 CONCHECK_NATNUM (length);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1617 return make_bit_vector (XINT (length), init);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1620 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 Return a newly created bit vector with specified arguments as elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 Any number of arguments, even zero arguments, are allowed.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1623 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1624 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1626 Lisp_Object bit_vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 int elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 struct Lisp_Bit_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 for (elt = 0; elt < nargs; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 CHECK_BIT (args[elt]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 p = make_bit_vector_internal (nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 for (elt = 0; elt < nargs; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 set_bit_vector_bit (p, elt, !ZEROP (args[elt]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1638 XSETBIT_VECTOR (bit_vector, p);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1639 return bit_vector;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 /* Compiled-function allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 DECLARE_FIXED_TYPE_ALLOC (compiled_function, struct Lisp_Compiled_Function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 make_compiled_function (int make_pure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 struct Lisp_Compiled_Function *b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 Lisp_Object new;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1655 size_t size = sizeof (struct Lisp_Compiled_Function);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 if (make_pure && check_purespace (size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1659 b = (struct Lisp_Compiled_Function *) (PUREBEG + pure_bytes_used);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
1661 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
1662 b->lheader.pure = 1;
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
1663 #endif
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1664 pure_bytes_used += size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 bump_purestat (&purestat_bytecode, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 ALLOCATE_FIXED_TYPE (compiled_function, struct Lisp_Compiled_Function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 b->maxdepth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 b->flags.documentationp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 b->flags.interactivep = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 b->flags.domainp = 0; /* I18N3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 b->bytecodes = Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 b->constants = Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 b->arglist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 b->doc_and_interactive = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 b->annotated = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 XSETCOMPILED_FUNCTION (new, b);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1685 return new;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1688 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1689 Return a new compiled-function object.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 Usage: (arglist instructions constants stack-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 &optional doc-string interactive-spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 Note that, unlike all other emacs-lisp functions, calling this with five
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 arguments is NOT the same as calling it with six arguments, the last of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 which is nil. If the INTERACTIVE arg is specified as nil, then that means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 that this function was defined with `(interactive)'. If the arg is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 specified, then that means the function is not interactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 This is terrible behavior which is retained for compatibility with old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 `.elc' files which expected these semantics.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1699 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1700 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 /* In a non-insane world this function would have this arglist...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (arglist, instructions, constants, stack_size, doc_string, interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 Lisp_Object arglist, instructions, constants, stack_size, doc_string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 interactive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 Lisp_Object arglist = args[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 Lisp_Object instructions = args[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 Lisp_Object constants = args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 Lisp_Object stack_size = args[3];
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1711 Lisp_Object doc_string = (nargs > 4) ? args[4] : Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1712 Lisp_Object interactive = (nargs > 5) ? args[5] : Qunbound;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 /* Don't purecopy the doc references in instructions because it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 wasteful; they will get fixed up later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 #### If something goes wrong and they don't get fixed up,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 we're screwed, because pure stuff isn't marked and thus the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 cons references won't be marked and will get reused.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 Note: there will be a window after the byte code is created and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 before the doc references are fixed up in which there will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 impure objects inside a pure object, which apparently won't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 get marked, leading the trouble. But during that entire window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 the objects are sitting on Vload_force_doc_string_list, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 is staticpro'd, so we're OK. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 int purecopy_instructions = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 if (nargs > 6)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1729 return Fsignal (Qwrong_number_of_arguments,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 list2 (intern ("make-byte-code"), make_int (nargs)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 CHECK_LIST (arglist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 /* instructions is a string or a cons (string . int) for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 lazy-loaded function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 if (CONSP (instructions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 CHECK_STRING (XCAR (instructions));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 CHECK_INT (XCDR (instructions));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 if (!NILP (constants))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 CHECK_VECTOR (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 purecopy_instructions = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 CHECK_STRING (instructions);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 CHECK_VECTOR (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 CHECK_NATNUM (stack_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 /* doc_string may be nil, string, int, or a cons (string . int). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 /* interactive may be list or string (or unbound). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 if (purify_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 if (!purified (arglist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 arglist = Fpurecopy (arglist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 if (purecopy_instructions && !purified (instructions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 instructions = Fpurecopy (instructions);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 if (!purified (doc_string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 doc_string = Fpurecopy (doc_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 if (!purified (interactive) && !UNBOUNDP (interactive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 interactive = Fpurecopy (interactive);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 /* Statistics are kept differently for the constants */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 if (!purified (constants))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 int old = purecopying_for_bytecode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 purecopying_for_bytecode = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 constants = Fpurecopy (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 purecopying_for_bytecode = old;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 constants = Fpurecopy (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 if (STRINGP (instructions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 bump_purestat (&purestat_string_bytecodes, pure_sizeof (instructions));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 if (VECTORP (constants))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 bump_purestat (&purestat_vector_bytecode_constants,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 pure_sizeof (constants));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 if (STRINGP (doc_string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 /* These should be have been snagged by make-docfile... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 bump_purestat (&purestat_string_documentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 pure_sizeof (doc_string));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 if (STRINGP (interactive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 bump_purestat (&purestat_string_interactive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 pure_sizeof (interactive));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1792
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 int docp = !NILP (doc_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 int intp = !UNBOUNDP (interactive);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 int domp = !NILP (Vfile_domain);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 Lisp_Object val = make_compiled_function (purify_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 b->flags.documentationp = docp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 b->flags.interactivep = intp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 b->flags.domainp = domp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 b->maxdepth = XINT (stack_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 b->bytecodes = instructions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 b->constants = constants;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 b->arglist = arglist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 if (!NILP (Vcurrent_compiled_function_annotation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 b->annotated = Fpurecopy (Vcurrent_compiled_function_annotation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 else if (!NILP (Vload_file_name_internal_the_purecopy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 b->annotated = Vload_file_name_internal_the_purecopy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 else if (!NILP (Vload_file_name_internal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 {
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
1817 struct gcpro gcpro1;
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
1818 GCPRO1(val); /* don't let val or b get reaped */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 Vload_file_name_internal_the_purecopy =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 Fpurecopy (Ffile_name_nondirectory (Vload_file_name_internal));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 b->annotated = Vload_file_name_internal_the_purecopy;
177
6075d714658b Import from CVS: tag r20-3b15
cvs
parents: 175
diff changeset
1822 UNGCPRO;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1824 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 if (docp && intp && domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 (doc_string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (interactive, Vfile_domain))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 else if (docp && domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (doc_string, Vfile_domain));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 else if (intp && domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (interactive, Vfile_domain));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 if (docp && intp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (doc_string, interactive));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 else if (intp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 b->doc_and_interactive = interactive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 else if (domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 b->doc_and_interactive = Vfile_domain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 b->doc_and_interactive = doc_string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1852 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 /* Symbol allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 DECLARE_FIXED_TYPE_ALLOC (symbol, struct Lisp_Symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1864 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 Return a newly allocated uninterned symbol whose name is NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 Its value and function definition are void, and its property list is nil.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1867 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1868 (str))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 struct Lisp_Symbol *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 CHECK_STRING (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 ALLOCATE_FIXED_TYPE (symbol, struct Lisp_Symbol, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 #ifdef LRECORD_SYMBOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 set_lheader_implementation (&(p->lheader), lrecord_symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 p->name = XSTRING (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 p->plist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 p->value = Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 p->function = Qunbound;
245
51092a27c943 Import from CVS: tag r20-5b21
cvs
parents: 243
diff changeset
1883 p->obarray = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 symbol_next (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 XSETSYMBOL (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 /* Extent allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 struct extent *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 allocate_extent (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 struct extent *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 ALLOCATE_FIXED_TYPE (extent, struct extent, e);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1903 /* xzero (*e); */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 set_lheader_implementation (&(e->lheader), lrecord_extent);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 extent_object (e) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 set_extent_start (e, -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 set_extent_end (e, -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 e->plist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1910 xzero (e->flags);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 extent_face (e) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 e->flags.end_open = 1; /* default is for endpoints to behave like markers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 e->flags.detachable = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
1916 return e;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 /* Event allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 DECLARE_FIXED_TYPE_ALLOC (event, struct Lisp_Event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 allocate_event (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 struct Lisp_Event *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 ALLOCATE_FIXED_TYPE (event, struct Lisp_Event, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 set_lheader_implementation (&(e->lheader), lrecord_event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 XSETEVENT (val, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1939
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 /* Marker allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 DECLARE_FIXED_TYPE_ALLOC (marker, struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1948 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1949 Return a new marker which does not point at any place.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1950 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1951 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 struct Lisp_Marker *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 set_lheader_implementation (&(p->lheader), lrecord_marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 p->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 p->memind = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 marker_next (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 marker_prev (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 p->insertion_type = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 XSETMARKER (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 noseeum_make_marker (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 struct Lisp_Marker *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 NOSEEUM_ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 set_lheader_implementation (&(p->lheader), lrecord_marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 p->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 p->memind = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 marker_next (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 marker_prev (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 p->insertion_type = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 XSETMARKER (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 /* String allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1989 /* The data for "short" strings generally resides inside of structs of type
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1990 string_chars_block. The Lisp_String structure is allocated just like any
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 other Lisp object (except for vectors), and these are freelisted when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 they get garbage collected. The data for short strings get compacted,
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
1993 but the data for large strings do not.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 Previously Lisp_String structures were relocated, but this caused a lot
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 of bus-errors because the C code didn't include enough GCPRO's for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 that the reference would get relocated).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 This new method makes things somewhat bigger, but it is MUCH safer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 DECLARE_FIXED_TYPE_ALLOC (string, struct Lisp_String);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 /* strings are used and freed quite often */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2007 #ifdef LRECORD_STRING
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2008 static Lisp_Object
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2009 mark_string (Lisp_Object obj, void (*markobj) (Lisp_Object))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2010 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2011 struct Lisp_String *ptr = XSTRING (obj);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2012
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2013 if (GC_CONSP (ptr->plist) && GC_EXTENT_INFOP (XCAR (ptr->plist)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2014 flush_cached_extent_info (XCAR (ptr->plist));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2015 return ptr->plist;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2016 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2017
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2018 static int
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2019 string_equal (Lisp_Object o1, Lisp_Object o2, int depth)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2020 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2021 Bytecount len;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2022 return (((len = XSTRING_LENGTH (o1)) == XSTRING_LENGTH (o2)) &&
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2023 !memcmp (XSTRING_DATA (o1), XSTRING_DATA (o2), len));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2024 }
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2025
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2026 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("string", string,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2027 mark_string, print_string,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2028 /*
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2029 * No `finalize', or `hash' methods.
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2030 * internal_hash already knows how
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2031 * to hash strings and finalization
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2032 * is done with the
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2033 * ADDITIONAL_FREE_string macro,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2034 * which is the standard way to do
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2035 * finalization when using
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2036 * SWEEP_FIXED_TYPE_BLOCK().
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2037 */
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2038 0, string_equal, 0,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2039 struct Lisp_String);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2040 #endif /* LRECORD_STRING */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2041
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 /* String blocks contain this many useful bytes. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2043 #define STRING_CHARS_BLOCK_SIZE \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2044 ((Bytecount) (8192 - MALLOC_OVERHEAD - \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2045 ((2 * sizeof (struct string_chars_block *)) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2046 + sizeof (EMACS_INT))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 /* Block header for small strings. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 struct string_chars_block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 EMACS_INT pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 struct string_chars_block *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 struct string_chars_block *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 /* Contents of string_chars_block->string_chars are interleaved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 string_chars structures (see below) and the actual string data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 struct string_chars_block *first_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 struct string_chars_block *current_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 /* If SIZE is the length of a string, this returns how many bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 * the string occupies in string_chars_block->string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 * (including alignment padding).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 #define STRING_FULLSIZE(s) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 ALIGN_SIZE (((s) + 1 + sizeof (struct Lisp_String *)),\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 ALIGNOF (struct Lisp_String *))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 #define CHARS_TO_STRING_CHAR(x) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 ((struct string_chars *) \
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2074 (((char *) (x)) - (slot_offset (struct string_chars, chars[0]))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 struct string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 struct Lisp_String *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 unsigned char chars[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 struct unused_string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 struct Lisp_String *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 EMACS_INT fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 init_string_chars_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2092 first_string_chars_block = xnew (struct string_chars_block);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 first_string_chars_block->prev = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 first_string_chars_block->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 first_string_chars_block->pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 current_string_chars_block = first_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 static struct string_chars *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 allocate_string_chars_struct (struct Lisp_String *string_it_goes_with,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 EMACS_INT fullsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 struct string_chars *s_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 /* Allocate the string's actual data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 if (BIG_STRING_FULLSIZE_P (fullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 s_chars = (struct string_chars *) xmalloc (fullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 else if (fullsize <=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (countof (current_string_chars_block->string_chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 - current_string_chars_block->pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 /* This string can fit in the current string chars block */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 s_chars = (struct string_chars *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (current_string_chars_block->string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 + current_string_chars_block->pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 current_string_chars_block->pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 /* Make a new current string chars block */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2123 struct string_chars_block *new = xnew (struct string_chars_block);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2124
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 current_string_chars_block->next = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 new->prev = current_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 new->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 current_string_chars_block = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 new->pos = fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 s_chars = (struct string_chars *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 current_string_chars_block->string_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 s_chars->string = string_it_goes_with;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 INCREMENT_CONS_COUNTER (fullsize, "string chars");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 return s_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 make_uninit_string (Bytecount length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 struct Lisp_String *s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 struct string_chars *s_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 EMACS_INT fullsize = STRING_FULLSIZE (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 if ((length < 0) || (fullsize <= 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 /* Allocate the string header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 ALLOCATE_FIXED_TYPE (string, struct Lisp_String, s);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2154 #ifdef LRECORD_STRING
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2155 set_lheader_implementation (&(s->lheader), lrecord_string);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2156 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 s_chars = allocate_string_chars_struct (s, fullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 set_string_data (s, &(s_chars->chars[0]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 set_string_length (s, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 s->plist = Qnil;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2163
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 set_string_byte (s, length, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 XSETSTRING (val, s);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2167 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 #ifdef VERIFY_STRING_CHARS_INTEGRITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 static void verify_string_chars_integrity (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 #endif
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2173
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 /* Resize the string S so that DELTA bytes can be inserted starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 at POS. If DELTA < 0, it means deletion starting at POS. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 POS < 0, resize the string but don't copy any characters. Use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 this if you're planning on completely overwriting the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 resize_string (struct Lisp_String *s, Bytecount pos, Bytecount delta)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 #ifdef VERIFY_STRING_CHARS_INTEGRITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 verify_string_chars_integrity ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 #ifdef ERROR_CHECK_BUFPOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 assert (pos <= string_length (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 if (delta < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 assert (pos + (-delta) <= string_length (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 if (delta < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 assert ((-delta) <= string_length (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2199 #endif /* ERROR_CHECK_BUFPOS */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 if (pos >= 0 && delta < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 /* If DELTA < 0, the functions below will delete the characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 before POS. We want to delete characters *after* POS, however,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 so convert this to the appropriate form. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 pos += -delta;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 if (delta == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 /* simplest case: no size change. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2212 Bytecount oldfullsize = STRING_FULLSIZE (string_length (s));
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2213 Bytecount newfullsize = STRING_FULLSIZE (string_length (s) + delta);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 if (oldfullsize == newfullsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 /* next simplest case; size change but the necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 allocation size won't change (up or down; code somewhere
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 depends on there not being any unused allocation space,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 modulo any alignment constraints). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2223 Bufbyte *addroff = pos + string_data (s);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 memmove (addroff + delta, addroff,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 /* +1 due to zero-termination. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 string_length (s) + 1 - pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 else if (BIG_STRING_FULLSIZE_P (oldfullsize) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 BIG_STRING_FULLSIZE_P (newfullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 /* next simplest case; the string is big enough to be malloc()ed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 itself, so we just realloc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 It's important not to let the string get below the threshold
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 for making big strings and still remain malloc()ed; if that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 were the case, repeated calls to this function on the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 string could result in memory leakage. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 set_string_data (s, (Bufbyte *) xrealloc (string_data (s),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 newfullsize));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2244 Bufbyte *addroff = pos + string_data (s);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 memmove (addroff + delta, addroff,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 /* +1 due to zero-termination. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 string_length (s) + 1 - pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 /* worst case. We make a new string_chars struct and copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 the string's data into it, inserting/deleting the delta
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 in the process. The old string data will either get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 freed by us (if it was malloc()ed) or will be reclaimed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 in the normal course of garbage collection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 struct string_chars *s_chars =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 allocate_string_chars_struct (s, newfullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 Bufbyte *new_addr = &(s_chars->chars[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 Bufbyte *old_addr = string_data (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 memcpy (new_addr, old_addr, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 memcpy (new_addr + pos + delta, old_addr + pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 string_length (s) + 1 - pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 set_string_data (s, new_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 if (BIG_STRING_FULLSIZE_P (oldfullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 xfree (old_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 /* We need to mark this chunk of the string_chars_block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 as unused so that compact_string_chars() doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 freak. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 struct string_chars *old_s_chars =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (struct string_chars *) ((char *) old_addr -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 sizeof (struct Lisp_String *));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 /* Sanity check to make sure we aren't hosed by strange
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 alignment/padding. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 assert (old_s_chars->string == s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 MARK_STRUCT_AS_FREE (old_s_chars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 ((struct unused_string_chars *) old_s_chars)->fullsize =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 oldfullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 set_string_length (s, string_length (s) + delta);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 /* If pos < 0, the string won't be zero-terminated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 Terminate now just to make sure. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 string_data (s)[string_length (s)] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2295 Lisp_Object string;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 XSETSTRING (string, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 /* We also have to adjust all of the extent indices after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 place we did the change. We say "pos - 1" because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 adjust_extents() is exclusive of the starting position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 passed to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 adjust_extents (string, pos - 1, string_length (s),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 delta);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 #ifdef VERIFY_STRING_CHARS_INTEGRITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 verify_string_chars_integrity ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2312 #ifdef MULE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2313
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2314 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2315 set_string_char (struct Lisp_String *s, Charcount i, Emchar c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2316 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2317 Bytecount oldlen, newlen;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2318 Bufbyte newstr[MAX_EMCHAR_LEN];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2319 Bytecount bytoff = charcount_to_bytecount (string_data (s), i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2320
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2321 oldlen = charcount_to_bytecount (string_data (s) + bytoff, 1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2322 newlen = set_charptr_emchar (newstr, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2323
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2324 if (oldlen != newlen)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2325 resize_string (s, bytoff, newlen - oldlen);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2326 /* Remember, string_data (s) might have changed so we can't cache it. */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2327 memcpy (string_data (s) + bytoff, newstr, newlen);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2328 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2329
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2330 #endif /* MULE */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2331
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2332 DEFUN ("make-string", Fmake_string, 2, 2, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2333 Return a new string of length LENGTH, with each character being INIT.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 LENGTH must be an integer and INIT must be a character.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2335 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2336 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 CHECK_NATNUM (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 CHECK_CHAR_COERCE_INT (init);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 int len = set_charptr_emchar (str, XCHAR (init));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 val = make_uninit_string (len * XINT (length));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 if (len == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 /* Optimize the single-byte case */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2349 memset (XSTRING_DATA (val), XCHAR (init), XSTRING_LENGTH (val));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 int i, j, k;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2353 Bufbyte *ptr = XSTRING_DATA (val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 k = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 for (i = 0; i < XINT (length); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 for (j = 0; j < len; j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 ptr[k++] = str[j];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2361 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2364 DEFUN ("string", Fstring, 0, MANY, 0, /*
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2365 Concatenate all the argument characters and make the result a string.
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2366 */
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2367 (int nargs, Lisp_Object *args))
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2368 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2369 Bufbyte *storage = alloca_array (Bufbyte, nargs * MAX_EMCHAR_LEN);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2370 Bufbyte *p = storage;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2371
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2372 for (; nargs; nargs--, args++)
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2373 {
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2374 Lisp_Object lisp_char = *args;
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2375 CHECK_CHAR_COERCE_INT (lisp_char);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2376 p += set_charptr_emchar (p, XCHAR (lisp_char));
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2377 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2378 return make_string (storage, p - storage);
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2379 }
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
2380
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 /* Take some raw memory, which MUST already be in internal format,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2382 and package it up into a Lisp string. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 make_string (CONST Bufbyte *contents, Bytecount length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 Lisp_Object val;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2387
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2388 /* Make sure we find out about bad make_string's when they happen */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2389 #if defined (ERROR_CHECK_BUFPOS) && defined (MULE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2390 bytecount_to_charcount (contents, length); /* Just for the assertions */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
2391 #endif
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2392
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 val = make_uninit_string (length);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2394 memcpy (XSTRING_DATA (val), contents, length);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2395 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 /* Take some raw memory, encoded in some external data format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 and convert it into a Lisp string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 make_ext_string (CONST Extbyte *contents, EMACS_INT length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 enum external_data_format fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2404 Bufbyte *intstr;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 Bytecount intlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 GET_CHARPTR_INT_DATA_ALLOCA (contents, length, fmt, intstr, intlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 return make_string (intstr, intlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 build_string (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2414 /* Some strlen's crash and burn if passed null. */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2415 return make_string ((CONST Bufbyte *) str, (str ? strlen(str) : 0));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 build_ext_string (CONST char *str, enum external_data_format fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2421 /* Some strlen's crash and burn if passed null. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2422 return make_ext_string ((CONST Extbyte *) str, (str ? strlen(str) : 0), fmt);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 build_translated_string (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 return build_string (GETTEXT (str));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 /* lcrecord lists */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 /* Lcrecord lists are used to manage the allocation of particular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 sorts of lcrecords, to avoid calling alloc_lcrecord() (and thus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 malloc() and garbage-collection junk) as much as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 It is similar to the Blocktype class.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 It works like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 1) Create an lcrecord-list object using make_lcrecord_list().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 This is often done at initialization. Remember to staticpro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 this object! The arguments to make_lcrecord_list() are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 same as would be passed to alloc_lcrecord().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 2) Instead of calling alloc_lcrecord(), call allocate_managed_lcrecord()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 and pass the lcrecord-list earlier created.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 3) When done with the lcrecord, call free_managed_lcrecord().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 The standard freeing caveats apply: ** make sure there are no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 pointers to the object anywhere! **
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 4) Calling free_managed_lcrecord() is just like kissing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 lcrecord goodbye as if it were garbage-collected. This means:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 -- the contents of the freed lcrecord are undefined, and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 contents of something produced by allocate_managed_lcrecord()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 are undefined, just like for alloc_lcrecord().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 -- the mark method for the lcrecord's type will *NEVER* be called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 on freed lcrecords.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 -- the finalize method for the lcrecord's type will be called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 at the time that free_managed_lcrecord() is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 mark_lcrecord_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 struct lcrecord_list *list = XLCRECORD_LIST (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 Lisp_Object chain = list->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 while (!NILP (chain))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 struct lrecord_header *lheader = XRECORD_LHEADER (chain);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 struct free_lcrecord_header *free_header =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (struct free_lcrecord_header *) lheader;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2475
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2476 #ifdef ERROR_CHECK_GC
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 CONST struct lrecord_implementation *implementation
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2478 = LHEADER_IMPLEMENTATION(lheader);
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
2479
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 /* There should be no other pointers to the free list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 assert (!MARKED_RECORD_HEADER_P (lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 /* Only lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 assert (!implementation->basic_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 /* Only free lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 assert (free_header->lcheader.free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 /* The type of the lcrecord must be right. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 assert (implementation == list->implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 /* So must the size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 assert (implementation->static_size == 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 || implementation->static_size == list->size);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2491 #endif /* ERROR_CHECK_GC */
80
1ce6082ce73f Import from CVS: tag r20-0b90
cvs
parents: 70
diff changeset
2492
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 MARK_RECORD_HEADER (lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 chain = free_header->chain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2496
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2500 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2501 mark_lcrecord_list, internal_object_printer,
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2502 0, 0, 0, struct lcrecord_list);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 Lisp_Object
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2504 make_lcrecord_list (size_t size,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 CONST struct lrecord_implementation *implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2507 struct lcrecord_list *p = alloc_lcrecord_type (struct lcrecord_list,
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2508 lrecord_lcrecord_list);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2509 Lisp_Object val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 p->implementation = implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 p->size = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 p->free = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 XSETLCRECORD_LIST (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 allocate_managed_lcrecord (Lisp_Object lcrecord_list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 if (!NILP (list->free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 Lisp_Object val = list->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 struct free_lcrecord_header *free_header =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (struct free_lcrecord_header *) XPNTR (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 struct lrecord_header *lheader =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 (struct lrecord_header *) free_header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 CONST struct lrecord_implementation *implementation
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2532 = LHEADER_IMPLEMENTATION (lheader);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 /* There should be no other pointers to the free list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 assert (!MARKED_RECORD_HEADER_P (lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 /* Only lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 assert (!implementation->basic_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 /* Only free lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 assert (free_header->lcheader.free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 /* The type of the lcrecord must be right. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 assert (implementation == list->implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 /* So must the size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 assert (implementation->static_size == 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 || implementation->static_size == list->size);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2545 #endif /* ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 list->free = free_header->chain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 free_header->lcheader.free = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2552 Lisp_Object val;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2553
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2554 XSETOBJ (val, Lisp_Type_Record,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 alloc_lcrecord (list->size, list->implementation));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2556 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 struct free_lcrecord_header *free_header =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (struct free_lcrecord_header *) XPNTR (lcrecord);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 struct lrecord_header *lheader =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (struct lrecord_header *) free_header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 CONST struct lrecord_implementation *implementation
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2569 = LHEADER_IMPLEMENTATION (lheader);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 /* Make sure the size is correct. This will catch, for example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 putting a window configuration on the wrong free list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 if (implementation->size_in_bytes_method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 assert (((implementation->size_in_bytes_method) (lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 == list->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 assert (implementation->static_size == list->size);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2579 #endif /* ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 if (implementation->finalizer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 ((implementation->finalizer) (lheader, 0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 free_header->chain = list->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 free_header->lcheader.free = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 list->free = lcrecord;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 /* Purity of essence, peace on earth */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 static int symbols_initialized;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 make_pure_string (CONST Bufbyte *data, Bytecount length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 Lisp_Object plist, int no_need_to_copy_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 struct Lisp_String *s;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2601 size_t size = sizeof (struct Lisp_String) +
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2602 (no_need_to_copy_data ? 0 : (length + 1)); /* + 1 for terminating 0 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 size = ALIGN_SIZE (size, ALIGNOF (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 if (symbols_initialized && !pure_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 /* Try to share some names. Saves a few kbytes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 Lisp_Object tem = oblookup (Vobarray, data, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 if (SYMBOLP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 s = XSYMBOL (tem)->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 if (!PURIFIED (s)) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 XSETSTRING (new, s);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2614 return new;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 if (!check_purespace (size))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2619 return make_string (data, length);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2621 s = (struct Lisp_String *) (PUREBEG + pure_bytes_used);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2622 #ifdef LRECORD_STRING
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2623 set_lheader_implementation (&(s->lheader), lrecord_string);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2624 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2625 s->lheader.pure = 1;
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2626 #endif
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2627 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 set_string_length (s, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 if (no_need_to_copy_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 set_string_data (s, (Bufbyte *) data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 set_string_data (s, (Bufbyte *) s + sizeof (struct Lisp_String));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 memcpy (string_data (s), data, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 set_string_byte (s, length, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 s->plist = Qnil;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2640 pure_bytes_used += size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 bump_purestat (&purestat_string_all, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 if (purecopying_for_bytecode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 bump_purestat (&purestat_string_other_function, size);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2646 #endif /* PURESTAT */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 /* Do this after the official "completion" of the purecopying. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 s->plist = Fpurecopy (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 XSETSTRING (new, s);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2652 return new;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 make_pure_pname (CONST Bufbyte *data, Bytecount length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 int no_need_to_copy_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 Lisp_Object name = make_pure_string (data, length, Qnil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 no_need_to_copy_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 bump_purestat (&purestat_string_pname, pure_sizeof (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 /* We've made (at least) Qnil now, and Vobarray will soon be set up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 symbols_initialized = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2667 return name;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 pure_cons (Lisp_Object car, Lisp_Object cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 Lisp_Object new;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2675 struct Lisp_Cons *c;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 if (!check_purespace (sizeof (struct Lisp_Cons)))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2678 return Fcons (Fpurecopy (car), Fpurecopy (cdr));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2680 c = (struct Lisp_Cons *) (PUREBEG + pure_bytes_used);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2681 #ifdef LRECORD_CONS
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2682 set_lheader_implementation (&(c->lheader), lrecord_cons);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2683 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2684 c->lheader.pure = 1;
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2685 #endif
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2686 #endif
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2687 pure_bytes_used += sizeof (struct Lisp_Cons);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 bump_purestat (&purestat_cons, sizeof (struct Lisp_Cons));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2690 c->car = Fpurecopy (car);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2691 c->cdr = Fpurecopy (cdr);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2692 XSETCONS (new, c);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2693 return new;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 pure_list (int nargs, Lisp_Object *args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2699 Lisp_Object val = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 for (--nargs; nargs >= 0; nargs--)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2702 val = pure_cons (args[nargs], val);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2703
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2704 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2709 static Lisp_Object
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 make_pure_float (double num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 struct Lisp_Float *f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2715 /* Make sure that PUREBEG + pure_bytes_used is aligned on at least a sizeof
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 (double) boundary. Some architectures (like the sparc) require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 this, and I suspect that floats are rare enough that it's no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 tragedy for those that don't. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 #if defined (__GNUC__) && (__GNUC__ >= 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 /* In gcc, we can directly ask what the alignment constraints of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 structure are, but in general, that's not possible... Arrgh!!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 int alignment = __alignof (struct Lisp_Float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 #else /* !GNUC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 /* Best guess is to make the `double' slot be aligned to the size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 of double (which is probably 8 bytes). This assumes that it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 ok to align the beginning of the structure to the same boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 that the `double' slot in it is supposed to be aligned to; this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 should be ok because presumably there is padding in the layout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 of the struct to account for this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 int alignment = sizeof (float_data (f));
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2734 #endif /* !GNUC */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2735 char *p = ((char *) PUREBEG + pure_bytes_used);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2736
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2737 p = (char *) (((EMACS_UINT) p + alignment - 1) & - alignment);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2738 pure_bytes_used = p - (char *) PUREBEG;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 if (!check_purespace (sizeof (struct Lisp_Float)))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2742 return make_float (num);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2744 f = (struct Lisp_Float *) (PUREBEG + pure_bytes_used);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 set_lheader_implementation (&(f->lheader), lrecord_float);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2746 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2747 f->lheader.pure = 1;
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2748 #endif
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2749 pure_bytes_used += sizeof (struct Lisp_Float);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 bump_purestat (&purestat_float, sizeof (struct Lisp_Float));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 float_data (f) = num;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 XSETFLOAT (val, f);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2754 return val;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 Lisp_Object
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2760 make_pure_vector (size_t len, Lisp_Object init)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 Lisp_Object new;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2763 struct Lisp_Vector *v;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2764 size_t size = (sizeof (struct Lisp_Vector)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2765 + (len - 1) * sizeof (Lisp_Object));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 init = Fpurecopy (init);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 if (!check_purespace (size))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2770 return make_vector (len, init);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2772 v = (struct Lisp_Vector *) (PUREBEG + pure_bytes_used);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2773 #ifdef LRECORD_VECTOR
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2774 set_lheader_implementation (&(v->header.lheader), lrecord_vector);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2775 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2776 v->header.lheader.pure = 1;
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
2777 #endif
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2778 #endif
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2779 pure_bytes_used += size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 bump_purestat (&purestat_vector_all, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2782 v->size = len;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 for (size = 0; size < len; size++)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2785 v->contents[size] = init;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2786
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
2787 XSETVECTOR (new, v);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2788 return new;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 /* Presently unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 alloc_pure_lrecord (int size, struct lrecord_implementation *implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2796 struct lrecord_header *header = (void *) (PUREBEG + pure_bytes_used);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2797
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2798 if (pure_bytes_used + size > get_PURESIZE())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 pure_storage_exhausted ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 set_lheader_implementation (header, implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 header->next = 0;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2803 return header;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2805 #endif /* unused */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2809 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 Make a copy of OBJECT in pure storage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 Recursively copies contents of vectors and cons cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 Does not copy symbols.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2813 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2814 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 if (!purify_flag)
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2818 return obj;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 if (!POINTER_TYPE_P (XTYPE (obj))
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2821 || PURIFIED (XPNTR (obj))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2822 /* happens when bootstrapping Qnil */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2823 || EQ (obj, Qnull_pointer))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2824 return obj;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 switch (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2828 #ifndef LRECORD_CONS
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2829 case Lisp_Type_Cons:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 return pure_cons (XCAR (obj), XCDR (obj));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2831 #endif
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2832
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2833 #ifndef LRECORD_STRING
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2834 case Lisp_Type_String:
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2835 return make_pure_string (XSTRING_DATA (obj),
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2836 XSTRING_LENGTH (obj),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 XSTRING (obj)->plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 0);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2839 #endif /* ! LRECORD_STRING */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2841 #ifndef LRECORD_VECTOR
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2842 case Lisp_Type_Vector:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 struct Lisp_Vector *o = XVECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 Lisp_Object new = make_pure_vector (vector_length (o), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 for (i = 0; i < vector_length (o); i++)
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2847 XVECTOR_DATA (new)[i] = Fpurecopy (o->contents[i]);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2848 return new;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2850 #endif /* !LRECORD_VECTOR */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 if (COMPILED_FUNCTIONP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 struct Lisp_Compiled_Function *o = XCOMPILED_FUNCTION (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 Lisp_Object new = make_compiled_function (1);
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2858 /* How on earth could this code have worked before? -sb */
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2859 struct Lisp_Compiled_Function *n = XCOMPILED_FUNCTION (new);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 n->flags = o->flags;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 n->bytecodes = Fpurecopy (o->bytecodes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 n->constants = Fpurecopy (o->constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 n->arglist = Fpurecopy (o->arglist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 n->doc_and_interactive = Fpurecopy (o->doc_and_interactive);
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
2865 n->maxdepth = o->maxdepth;
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2866 return new;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 }
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2868 #ifdef LRECORD_CONS
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2869 else if (CONSP (obj))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2870 return pure_cons (XCAR (obj), XCDR (obj));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2871 #endif /* LRECORD_CONS */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2872 #ifdef LRECORD_VECTOR
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2873 else if (VECTORP (obj))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2874 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2875 struct Lisp_Vector *o = XVECTOR (obj);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2876 Lisp_Object new = make_pure_vector (vector_length (o), Qnil);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2877 for (i = 0; i < vector_length (o); i++)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2878 XVECTOR_DATA (new)[i] = Fpurecopy (o->contents[i]);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2879 return new;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2880 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2881 #endif /* LRECORD_VECTOR */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2882 #ifdef LRECORD_STRING
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2883 else if (STRINGP (obj))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2884 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2885 return make_pure_string (XSTRING_DATA (obj),
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2886 XSTRING_LENGTH (obj),
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2887 XSTRING (obj)->plist,
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2888 0);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2889 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
2890 #endif /* LRECORD_STRING */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 else if (FLOATP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 return make_pure_float (float_data (XFLOAT (obj)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 #endif /* LISP_FLOAT_TYPE */
247
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2895 else if (SYMBOLP (obj))
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2896 {
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2897 /*
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2898 * Symbols can't be made pure (and thus read-only),
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2899 * because assigning to their function, value or plist
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2900 * slots would produced a SEGV in the dumped XEmacs. So
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2901 * we previously would just return the symbol unchanged.
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2902 *
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2903 * But purified aggregate objects like lists and vectors
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2904 * can contain uninterned symbols. If there are no
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2905 * other non-pure references to the symbol, then the
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
2906 * symbol is not protected from garbage collection
247
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2907 * because the collector does not mark the contents of
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2908 * purified objects. So to protect the symbols, an impure
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2909 * reference has to be kept for each uninterned symbol
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2910 * that is referenced by a pure object. All such
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2911 * symbols are stored in the hashtable pointed to by
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
2912 * Vpure_uninterned_symbol_table, which is itself
247
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2913 * staticpro'd.
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2914 */
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
2915 if (!NILP (XSYMBOL (obj)->obarray))
247
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2916 return obj;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
2917 Fputhash (obj, Qnil, Vpure_uninterned_symbol_table);
247
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2918 return obj;
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2919 }
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2920 else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 signal_simple_error ("Can't purecopy %S", obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
2924 return obj;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2929 static void
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2930 puresize_adjust_h (size_t puresize)
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2931 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2932 FILE *stream = fopen ("puresize-adjust.h", "w");
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2933
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2934 if (stream == NULL)
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2935 report_file_error ("Opening puresize adjustment file",
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2936 Fcons (build_string ("puresize-adjust.h"), Qnil));
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2937
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2938 fprintf (stream,
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2939 "/*\tDo not edit this file!\n"
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2940 "\tAutomatically generated by XEmacs */\n"
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2941 "# define PURESIZE_ADJUSTMENT (%ld)\n",
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2942 (long) (puresize - RAW_PURESIZE));
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2943 fclose (stream);
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2944 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2945
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 report_pure_usage (int report_impurities,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 int die_if_pure_storage_exceeded)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 {
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2950 int rc = 0;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2951
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 if (pure_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 message ("\n****\tPure Lisp storage exhausted!\n"
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2955 "\tPurespace usage: %ld of %ld\n"
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2956 "****",
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2957 (long) get_PURESIZE() + pure_lossage,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2958 (long) get_PURESIZE());
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2959 if (die_if_pure_storage_exceeded)
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2960 {
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2961 puresize_adjust_h (get_PURESIZE() + pure_lossage);
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
2962 #ifdef HEAP_IN_DATA
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2963 sheap_adjust_h();
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
2964 #endif
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2965 rc = -1;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2966 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2970 size_t lost = (get_PURESIZE() - pure_bytes_used) / 1024;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 char buf[200];
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
2972 /* extern Lisp_Object Vemacs_beta_version; */
247
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2973 /* This used to be NILP(Vemacs_beta_version) ? 512 : 4; */
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2974 #ifndef PURESIZE_SLOP
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
2975 #define PURESIZE_SLOP 0
247
e70b3a057e12 Import from CVS: tag r20-5b22
cvs
parents: 245
diff changeset
2976 #endif
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2977 size_t slop = PURESIZE_SLOP;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 sprintf (buf, "Purespace usage: %ld of %ld (%d%%",
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2980 (long) pure_bytes_used,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2981 (long) get_PURESIZE(),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2982 (int) (pure_bytes_used / (get_PURESIZE() / 100.0) + 0.5));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
2983 if (lost > ((slop ? slop : 1) / 1024)) {
274
ca9a9ec9c1c1 Import from CVS: tag r21-0b35
cvs
parents: 272
diff changeset
2984 sprintf (buf + strlen (buf), " -- %ldk wasted", (long)lost);
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2985 if (die_if_pure_storage_exceeded) {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2986 puresize_adjust_h (pure_bytes_used + slop);
251
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
2987 #ifdef HEAP_IN_DATA
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
2988 sheap_adjust_h();
677f6a0ee643 Import from CVS: tag r20-5b24
cvs
parents: 249
diff changeset
2989 #endif
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2990 rc = -1;
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2991 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2992 }
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
2993
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 strcat (buf, ").");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 message ("%s", buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 #ifdef PURESTAT
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
2999
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3000 purestat_vector_other.nbytes =
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3001 purestat_vector_all.nbytes -
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3002 purestat_vector_bytecode_constants.nbytes;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3003 purestat_vector_other.nobjects =
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3004 purestat_vector_all.nobjects -
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3005 purestat_vector_bytecode_constants.nobjects;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3006
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3007 purestat_string_other.nbytes =
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3008 purestat_string_all.nbytes -
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3009 (purestat_string_pname.nbytes +
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3010 purestat_string_bytecodes.nbytes +
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3011 purestat_string_interactive.nbytes +
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3012 purestat_string_documentation.nbytes +
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 #ifdef I18N3
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3014 purestat_string_domain.nbytes +
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 #endif
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3016 purestat_string_other_function.nbytes);
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3017
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3018 purestat_string_other.nobjects =
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3019 purestat_string_all.nobjects -
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3020 (purestat_string_pname.nobjects +
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3021 purestat_string_bytecodes.nobjects +
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3022 purestat_string_interactive.nobjects +
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3023 purestat_string_documentation.nobjects +
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 #ifdef I18N3
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3025 purestat_string_domain.nobjects +
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 #endif
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3027 purestat_string_other_function.nobjects);
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3028
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3029 message (" %-26s Total Bytes", "");
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3030
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3031 {
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3032 int j;
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3033
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3034 for (j = 0; j < countof (purestats); j++)
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3035 if (!purestats[j])
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 clear_message ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 else
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3038 {
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3039 char buf [100];
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3040 sprintf(buf, "%s:", purestats[j]->name);
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3041 message (" %-26s %5d %7d %2d%%",
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3042 buf,
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3043 purestats[j]->nobjects,
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3044 purestats[j]->nbytes,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3045 (int) (purestats[j]->nbytes / (pure_bytes_used / 100.0) + 0.5));
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3046 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 if (report_impurities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 Lisp_Object tem = Felt (Fgarbage_collect (), make_int (5));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 GCPRO1 (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 message ("\nImpurities:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 while (!NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 if (CONSP (tem) && SYMBOLP (Fcar (tem)) && CONSP (Fcdr (tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 int total = XINT (Fcar (Fcdr (tem)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 if (total > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 char buf [100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 char *s = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 memcpy (buf, string_data (XSYMBOL (Fcar (tem))->name),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 string_length (XSYMBOL (Fcar (tem))->name) + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 while (*s++) if (*s == '-') *s = ' ';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 s--; *s++ = ':'; *s = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3070 message (" %-33s %6d", buf, total);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 tem = Fcdr (Fcdr (tem));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 else /* WTF?! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 Fprin1 (tem, Qexternal_debugging_output);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 tem = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 garbage_collect_1 (); /* GC garbage_collect's garbage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 clear_message ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
3085 if (rc < 0) {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3086 unlink("SATISFIED");
171
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 169
diff changeset
3087 fatal ("Pure size adjusted, Don't Panic! I will restart the `make'");
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
3088 } else if (pure_lossage && die_if_pure_storage_exceeded) {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 fatal ("Pure storage exhausted");
102
a145efe76779 Import from CVS: tag r20-1b3
cvs
parents: 100
diff changeset
3090 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 /* staticpro */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 struct gcpro *gcprolist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 /* 415 used Mly 29-Jun-93 */
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
3101 /* 1327 used slb 28-Feb-98 */
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
3102 #ifdef HAVE_SHLIB
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
3103 #define NSTATICS 4000
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
3104 #else
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
3105 #define NSTATICS 2000
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
3106 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 /* Not "static" because of linker lossage on some systems */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 Lisp_Object *staticvec[NSTATICS]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 /* Force it into data space! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 = {0};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 static int staticidx;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 /* Put an entry in staticvec, pointing at the variable whose address is given
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 staticpro (Lisp_Object *varaddress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 if (staticidx >= countof (staticvec))
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
3119 /* #### This is now a dubious abort() since this routine may be called */
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
3120 /* by Lisp attempting to load a DLL. */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 staticvec[staticidx++] = varaddress;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 /* Mark reference to a Lisp_Object. If the object referred to has not been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 seen yet, recursively mark all the references contained in it. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3128
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 mark_object (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 tail_recurse:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3134 if (EQ (obj, Qnull_pointer))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3135 return;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 if (!POINTER_TYPE_P (XGCTYPE (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 if (PURIFIED (XPNTR (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 switch (XGCTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3142 #ifndef LRECORD_CONS
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3143 case Lisp_Type_Cons:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 struct Lisp_Cons *ptr = XCONS (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 if (CONS_MARKED_P (ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 MARK_CONS (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 /* If the cdr is nil, tail-recurse on the car. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 if (NILP (ptr->cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 obj = ptr->car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 mark_object (ptr->car);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 obj = ptr->cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 }
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3161 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3163 case Lisp_Type_Record:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 /* case Lisp_Symbol_Value_Magic: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 CONST struct lrecord_implementation *implementation
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3168 = LHEADER_IMPLEMENTATION (lheader);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 if (! MARKED_RECORD_HEADER_P (lheader) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 ! UNMARKABLE_RECORD_HEADER_P (lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 MARK_RECORD_HEADER (lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 if (!implementation->basic_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 assert (! ((struct lcrecord_header *) lheader)->free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 if (implementation->marker != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 obj = ((implementation->marker) (obj, mark_object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 if (!NILP (obj)) goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3187 #ifndef LRECORD_STRING
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3188 case Lisp_Type_String:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 struct Lisp_String *ptr = XSTRING (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 if (!XMARKBIT (ptr->plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 if (CONSP (ptr->plist) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 EXTENT_INFOP (XCAR (ptr->plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 flush_cached_extent_info (XCAR (ptr->plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 XMARK (ptr->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 obj = ptr->plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 break;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3203 #endif /* ! LRECORD_STRING */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3205 #ifndef LRECORD_VECTOR
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3206 case Lisp_Type_Vector:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 struct Lisp_Vector *ptr = XVECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 int len = vector_length (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 if (len < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 break; /* Already marked */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 ptr->size = -1 - len; /* Else mark it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 for (i = 0; i < len - 1; i++) /* and then mark its elements */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 mark_object (ptr->contents[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 if (len > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 obj = ptr->contents[len - 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 break;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3224 #endif /* !LRECORD_VECTOR */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 #ifndef LRECORD_SYMBOL
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3227 case Lisp_Type_Symbol:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 struct Lisp_Symbol *sym = XSYMBOL (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 while (!XMARKBIT (sym->plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 XMARK (sym->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 mark_object (sym->value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 mark_object (sym->function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3237 /*
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3238 * symbol->name is a struct Lisp_String *, not a
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3239 * Lisp_Object. Fix it up and pass to mark_object.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3240 */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3241 Lisp_Object symname;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3242 XSETSTRING(symname, sym->name);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3243 mark_object(symname);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 if (!symbol_next (sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 obj = sym->plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 mark_object (sym->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 /* Mark the rest of the symbols in the hash-chain */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 sym = symbol_next (sym);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 #endif /* !LRECORD_SYMBOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 /* mark all of the conses in a list and mark the final cdr; but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 DO NOT mark the cars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 Use only for internal lists! There should never be other pointers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 to the cons cells, because if so, the cars will remain unmarked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 even when they maybe should be marked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 mark_conses_in_list (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 for (rest = obj; CONSP (rest); rest = XCDR (rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 if (CONS_MARKED_P (XCONS (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 MARK_CONS (XCONS (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 mark_object (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 #ifdef PURESTAT
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3286 /* Simpler than mark-object, because pure structure can't
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3287 have any circularities */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 static int idiot_c_doesnt_have_closures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 idiot_c (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 idiot_c_doesnt_have_closures += pure_sizeof (obj, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3298 static size_t
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3299 pure_string_sizeof (Lisp_Object obj)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3300 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3301 struct Lisp_String *ptr = XSTRING (obj);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3302
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3303 if (string_data (ptr) != (Bufbyte *) ptr + sizeof (*ptr))
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3304 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3305 /* string-data not allocated contiguously.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3306 Probably (better be!!) a pointer constant "C" data. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3307 return sizeof (*ptr);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3308 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3309 else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3310 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3311 size_t size = sizeof (*ptr) + string_length (ptr) + 1;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3312 size = ALIGN_SIZE (size, sizeof (Lisp_Object));
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3313 return size;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3314 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3315 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3316
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 /* recurse arg isn't actually used */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3318 static size_t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 pure_sizeof (Lisp_Object obj /*, int recurse */)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3321 size_t total = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 /*tail_recurse: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 if (!POINTER_TYPE_P (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 || !PURIFIED (XPNTR (obj)))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
3326 return total;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 /* symbol's sizes are accounted for separately */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 if (SYMBOLP (obj))
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
3330 return total;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 switch (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3334
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3335 #ifndef LRECORD_STRING
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3336 case Lisp_Type_String:
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3337 total += pure_string_sizeof (obj);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 break;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3339 #endif /* ! LRECORD_STRING */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3341 #ifndef LRECORD_VECTOR
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3342 case Lisp_Type_Vector:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 struct Lisp_Vector *ptr = XVECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 int len = vector_length (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 total += (sizeof (struct Lisp_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 + (len - 1) * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 if (!recurse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3352 {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 for (i = 0; i < len - 1; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 total += pure_sizeof (ptr->contents[i], 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 if (len > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 obj = ptr->contents[len - 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 break;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3365 #endif /* !LRECORD_VECTOR */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3366
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3367 case Lisp_Type_Record:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 CONST struct lrecord_implementation *implementation
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3371 = LHEADER_IMPLEMENTATION (lheader);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3373 #ifdef LRECORD_STRING
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3374 if (STRINGP (obj))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3375 total += pure_string_sizeof (obj);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3376 else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3377 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 if (implementation->size_in_bytes_method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 total += ((implementation->size_in_bytes_method) (lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 total += implementation->static_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 if (!recurse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 if (implementation->marker != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 int old = idiot_c_doesnt_have_closures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 idiot_c_doesnt_have_closures = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 obj = ((implementation->marker) (obj, idiot_c));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 total += idiot_c_doesnt_have_closures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 idiot_c_doesnt_have_closures = old;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3395
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 if (!NILP (obj)) goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3402 #ifndef LRECORD_CONS
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3403 case Lisp_Type_Cons:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 struct Lisp_Cons *ptr = XCONS (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 total += sizeof (*ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 if (!recurse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 /* If the cdr is nil, tail-recurse on the car. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 if (NILP (ptr->cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 obj = ptr->car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 total += pure_sizeof (ptr->car, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 obj = ptr->cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 break;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3424 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 /* Others can't be purified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
3430 return total;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 /* Find all structures not marked, and free them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3439 #ifndef LRECORD_VECTOR
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 static int gc_count_num_vector_used, gc_count_vector_total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 static int gc_count_vector_storage;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3442 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 static int gc_count_num_bit_vector_used, gc_count_bit_vector_total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 static int gc_count_bit_vector_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 static int gc_count_num_short_string_in_use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 static int gc_count_string_total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 static int gc_count_short_string_total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 /* static int gc_count_total_records_used, gc_count_records_total_size; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 /* This will be used more extensively In The Future */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 static int last_lrecord_type_index_assigned;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3455 CONST struct lrecord_implementation *lrecord_implementations_table[128];
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 #define max_lrecord_type (countof (lrecord_implementations_table) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3458 int
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 lrecord_type_index (CONST struct lrecord_implementation *implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 int type_index = *(implementation->lrecord_type_index);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3462 /* Have to do this circuitous validation test because of problems
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 dumping out initialized variables (ie can't set xxx_type_index to -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 because that would make xxx_type_index read-only in a dumped emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 if (type_index < 0 || type_index > max_lrecord_type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 || lrecord_implementations_table[type_index] != implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 if (last_lrecord_type_index_assigned == max_lrecord_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 type_index = ++last_lrecord_type_index_assigned;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 lrecord_implementations_table[type_index] = implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 *(implementation->lrecord_type_index) = type_index;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 }
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
3474 return type_index;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 /* stats on lcrecords in use - kinda kludgy */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 static struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 int instances_in_use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 int bytes_in_use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 int instances_freed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 int bytes_freed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 int instances_on_free_list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 } lcrecord_stats [countof (lrecord_implementations_table)];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 reset_lcrecord_stats (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 for (i = 0; i < countof (lcrecord_stats); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 lcrecord_stats[i].instances_in_use = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 lcrecord_stats[i].bytes_in_use = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 lcrecord_stats[i].instances_freed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 lcrecord_stats[i].bytes_freed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 lcrecord_stats[i].instances_on_free_list = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 tick_lcrecord_stats (CONST struct lrecord_header *h, int free_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 {
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3506 CONST struct lrecord_implementation *implementation =
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3507 LHEADER_IMPLEMENTATION (h);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 int type_index = lrecord_type_index (implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 if (((struct lcrecord_header *) h)->free)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 assert (!free_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 lcrecord_stats[type_index].instances_on_free_list++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3517 size_t sz = (implementation->size_in_bytes_method
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3518 ? ((implementation->size_in_bytes_method) (h))
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
3519 : implementation->static_size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 if (free_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 lcrecord_stats[type_index].instances_freed++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 lcrecord_stats[type_index].bytes_freed += sz;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 lcrecord_stats[type_index].instances_in_use++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 lcrecord_stats[type_index].bytes_in_use += sz;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 /* Free all unmarked records */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 struct lcrecord_header *header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 int num_used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 /* int total_size = 0; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 reset_lcrecord_stats ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 /* First go through and call all the finalize methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 Then go through and free the objects. There used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 be only one loop here, with the call to the finalizer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 occurring directly before the xfree() below. That
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 is marginally faster but much less safe -- if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 finalize method for an object needs to reference any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 other objects contained within it (and many do),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 we could easily be screwed by having already freed that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 other object. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 for (header = *prev; header; header = header->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 struct lrecord_header *h = &(header->lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 if (!MARKED_RECORD_HEADER_P (h) && ! (header->free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 {
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3559 if (LHEADER_IMPLEMENTATION (h)->finalizer)
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
3560 ((LHEADER_IMPLEMENTATION (h)->finalizer) (h, 0));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 for (header = *prev; header; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 struct lrecord_header *h = &(header->lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 if (MARKED_RECORD_HEADER_P (h))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 UNMARK_RECORD_HEADER (h);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 num_used++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 /* total_size += ((n->implementation->size_in_bytes) (h));*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 prev = &(header->next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 header = *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 tick_lcrecord_stats (h, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 struct lcrecord_header *next = header->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 *prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 tick_lcrecord_stats (h, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 /* used to call finalizer right here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 xfree (header);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 header = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 *used = num_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 /* *total = total_size; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3590 #ifndef LRECORD_VECTOR
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3591
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 static void
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3593 sweep_vectors_1 (Lisp_Object *prev,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 int *used, int *total, int *storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 Lisp_Object vector;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 int num_used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 int total_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 int total_storage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 for (vector = *prev; VECTORP (vector); )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 struct Lisp_Vector *v = XVECTOR (vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 int len = v->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 if (len < 0) /* marked */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 len = - (len + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 v->size = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 total_size += len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 total_storage += (MALLOC_OVERHEAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 + sizeof (struct Lisp_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 + (len - 1 + 1) * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 num_used++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 prev = &(vector_next (v));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 vector = *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 Lisp_Object next = vector_next (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 *prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 xfree (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 vector = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 *used = num_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 *total = total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 *storage = total_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3630 #endif /* ! LRECORD_VECTOR */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3631
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 static void
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3633 sweep_bit_vectors_1 (Lisp_Object *prev,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 int *used, int *total, int *storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 Lisp_Object bit_vector;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 int num_used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 int total_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 int total_storage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 /* BIT_VECTORP fails because the objects are marked, which changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 their implementation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 for (bit_vector = *prev; !EQ (bit_vector, Qzero); )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 struct Lisp_Bit_Vector *v = XBIT_VECTOR (bit_vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 int len = v->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 if (MARKED_RECORD_P (bit_vector))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 UNMARK_RECORD_HEADER (&(v->lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 total_size += len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 total_storage += (MALLOC_OVERHEAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 + sizeof (struct Lisp_Bit_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 + (BIT_VECTOR_LONG_STORAGE (len) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 * sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 num_used++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 prev = &(bit_vector_next (v));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 bit_vector = *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 Lisp_Object next = bit_vector_next (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 *prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 xfree (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 bit_vector = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 *used = num_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 *total = total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 *storage = total_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 /* And the Lord said: Thou shalt use the `c-backslash-region' command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 to make macros prettier. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 struct typename##_block *_frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 struct typename##_block **_frob_prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 int _frob_limit; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 int num_free = 0, num_used = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 for (_frob_prev = &current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 _frob_current = current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 _frob_limit = current_##typename##_block_index; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 _frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 ) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 int _frob_iii; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 if (FREE_STRUCT_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 else if (!MARKED_##typename##_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 num_used++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 UNMARK_##typename (_frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 _frob_prev = &(_frob_current->prev); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 _frob_current = _frob_current->prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 _frob_limit = countof (current_##typename##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 gc_count_num_##typename##_in_use = num_used; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 gc_count_num_##typename##_freelist = num_free; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3720 #else /* !ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 struct typename##_block *_frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 struct typename##_block **_frob_prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 int _frob_limit; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 int num_free = 0, num_used = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 typename##_free_list = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 for (_frob_prev = &current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 _frob_current = current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 _frob_limit = current_##typename##_block_index; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 _frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 ) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 int _frob_iii; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 int _frob_empty = 1; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 obj_type *_frob_old_free_list = typename##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 if (FREE_STRUCT_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, _frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 else if (!MARKED_##typename##_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 _frob_empty = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 num_used++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 UNMARK_##typename (_frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 if (!_frob_empty) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 _frob_prev = &(_frob_current->prev); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 _frob_current = _frob_current->prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 else if (_frob_current == current_##typename##_block \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 && !_frob_current->prev) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 /* No real point in freeing sole allocation block */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 break; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 struct typename##_block *_frob_victim_block = _frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 if (_frob_victim_block == current_##typename##_block) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 current_##typename##_block_index \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 = countof (current_##typename##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 _frob_current = _frob_current->prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 *_frob_prev = _frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 xfree (_frob_victim_block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 /* Restore free list to what it was before victim was swept */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 typename##_free_list = _frob_old_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 num_free -= _frob_limit; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 _frob_limit = countof (current_##typename##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 gc_count_num_##typename##_in_use = num_used; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 gc_count_num_##typename##_freelist = num_free; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3795 #endif /* !ERROR_CHECK_GC */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 sweep_conses (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3803 #ifndef LRECORD_CONS
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3804 # define MARKED_cons_P(ptr) XMARKBIT ((ptr)->car)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3805 # define UNMARK_cons(ptr) do { XUNMARK ((ptr)->car); } while (0)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3806 #else /* LRECORD_CONS */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3807 # define MARKED_cons_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3808 # define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
3809 #endif /* LRECORD_CONS */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 #define ADDITIONAL_FREE_cons(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 SWEEP_FIXED_TYPE_BLOCK (cons, struct Lisp_Cons);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 /* Explicitly free a cons cell. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 free_cons (struct Lisp_Cons *ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 /* If the CAR is not an int, then it will be a pointer, which will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 always be four-byte aligned. If this cons cell has already been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 placed on the free list, however, its car will probably contain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 a chain pointer to the next cons on the list, which has cleverly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 had all its 0's and 1's inverted. This allows for a quick
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 check to make sure we're not freeing something already freed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 if (POINTER_TYPE_P (XTYPE (ptr->car)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 ASSERT_VALID_POINTER (XPNTR (ptr->car));
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3828 #endif /* ERROR_CHECK_GC */
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3829
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 #ifndef ALLOC_NO_POOLS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, struct Lisp_Cons, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 #endif /* ALLOC_NO_POOLS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 /* explicitly free a list. You **must make sure** that you have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 created all the cons cells that make up this list and that there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 are no pointers to any of these cons cells anywhere else. If there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 are, you will lose. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 free_list (Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 Lisp_Object rest, next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845 for (rest = list; !NILP (rest); rest = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 next = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 free_cons (XCONS (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 /* explicitly free an alist. You **must make sure** that you have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 created all the cons cells that make up this alist and that there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854 are no pointers to any of these cons cells anywhere else. If there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 are, you will lose. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 free_alist (Lisp_Object alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860 Lisp_Object rest, next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 for (rest = alist; !NILP (rest); rest = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 next = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 free_cons (XCONS (XCAR (rest)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 free_cons (XCONS (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 sweep_compiled_functions (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 #define MARKED_compiled_function_P(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 #define ADDITIONAL_FREE_compiled_function(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878 SWEEP_FIXED_TYPE_BLOCK (compiled_function, struct Lisp_Compiled_Function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 sweep_floats (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 #define MARKED_float_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 #define ADDITIONAL_FREE_float(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 SWEEP_FIXED_TYPE_BLOCK (float, struct Lisp_Float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 sweep_symbols (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 #ifndef LRECORD_SYMBOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 # define MARKED_symbol_P(ptr) XMARKBIT ((ptr)->plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 # define UNMARK_symbol(ptr) do { XUNMARK ((ptr)->plist); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 # define MARKED_symbol_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902 # define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 #endif /* !LRECORD_SYMBOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 #define ADDITIONAL_FREE_symbol(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 SWEEP_FIXED_TYPE_BLOCK (symbol, struct Lisp_Symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 sweep_extents (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912 #define MARKED_extent_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 #define ADDITIONAL_FREE_extent(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920 sweep_events (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 #define MARKED_event_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 #define ADDITIONAL_FREE_event(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 SWEEP_FIXED_TYPE_BLOCK (event, struct Lisp_Event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 sweep_markers (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932 #define MARKED_marker_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934 #define ADDITIONAL_FREE_marker(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 do { Lisp_Object tem; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 XSETMARKER (tem, ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 unchain_marker (tem); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 SWEEP_FIXED_TYPE_BLOCK (marker, struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943 /* Explicitly free a marker. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 free_marker (struct Lisp_Marker *ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948 /* Perhaps this will catch freeing an already-freed marker. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 Lisp_Object temmy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 XSETMARKER (temmy, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 assert (GC_MARKERP (temmy));
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3952 #endif /* ERROR_CHECK_GC */
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3953
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 #ifndef ALLOC_NO_POOLS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, struct Lisp_Marker, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 #endif /* ALLOC_NO_POOLS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3959
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3960 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3961
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3962 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3963 verify_string_chars_integrity (void)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3964 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3965 struct string_chars_block *sb;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3966
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3967 /* Scan each existing string block sequentially, string by string. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3968 for (sb = first_string_chars_block; sb; sb = sb->next)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3969 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3970 int pos = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3971 /* POS is the index of the next string in the block. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3972 while (pos < sb->pos)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3973 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
3974 struct string_chars *s_chars =
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3975 (struct string_chars *) &(sb->string_chars[pos]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3976 struct Lisp_String *string;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3977 int size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3978 int fullsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3979
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3980 /* If the string_chars struct is marked as free (i.e. the STRING
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3981 pointer is 0xFFFFFFFF) then this is an unused chunk of string
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3982 storage. (See below.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3983
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3984 if (FREE_STRUCT_P (s_chars))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3985 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3986 fullsize = ((struct unused_string_chars *) s_chars)->fullsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3987 pos += fullsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3988 continue;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3989 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3990
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3991 string = s_chars->string;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3992 /* Must be 32-bit aligned. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3993 assert ((((int) string) & 3) == 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3994
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3995 size = string_length (string);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3996 fullsize = STRING_FULLSIZE (size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3997
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3998 assert (!BIG_STRING_FULLSIZE_P (fullsize));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
3999 assert (string_data (string) == s_chars->chars);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4000 pos += fullsize;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4001 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4002 assert (pos == sb->pos);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4003 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4004 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4005
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4006 #endif /* MULE && ERROR_CHECK_GC */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4007
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 /* Compactify string chars, relocating the reference to each --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009 free any empty string_chars_block we see. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 compact_string_chars (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 struct string_chars_block *to_sb = first_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 int to_pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 struct string_chars_block *from_sb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4016
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 /* Scan each existing string block sequentially, string by string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020 int from_pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021 /* FROM_POS is the index of the next string in the block. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 while (from_pos < from_sb->pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4023 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4024 struct string_chars *from_s_chars =
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025 (struct string_chars *) &(from_sb->string_chars[from_pos]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026 struct string_chars *to_s_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 struct Lisp_String *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4028 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 int fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 /* If the string_chars struct is marked as free (i.e. the STRING
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032 pointer is 0xFFFFFFFF) then this is an unused chunk of string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033 storage. This happens under Mule when a string's size changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034 in such a way that its fullsize changes. (Strings can change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035 size because a different-length character can be substituted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036 for another character.) In this case, after the bogus string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037 pointer is the "fullsize" of this entry, i.e. how many bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038 to skip. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 if (FREE_STRUCT_P (from_s_chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 from_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 string = from_s_chars->string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 assert (!(FREE_STRUCT_P (string)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 size = string_length (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 fullsize = STRING_FULLSIZE (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 if (BIG_STRING_FULLSIZE_P (fullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 /* Just skip it if it isn't marked. */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4057 #ifdef LRECORD_STRING
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4058 if (! MARKED_RECORD_HEADER_P (&(string->lheader)))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4059 #else
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 if (!XMARKBIT (string->plist))
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4061 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063 from_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067 /* If it won't fit in what's left of TO_SB, close TO_SB out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068 and go on to the next string_chars_block. We know that TO_SB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 cannot advance past FROM_SB here since FROM_SB is large enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 to currently contain this string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 if ((to_pos + fullsize) > countof (to_sb->string_chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 to_sb->pos = to_pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 to_sb = to_sb->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075 to_pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4076 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4077
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078 /* Compute new address of this string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079 and update TO_POS for the space being used. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 /* Copy the string_chars to the new place. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 if (from_s_chars != to_s_chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 memmove (to_s_chars, from_s_chars, fullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 /* Relocate FROM_S_CHARS's reference */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 set_string_data (string, &(to_s_chars->chars[0]));
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4088
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089 from_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090 to_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4094 /* Set current to the last string chars block still used and
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095 free any that follow. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 struct string_chars_block *victim;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 for (victim = to_sb->next; victim; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 struct string_chars_block *next = victim->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 xfree (victim);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103 victim = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 current_string_chars_block = to_sb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107 current_string_chars_block->pos = to_pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 current_string_chars_block->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 #if 1 /* Hack to debug missing purecopy's */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113 static int debug_string_purity;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116 debug_string_purity_print (struct Lisp_String *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118 Charcount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 Charcount s = string_char_length (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120 putc ('\"', stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4121 for (i = 0; i < s; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4122 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4123 Emchar ch = string_char (p, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4124 if (ch < 32 || ch >= 126)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4125 stderr_out ("\\%03o", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4126 else if (ch == '\\' || ch == '\"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4127 stderr_out ("\\%c", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4128 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4129 stderr_out ("%c", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4131 stderr_out ("\"\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4132 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4133 #endif /* 1 */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4136 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 sweep_strings (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139 int num_small_used = 0, num_small_bytes = 0, num_bytes = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140 int debug = debug_string_purity;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4142 #ifdef LRECORD_STRING
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4143
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4144 # define MARKED_string_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4145 # define UNMARK_string(ptr) \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4146 do { struct Lisp_String *p = (ptr); \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4147 int size = string_length (p); \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4148 UNMARK_RECORD_HEADER (&(p->lheader)); \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4149 num_bytes += size; \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4150 if (!BIG_STRING_SIZE_P (size)) \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4151 { num_small_bytes += size; \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4152 num_small_used++; \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4153 } \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4154 if (debug) debug_string_purity_print (p); \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4155 } while (0)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4156 # define ADDITIONAL_FREE_string(p) \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4157 do { int size = string_length (p); \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4158 if (BIG_STRING_SIZE_P (size)) \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4159 xfree_1 (CHARS_TO_STRING_CHAR (string_data (p))); \
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4160 } while (0)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4161
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4162 #else
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4163
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4164 # define MARKED_string_P(ptr) XMARKBIT ((ptr)->plist)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4165 # define UNMARK_string(ptr) \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 do { struct Lisp_String *p = (ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 int size = string_length (p); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168 XUNMARK (p->plist); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 num_bytes += size; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 if (!BIG_STRING_SIZE_P (size)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 { num_small_bytes += size; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172 num_small_used++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 if (debug) debug_string_purity_print (p); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 } while (0)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4176 # define ADDITIONAL_FREE_string(p) \
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177 do { int size = string_length (p); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 if (BIG_STRING_SIZE_P (size)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 xfree_1 (CHARS_TO_STRING_CHAR (string_data (p))); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4182 #endif /* ! LRECORD_STRING */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4183
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184 SWEEP_FIXED_TYPE_BLOCK (string, struct Lisp_String);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 gc_count_num_short_string_in_use = num_small_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 gc_count_string_total_size = num_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188 gc_count_short_string_total_size = num_small_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 /* I hate duplicating all this crap! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 marked_p (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4196 if (EQ (obj, Qnull_pointer)) return 1;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 if (!POINTER_TYPE_P (XGCTYPE (obj))) return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 if (PURIFIED (XPNTR (obj))) return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 switch (XGCTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4201 #ifndef LRECORD_CONS
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4202 case Lisp_Type_Cons:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203 return XMARKBIT (XCAR (obj));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4204 #endif
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4205 case Lisp_Type_Record:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 return MARKED_RECORD_HEADER_P (XRECORD_LHEADER (obj));
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4207 #ifndef LRECORD_STRING
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4208 case Lisp_Type_String:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 return XMARKBIT (XSTRING (obj)->plist);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4210 #endif /* ! LRECORD_STRING */
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4211 #ifndef LRECORD_VECTOR
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4212 case Lisp_Type_Vector:
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4213 return XVECTOR_LENGTH (obj) < 0;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4214 #endif /* !LRECORD_VECTOR */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215 #ifndef LRECORD_SYMBOL
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4216 case Lisp_Type_Symbol:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 return XMARKBIT (XSYMBOL (obj)->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4219 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 return 0; /* suppress compiler warning */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226 gc_sweep (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 /* Free all unmarked records. Do this at the very beginning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 before anything else, so that the finalize methods can safely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 examine items in the objects. sweep_lcrecords_1() makes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231 sure to call all the finalize methods *before* freeing anything,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 to complete the safety. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 int ignored;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235 sweep_lcrecords_1 (&all_lcrecords, &ignored);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4238 compact_string_chars ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4240 /* Finalize methods below (called through the ADDITIONAL_FREE_foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4241 macros) must be *extremely* careful to make sure they're not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 referencing freed objects. The only two existing finalize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243 methods (for strings and markers) pass muster -- the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244 finalizer doesn't look at anything but its own specially-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245 created block, and the marker finalizer only looks at live
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 buffers (which will never be freed) and at the markers before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247 and after it in the chain (which, by induction, will never be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 freed because if so, they would have already removed themselves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249 from the chain). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 /* Put all unmarked strings on free list, free'ing the string chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252 of large unmarked strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 sweep_strings ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255 /* Put all unmarked conses on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 sweep_conses ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4258 #ifndef LRECORD_VECTOR
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259 /* Free all unmarked vectors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 sweep_vectors_1 (&all_vectors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 &gc_count_num_vector_used, &gc_count_vector_total_size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 &gc_count_vector_storage);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4263 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265 /* Free all unmarked bit vectors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266 sweep_bit_vectors_1 (&all_bit_vectors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267 &gc_count_num_bit_vector_used,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 &gc_count_bit_vector_total_size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 &gc_count_bit_vector_storage);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4271 /* Free all unmarked compiled-function objects */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4272 sweep_compiled_functions ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4274 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4275 /* Put all unmarked floats on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4276 sweep_floats ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4277 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4279 /* Put all unmarked symbols on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4280 sweep_symbols ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4282 /* Put all unmarked extents on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4283 sweep_extents ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4285 /* Put all unmarked markers on free list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4286 Dechain each one first from the buffer into which it points. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4287 sweep_markers ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4289 sweep_events ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4291 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4293 /* Clearing for disksave. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4295 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4296 disksave_object_finalization (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4297 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298 /* It's important that certain information from the environment not get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 dumped with the executable (pathnames, environment variables, etc.).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300 To make it easier to tell when this has happend with strings(1) we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4301 clear some known-to-be-garbage blocks of memory, so that leftover
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4302 results of old evaluation don't look like potential problems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 But first we set some notable variables to nil and do one more GC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304 to turn those strings into garbage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4305 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 /* Yeah, this list is pretty ad-hoc... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4308 Vprocess_environment = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4309 Vexec_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310 Vdata_directory = Qnil;
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 108
diff changeset
4311 Vsite_directory = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312 Vdoc_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313 Vconfigure_info_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 Vexec_path = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315 Vload_path = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316 /* Vdump_load_path = Qnil; */
288
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
4317 uncache_home_directory();
e11d67e05968 Import from CVS: tag r21-0b42
cvs
parents: 282
diff changeset
4318
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 211
diff changeset
4319 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 211
diff changeset
4320 defined(LOADHIST_BUILTIN))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4321 Vload_history = Qnil;
233
52952cbfc5b5 Import from CVS: tag r20-5b15
cvs
parents: 211
diff changeset
4322 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 Vshell_file_name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325 garbage_collect_1 ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 /* Run the disksave finalization methods of all live objects. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 disksave_object_finalization_1 ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4330 #if 0 /* I don't see any point in this. The purespace starts out all 0's */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 /* Zero out the unused portion of purespace */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 if (!pure_lossage)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4333 memset ( (char *) (PUREBEG + pure_bytes_used), 0,
171
929b76928fce Import from CVS: tag r20-3b12
cvs
parents: 169
diff changeset
4334 (((char *) (PUREBEG + get_PURESIZE())) -
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4335 ((char *) (PUREBEG + pure_bytes_used))));
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4336 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 /* Zero out the uninitialized (really, unused) part of the containers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 for the live strings. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 struct string_chars_block *scb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 for (scb = first_string_chars_block; scb; scb = scb->next)
249
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4343 {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4344 int count = sizeof (scb->string_chars) - scb->pos;
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4345
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4346 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4347 if (count != 0) {
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4348 /* from the block's fill ptr to the end */
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4349 memset ((scb->string_chars + scb->pos), 0, count);
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4350 }
83b3d10dcba9 Import from CVS: tag r20-5b23
cvs
parents: 247
diff changeset
4351 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 /* There, that ought to be enough... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4359 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4360 restore_gc_inhibit (Lisp_Object val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4361 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4362 gc_currently_forbidden = XINT (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4363 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4364 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366 /* Maybe we want to use this when doing a "panic" gc after memory_full()? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 static int gc_hooks_inhibited;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371 garbage_collect_1 (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 char stack_top_variable;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374 extern char *stack_bottom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 int i;
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
4376 struct frame *f;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4377 int speccount;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4378 int cursor_changed;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4379 Lisp_Object pre_gc_cursor;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4381
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4382 if (gc_in_progress
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4383 || gc_currently_forbidden
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4384 || in_display
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4385 || preparing_for_armageddon)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4386 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4387
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4388 pre_gc_cursor = Qnil;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4389 cursor_changed = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4390
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
4391 /* This function cannot be called inside GC so we move to after the */
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
4392 /* above tests */
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
4393 f = selected_frame ();
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
4394
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4395 GCPRO1 (pre_gc_cursor);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4397 /* Very important to prevent GC during any of the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4398 stuff that might run Lisp code; otherwise, we'll likely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4399 have infinite GC recursion. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4400 speccount = specpdl_depth ();
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4401 record_unwind_protect (restore_gc_inhibit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4402 make_int (gc_currently_forbidden));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4403 gc_currently_forbidden = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4405 if (!gc_hooks_inhibited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4406 run_hook_trapping_errors ("Error in pre-gc-hook", Qpre_gc_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4408 /* Now show the GC cursor/message. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4409 if (!noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4410 {
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4411 if (FRAME_WIN_P (f))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4412 {
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4413 Lisp_Object frame = make_frame (f);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4414 Lisp_Object cursor = glyph_image_instance (Vgc_pointer_glyph,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4415 FRAME_SELECTED_WINDOW (f),
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4416 ERROR_ME_NOT, 1);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4417 pre_gc_cursor = f->pointer;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4418 if (POINTER_IMAGE_INSTANCEP (cursor)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4419 /* don't change if we don't know how to change back. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4420 && POINTER_IMAGE_INSTANCEP (pre_gc_cursor))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 {
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4422 cursor_changed = 1;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4423 Fset_frame_pointer (frame, cursor);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425 }
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4426
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4427 /* Don't print messages to the stream device. */
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4428 if (!cursor_changed && !FRAME_STREAM_P (f))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4429 {
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4430 char *msg = (STRINGP (Vgc_message)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4431 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4432 : 0);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4433 Lisp_Object args[2], whole_msg;
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4434 args[0] = build_string (msg ? msg :
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4435 GETTEXT ((CONST char *) gc_default_message));
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4436 args[1] = build_string ("...");
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4437 whole_msg = Fconcat (2, args);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4438 echo_area_message (f, (Bufbyte *) 0, whole_msg, 0, -1,
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4439 Qgarbage_collecting);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4440 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4441 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4443 /***** Now we actually start the garbage collection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 gc_in_progress = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4447 gc_generation_number[0]++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4449 #if MAX_SAVE_STACK > 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451 /* Save a copy of the contents of the stack, for debugging. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4452 if (!purify_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4454 /* Static buffer in which we save a copy of the C stack at each GC. */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4455 static char *stack_copy;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4456 static size_t stack_copy_size;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4457
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4458 ptrdiff_t stack_diff = &stack_top_variable - stack_bottom;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4459 size_t stack_size = (stack_diff > 0 ? stack_diff : -stack_diff);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4460 if (stack_size < MAX_SAVE_STACK)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4462 if (stack_copy_size < stack_size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4464 stack_copy = (char *) xrealloc (stack_copy, stack_size);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4465 stack_copy_size = stack_size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4466 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4467
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4468 memcpy (stack_copy,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4469 stack_diff > 0 ? stack_bottom : &stack_top_variable,
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4470 stack_size);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 #endif /* MAX_SAVE_STACK > 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 /* Do some totally ad-hoc resource clearing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 /* #### generalize this? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477 clear_event_resource ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478 cleanup_specifiers ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4480 /* Mark all the special slots that serve as the roots of accessibility. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 struct gcpro *tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483 struct catchtag *catch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484 struct backtrace *backlist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 struct specbinding *bind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 for (i = 0; i < staticidx; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4489 #ifdef GDB_SUCKS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490 printf ("%d\n", i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 debug_print (*staticvec[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 mark_object (*(staticvec[i]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496 for (tail = gcprolist; tail; tail = tail->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498 for (i = 0; i < tail->nvars; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 mark_object (tail->var[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4502 for (bind = specpdl; bind != specpdl_ptr; bind++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 mark_object (bind->symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 mark_object (bind->old_value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4508 for (catch = catchlist; catch; catch = catch->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 mark_object (catch->tag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 mark_object (catch->val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 for (backlist = backtrace_list; backlist; backlist = backlist->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 int nargs = backlist->nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4518 mark_object (*backlist->function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4519 if (nargs == UNEVALLED || nargs == MANY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520 mark_object (backlist->args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 for (i = 0; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523 mark_object (backlist->args[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4526 mark_redisplay (mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4527 mark_profiling_info (mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4528 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4530 /* OK, now do the after-mark stuff. This is for things that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4531 are only marked when something else is marked (e.g. weak hashtables).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4532 There may be complex dependencies between such objects -- e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4533 a weak hashtable might be unmarked, but after processing a later
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4534 weak hashtable, the former one might get marked. So we have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4535 iterate until nothing more gets marked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4536 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4537 int did_mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4538 /* Need to iterate until there's nothing more to mark, in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4539 of chains of mark dependencies. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4540 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542 did_mark = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543 did_mark += !!finish_marking_weak_hashtables (marked_p, mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 did_mark += !!finish_marking_weak_lists (marked_p, mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 while (did_mark);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4547 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549 /* And prune (this needs to be called after everything else has been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550 marked and before we do any sweeping). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551 /* #### this is somewhat ad-hoc and should probably be an object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552 method */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 prune_weak_hashtables (marked_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554 prune_weak_lists (marked_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 prune_specifiers (marked_p);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents: 48
diff changeset
4556 prune_syntax_tables (marked_p);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 gc_sweep ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560 consing_since_gc = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 #ifndef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4562 /* Allow you to set it really fucking low if you really want ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563 if (gc_cons_threshold < 10000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564 gc_cons_threshold = 10000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567 gc_in_progress = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569 /******* End of garbage collection ********/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 run_hook_trapping_errors ("Error in post-gc-hook", Qpost_gc_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573 /* Now remove the GC cursor/message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574 if (!noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 {
163
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4576 if (cursor_changed)
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4577 Fset_frame_pointer (make_frame (f), pre_gc_cursor);
0132846995bd Import from CVS: tag r20-3b8
cvs
parents: 161
diff changeset
4578 else if (!FRAME_STREAM_P (f))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580 char *msg = (STRINGP (Vgc_message)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
4581 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 : 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 /* Show "...done" only if the echo area would otherwise be empty. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4585 if (NILP (clear_echo_area (selected_frame (),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586 Qgarbage_collecting, 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588 Lisp_Object args[2], whole_msg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 args[0] = build_string (msg ? msg :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 GETTEXT ((CONST char *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591 gc_default_message));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4592 args[1] = build_string ("... done");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4593 whole_msg = Fconcat (2, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4594 echo_area_message (selected_frame (), (Bufbyte *) 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4595 whole_msg, 0, -1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 Qgarbage_collecting);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601 /* now stop inhibiting GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4604 if (!breathing_space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4606 breathing_space = malloc (4096 - MALLOC_OVERHEAD);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4609 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4613 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 /* This isn't actually called. BTL recognizes the stack frame of the top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615 of the garbage collector by noting that PC is between &garbage_collect_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616 and &BTL_after_garbage_collect_1_stub. So this fn must be right here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 There's not any other way to know the address of the end of a function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 void BTL_after_garbage_collect_1_stub () { abort (); }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4620 #endif /* EMACS_BTL */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 /* Debugging aids. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4624 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 gc_plist_hack (CONST char *name, int value, Lisp_Object tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 /* C doesn't have local functions (or closures, or GC, or readable syntax,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628 or portable numeric datatypes, or bit-vectors, or characters, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4629 arrays, or exceptions, or ...) */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4630 return cons3 (intern (name), make_int (value), tail);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4631 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633 #define HACK_O_MATIC(type, name, pl) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635 int s = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4636 struct type##_block *x = current_##type##_block; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4637 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4638 (pl) = gc_plist_hack ((name), s, (pl)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4639 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4640
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4641 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4642 Reclaim storage for Lisp objects no longer needed.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4643 Return info on amount of space in use:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4644 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4645 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4646 PLIST)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4647 where `PLIST' is a list of alternating keyword/value pairs providing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4648 more detailed information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4649 Garbage collection happens automatically if you cons more than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4650 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4651 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4652 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4653 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4654 Lisp_Object pl = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4655 int i;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4656 #ifdef LRECORD_VECTOR
243
f220cc83d72e Import from CVS: tag r20-5b20
cvs
parents: 233
diff changeset
4657 int gc_count_vector_total_size = 0;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4658 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4659
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4660 if (purify_flag && pure_lossage)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4661 return Qnil;
104
cf808b4c4290 Import from CVS: tag r20-1b4
cvs
parents: 102
diff changeset
4662
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4663 garbage_collect_1 ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4665 for (i = 0; i < last_lrecord_type_index_assigned; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4666 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4667 if (lcrecord_stats[i].bytes_in_use != 0
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4668 || lcrecord_stats[i].bytes_freed != 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4669 || lcrecord_stats[i].instances_on_free_list != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4670 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4671 char buf [255];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4672 CONST char *name = lrecord_implementations_table[i]->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4673 int len = strlen (name);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4674 #ifdef LRECORD_VECTOR
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4675 /* save this for the FSFmacs-compatible part of the summary */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4676 if (i == *lrecord_vector[0].lrecord_type_index)
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4677 gc_count_vector_total_size =
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4678 lcrecord_stats[i].bytes_in_use + lcrecord_stats[i].bytes_freed;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4679 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4680 sprintf (buf, "%s-storage", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4681 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4682 /* Okay, simple pluralization check for `symbol-value-varalias' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4683 if (name[len-1] == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4684 sprintf (buf, "%ses-freed", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4685 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4686 sprintf (buf, "%ss-freed", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4687 if (lcrecord_stats[i].instances_freed != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4688 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4689 if (name[len-1] == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4690 sprintf (buf, "%ses-on-free-list", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4691 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4692 sprintf (buf, "%ss-on-free-list", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4693 if (lcrecord_stats[i].instances_on_free_list != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4694 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4695 pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4696 if (name[len-1] == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4697 sprintf (buf, "%ses-used", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4698 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4699 sprintf (buf, "%ss-used", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4700 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4701 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4702 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4704 HACK_O_MATIC (extent, "extent-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4705 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4706 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4707 HACK_O_MATIC (event, "event-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4708 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4709 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4710 HACK_O_MATIC (marker, "marker-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4711 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4712 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4713 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4714 HACK_O_MATIC (float, "float-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4715 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4716 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4717 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4718 HACK_O_MATIC (string, "string-header-storage", pl);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4719 pl = gc_plist_hack ("long-strings-total-length",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4720 gc_count_string_total_size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4721 - gc_count_short_string_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4722 HACK_O_MATIC (string_chars, "short-string-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4723 pl = gc_plist_hack ("short-strings-total-length",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4724 gc_count_short_string_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4725 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4726 pl = gc_plist_hack ("long-strings-used",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4727 gc_count_num_string_in_use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4728 - gc_count_num_short_string_in_use, pl);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4729 pl = gc_plist_hack ("short-strings-used",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4730 gc_count_num_short_string_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4732 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4733 pl = gc_plist_hack ("compiled-functions-free",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4734 gc_count_num_compiled_function_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4735 pl = gc_plist_hack ("compiled-functions-used",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4736 gc_count_num_compiled_function_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4737
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4738 #ifndef LRECORD_VECTOR
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4739 pl = gc_plist_hack ("vector-storage", gc_count_vector_storage, pl);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4740 pl = gc_plist_hack ("vectors-total-length",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4741 gc_count_vector_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4742 pl = gc_plist_hack ("vectors-used", gc_count_num_vector_used, pl);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4743 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4745 pl = gc_plist_hack ("bit-vector-storage", gc_count_bit_vector_storage, pl);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4746 pl = gc_plist_hack ("bit-vectors-total-length",
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4747 gc_count_bit_vector_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4748 pl = gc_plist_hack ("bit-vectors-used", gc_count_num_bit_vector_used, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4750 HACK_O_MATIC (symbol, "symbol-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4751 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4752 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4754 HACK_O_MATIC (cons, "cons-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4755 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4756 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4758 /* The things we do for backwards-compatibility */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4759 return
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4760 list6 (Fcons (make_int (gc_count_num_cons_in_use),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4761 make_int (gc_count_num_cons_freelist)),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4762 Fcons (make_int (gc_count_num_symbol_in_use),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4763 make_int (gc_count_num_symbol_freelist)),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4764 Fcons (make_int (gc_count_num_marker_in_use),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4765 make_int (gc_count_num_marker_freelist)),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4766 make_int (gc_count_string_total_size),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4767 make_int (gc_count_vector_total_size),
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4768 pl);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4769 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4770 #undef HACK_O_MATIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4771
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4772 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4773 Return the number of bytes consed since the last garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4774 \"Consed\" is a misnomer in that this actually counts allocation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4775 of all different kinds of objects, not just conses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4777 If this value exceeds `gc-cons-threshold', a garbage collection happens.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4778 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4779 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4780 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4781 return make_int (consing_since_gc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4782 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4783
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4784 DEFUN ("memory-limit", Fmemory_limit, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4785 Return the address of the last byte Emacs has allocated, divided by 1024.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4786 This may be helpful in debugging Emacs's memory usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4787 The value is divided by 1024 to make sure it will fit in a lisp integer.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4788 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4789 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4790 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4791 return make_int ((EMACS_INT) sbrk (0) / 1024);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4792 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4796 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4797 object_dead_p (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4798 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4799 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) ||
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4800 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) ||
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4801 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) ||
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4802 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) ||
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4803 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) ||
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4804 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) ||
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 171
diff changeset
4805 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj))));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4806 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4808 #ifdef MEMORY_USAGE_STATS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4810 /* Attempt to determine the actual amount of space that is used for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4811 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4813 It seems that the following holds:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4815 1. When using the old allocator (malloc.c):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4817 -- blocks are always allocated in chunks of powers of two. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4818 each block, there is an overhead of 8 bytes if rcheck is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4819 defined, 20 bytes if it is defined. In other words, a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4820 one-byte allocation needs 8 bytes of overhead for a total of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4821 9 bytes, and needs to have 16 bytes of memory chunked out for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4822 it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4824 2. When using the new allocator (gmalloc.c):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4826 -- blocks are always allocated in chunks of powers of two up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4827 to 4096 bytes. Larger blocks are allocated in chunks of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4828 an integral multiple of 4096 bytes. The minimum block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4829 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4830 is defined. There is no per-block overhead, but there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4831 is an overhead of 3*sizeof (size_t) for each 4096 bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4832 allocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4834 3. When using the system malloc, anything goes, but they are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4835 generally slower and more space-efficient than the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4836 allocators. One possibly reasonable assumption to make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4837 for want of better data is that sizeof (void *), or maybe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4838 2 * sizeof (void *), is required as overhead and that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4839 blocks are allocated in the minimum required size except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4840 that some minimum block size is imposed (e.g. 16 bytes). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4841
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4842 size_t
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4843 malloced_storage_size (void *ptr, size_t claimed_size,
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4844 struct overhead_stats *stats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4845 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4846 size_t orig_claimed_size = claimed_size;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4847
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4848 #ifdef GNU_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4850 if (claimed_size < 2 * sizeof (void *))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4851 claimed_size = 2 * sizeof (void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4852 # ifdef SUNOS_LOCALTIME_BUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4853 if (claimed_size < 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4854 claimed_size = 16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4855 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4856 if (claimed_size < 4096)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4857 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4858 int log = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4860 /* compute the log base two, more or less, then use it to compute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4861 the block size needed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4862 claimed_size--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4863 /* It's big, it's heavy, it's wood! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4864 while ((claimed_size /= 2) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4865 ++log;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4866 claimed_size = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4867 /* It's better than bad, it's good! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4868 while (log > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4869 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4870 claimed_size *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4871 log--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4872 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4873 /* We have to come up with some average about the amount of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4874 blocks used. */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4875 if ((size_t) (rand () & 4095) < claimed_size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4876 claimed_size += 3 * sizeof (void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4877 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4878 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4879 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4880 claimed_size += 4095;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4881 claimed_size &= ~4095;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4882 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4883 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4885 #elif defined (SYSTEM_MALLOC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4887 if (claimed_size < 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4888 claimed_size = 16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4889 claimed_size += 2 * sizeof (void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4891 #else /* old GNU allocator */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4892
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4893 # ifdef rcheck /* #### may not be defined here */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4894 claimed_size += 20;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4895 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4896 claimed_size += 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4897 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4898 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4899 int log = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4901 /* compute the log base two, more or less, then use it to compute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4902 the block size needed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4903 claimed_size--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4904 /* It's big, it's heavy, it's wood! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4905 while ((claimed_size /= 2) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4906 ++log;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4907 claimed_size = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4908 /* It's better than bad, it's good! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4909 while (log > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4910 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4911 claimed_size *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4912 log--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4913 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4914 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4916 #endif /* old GNU allocator */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4918 if (stats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4919 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4920 stats->was_requested += orig_claimed_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4921 stats->malloc_overhead += claimed_size - orig_claimed_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4922 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4923 return claimed_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4924 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4925
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4926 size_t
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4927 fixed_type_block_overhead (size_t size)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4928 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4929 size_t per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4930 size_t overhead = 0;
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4931 size_t storage_size = malloced_storage_size (0, per_block, 0);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4932 while (size >= per_block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4933 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4934 size -= per_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4935 overhead += sizeof (void *) + per_block - storage_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4936 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4937 if (rand () % per_block < size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4938 overhead += sizeof (void *) + per_block - storage_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4939 return overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4940 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4942 #endif /* MEMORY_USAGE_STATS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4945 /* Initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4946 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4947 init_alloc_once_early (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4948 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4949 int iii;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4951 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4952 for (iii = 0; iii < countof (purestats); iii++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4953 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4954 if (! purestats[iii]) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4955 purestats[iii]->nobjects = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4956 purestats[iii]->nbytes = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4957 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4958 purecopying_for_bytecode = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4959 #endif /* PURESTAT */
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4960
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4961 last_lrecord_type_index_assigned = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4962 for (iii = 0; iii < countof (lrecord_implementations_table); iii++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4963 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4964 lrecord_implementations_table[iii] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4965 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4966
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4967 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4968 /*
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4969 * If USE_INDEXED_LRECORD_IMPLEMENTATION is defined, all the staticly
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4970 * defined subr lrecords were initialized with lheader->type == 0.
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4971 * See subr_lheader_initializer in lisp.h. Force type index 0 to be
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4972 * assigned to lrecord_subr so that those predefined indexes match
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4973 * reality.
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4974 */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4975 lrecord_type_index (lrecord_subr);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4976 assert (*(lrecord_subr[0].lrecord_type_index) == 0);
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4977 /*
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4978 * The same is true for symbol_value_forward objects, except the
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4979 * type is 1.
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4980 */
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4981 lrecord_type_index (lrecord_symbol_value_forward);
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4982 assert (*(lrecord_symbol_value_forward[0].lrecord_type_index) == 1);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4983 #endif /* USE_INDEXED_LRECORD_IMPLEMENTATION */
211
78478c60bfcd Import from CVS: tag r20-4b4
cvs
parents: 207
diff changeset
4984
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4985 symbols_initialized = 0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
4986
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4987 gc_generation_number[0] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4988 /* purify_flag 1 is correct even if CANNOT_DUMP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4989 * loadup.el will set to nil at end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4990 purify_flag = 1;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4991 pure_bytes_used = 0;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4992 pure_lossage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4993 breathing_space = 0;
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4994 #ifndef LRECORD_VECTOR
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4995 XSETINT (all_vectors, 0); /* Qzero may not be set yet. */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 195
diff changeset
4996 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4997 XSETINT (all_bit_vectors, 0); /* Qzero may not be set yet. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4998 XSETINT (Vgc_message, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4999 all_lcrecords = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5000 ignore_malloc_warnings = 1;
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
5001 #ifdef DOUG_LEA_MALLOC
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
5002 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
5003 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
5004 #if 0 /* Moved to emacs.c */
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
5005 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 255
diff changeset
5006 #endif
255
084402c475ba Import from CVS: tag r20-5b26
cvs
parents: 251
diff changeset
5007 #endif
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5008 init_string_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5009 init_string_chars_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5010 init_cons_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5011 init_symbol_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5012 init_compiled_function_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5013 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5014 init_float_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5015 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5016 init_marker_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5017 init_extent_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5018 init_event_alloc ();
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
5019
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5020 ignore_malloc_warnings = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5021 staticidx = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5022 consing_since_gc = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5023 #if 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5024 gc_cons_threshold = 500000; /* XEmacs change */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5025 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5026 gc_cons_threshold = 15000; /* debugging */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5027 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5028 #ifdef VIRT_ADDR_VARIES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5029 malloc_sbrk_unused = 1<<22; /* A large number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5030 malloc_sbrk_used = 100000; /* as reasonable as any number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5031 #endif /* VIRT_ADDR_VARIES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5032 lrecord_uid_counter = 259;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5033 debug_string_purity = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5034 gcprolist = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5036 gc_currently_forbidden = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5037 gc_hooks_inhibited = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5039 #ifdef ERROR_CHECK_TYPECHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5040 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5041 666;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5042 ERROR_ME_NOT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5043 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5044 ERROR_ME_WARN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5045 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5046 3333632;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 177
diff changeset
5047 #endif /* ERROR_CHECK_TYPECHECK */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5048 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5050 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5051 reinit_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5052 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5053 gcprolist = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5054 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5056 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5057 syms_of_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5058 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5059 defsymbol (&Qpre_gc_hook, "pre-gc-hook");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5060 defsymbol (&Qpost_gc_hook, "post-gc-hook");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5061 defsymbol (&Qgarbage_collecting, "garbage-collecting");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5062
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5063 DEFSUBR (Fcons);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5064 DEFSUBR (Flist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5065 DEFSUBR (Fvector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5066 DEFSUBR (Fbit_vector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5067 DEFSUBR (Fmake_byte_code);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5068 DEFSUBR (Fmake_list);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5069 DEFSUBR (Fmake_vector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5070 DEFSUBR (Fmake_bit_vector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5071 DEFSUBR (Fmake_string);
278
90d73dddcdc4 Import from CVS: tag r21-0b37
cvs
parents: 274
diff changeset
5072 DEFSUBR (Fstring);
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5073 DEFSUBR (Fmake_symbol);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5074 DEFSUBR (Fmake_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5075 DEFSUBR (Fpurecopy);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5076 DEFSUBR (Fgarbage_collect);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5077 DEFSUBR (Fmemory_limit);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
5078 DEFSUBR (Fconsing_since_gc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5079 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5080
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5081 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5082 vars_of_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5083 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5084 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5085 *Number of bytes of consing between garbage collections.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5086 \"Consing\" is a misnomer in that this actually counts allocation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5087 of all different kinds of objects, not just conses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5088 Garbage collection can happen automatically once this many bytes have been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5089 allocated since the last garbage collection. All data types count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5090
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5091 Garbage collection happens automatically when `eval' or `funcall' are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5092 called. (Note that `funcall' is called implicitly as part of evaluation.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5093 By binding this temporarily to a large number, you can effectively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5094 prevent garbage collection during a part of the program.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5096 See also `consing-since-gc'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5097 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5098
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5099 DEFVAR_INT ("pure-bytes-used", &pure_bytes_used /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5100 Number of bytes of sharable Lisp data allocated so far.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5101 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5103 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5104 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5105 Number of bytes of unshared memory allocated in this session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5106 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5108 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5109 Number of bytes of unshared memory remaining available in this session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5110 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5111 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5113 #ifdef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5114 DEFVAR_INT ("debug-allocation", &debug_allocation /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5115 If non-zero, print out information to stderr about all objects allocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5116 See also `debug-allocation-backtrace-length'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5117 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5118 debug_allocation = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5120 DEFVAR_INT ("debug-allocation-backtrace-length",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5121 &debug_allocation_backtrace_length /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5122 Length (in stack frames) of short backtrace printed out by `debug-allocation'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5123 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5124 debug_allocation_backtrace_length = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5125 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5127 DEFVAR_BOOL ("purify-flag", &purify_flag /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5128 Non-nil means loading Lisp code in order to dump an executable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5129 This means that certain objects should be allocated in shared (pure) space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5130 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5132 DEFVAR_LISP ("pre-gc-hook", &Vpre_gc_hook /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5133 Function or functions to be run just before each garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5134 Interrupts, garbage collection, and errors are inhibited while this hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5135 runs, so be extremely careful in what you add here. In particular, avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5136 consing, and do not interact with the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5137 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5138 Vpre_gc_hook = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5140 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5141 Function or functions to be run just after each garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5142 Interrupts, garbage collection, and errors are inhibited while this hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5143 runs, so be extremely careful in what you add here. In particular, avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5144 consing, and do not interact with the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5145 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5146 Vpost_gc_hook = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5148 DEFVAR_LISP ("gc-message", &Vgc_message /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5149 String to print to indicate that a garbage collection is in progress.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5150 This is printed in the echo area. If the selected frame is on a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5151 window system and `gc-pointer-glyph' specifies a value (i.e. a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5152 image instance) in the domain of the selected frame, the mouse pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5153 will change instead of this message being printed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5154 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5155 Vgc_message = make_pure_string ((CONST Bufbyte *) gc_default_message,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5156 countof (gc_default_message) - 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5157 Qnil, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5159 DEFVAR_LISP ("gc-pointer-glyph", &Vgc_pointer_glyph /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5160 Pointer glyph used to indicate that a garbage collection is in progress.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5161 If the selected window is on a window system and this glyph specifies a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5162 value (i.e. a pointer image instance) in the domain of the selected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5163 window, the pointer will be changed as specified during garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5164 Otherwise, a message will be printed in the echo area, as controlled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5165 by `gc-message'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5166 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5167 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5169 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5170 complex_vars_of_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5171 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5172 Vgc_pointer_glyph = Fmake_glyph_internal (Qpointer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5173 }