annotate src/alloc.c @ 32:e04119814345 r19-15b99

Import from CVS: tag r19-15b99
author cvs
date Mon, 13 Aug 2007 08:52:56 +0200
parents ec9a17fef872
children d620409f5eb8
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.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 Copyright (C) 1995, 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 /* Authorship:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 FSF: Original version; a long time ago.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 Mly: Significantly rewritten to use new 3-bit tags and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 nicely abstracted object definitions, for 19.8.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 JWZ: Improved code to keep track of purespace usage and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 issue nice purespace and GC stats.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 Ben Wing: Cleaned up frob-block lrecord code, added error-checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 and various changes for Mule, for 19.12.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Added bit vectors for 19.13.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 Added lcrecord lists for 19.14.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 #ifndef standalone
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"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 #include "device.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #include "elhash.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 #include "events.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #include "extents.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #include "frame.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #include "glyphs.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #include "redisplay.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 #include "specifier.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 #include "window.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 /* #define GDB_SUCKS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* #define VERIFY_STRING_CHARS_INTEGRITY */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 /* Define this to see where all that space is going... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 #define PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 /* Define this to use malloc/free with no freelist for all datatypes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 the hope being that some debugging tools may help detect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 freed memory references */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 /* #define ALLOC_NO_POOLS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 #include "puresize.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 #ifdef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 int debug_allocation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 int debug_allocation_backtrace_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 /* Number of bytes of consing done since the last gc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 EMACS_INT consing_since_gc;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 extern void cadillac_record_backtrace ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 #define INCREMENT_CONS_COUNTER_1(size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 consing_since_gc += __sz__; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 cadillac_record_backtrace (2, __sz__); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 #define INCREMENT_CONS_COUNTER_1(size) (consing_since_gc += (size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 #define debug_allocation_backtrace() \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 if (debug_allocation_backtrace_length > 0) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 debug_short_backtrace (debug_allocation_backtrace_length); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 #ifdef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 #define INCREMENT_CONS_COUNTER(foosize, type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 if (debug_allocation) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 stderr_out ("allocating %s (size %ld)\n", type, (long)foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 debug_allocation_backtrace (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 INCREMENT_CONS_COUNTER_1 (foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 if (debug_allocation > 1) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 stderr_out ("allocating noseeum %s (size %ld)\n", type, (long)foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 debug_allocation_backtrace (); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 INCREMENT_CONS_COUNTER_1 (foosize); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 #define INCREMENT_CONS_COUNTER(size, type) INCREMENT_CONS_COUNTER_1 (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 #define NOSEEUM_INCREMENT_CONS_COUNTER(size, type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 INCREMENT_CONS_COUNTER_1 (size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 #define DECREMENT_CONS_COUNTER(size) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 if (consing_since_gc >= __sz__) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 consing_since_gc -= __sz__; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 consing_since_gc = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 /* Number of bytes of consing since gc before another gc should be done. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 EMACS_INT gc_cons_threshold;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 /* Nonzero during gc */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 int gc_in_progress;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 /* Number of times GC has happened at this level or below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 * Level 0 is most volatile, contrary to usual convention.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 * (Of course, there's only one level at present) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 EMACS_INT gc_generation_number[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 /* 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
144 static int lrecord_uid_counter;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 /* Nonzero when calling certain hooks or doing other things where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 a GC would be bad */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 int gc_currently_forbidden;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 /* Hooks. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 Lisp_Object Vpre_gc_hook, Qpre_gc_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 Lisp_Object Vpost_gc_hook, Qpost_gc_hook;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 /* "Garbage collecting" */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 Lisp_Object Vgc_message;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 Lisp_Object Vgc_pointer_glyph;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 static CONST char gc_default_message[] = "Garbage collecting";
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 Lisp_Object Qgarbage_collecting;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 #ifndef VIRT_ADDR_VARIES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 extern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 #endif /* VIRT_ADDR_VARIES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 EMACS_INT malloc_sbrk_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 #ifndef VIRT_ADDR_VARIES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 extern
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 #endif /* VIRT_ADDR_VARIES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 EMACS_INT malloc_sbrk_unused;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 /* Non-zero means defun should do purecopy on the function definition */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 int purify_flag;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 extern Lisp_Object pure[];/* moved to pure.c to speed incremental linking */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 #define PUREBEG ((unsigned char *) pure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 /* Index in pure at which next pure object will be allocated. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 static long pureptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 #define PURIFIED(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ((PNTR_COMPARISON_TYPE) (ptr) < \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (PNTR_COMPARISON_TYPE) (PUREBEG + PURESIZE) && \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (PNTR_COMPARISON_TYPE) (ptr) >= \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (PNTR_COMPARISON_TYPE) PUREBEG)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 /* Non-zero if pureptr > PURESIZE; accounts for excess purespace needs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 static long pure_lossage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 #ifdef ERROR_CHECK_TYPECHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 Error_behavior ERROR_ME, ERROR_ME_NOT, ERROR_ME_WARN;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 purified (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 if (!POINTER_TYPE_P (XGCTYPE (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 return (PURIFIED (XPNTR (obj)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 purespace_usage (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 return (int) pureptr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 check_purespace (EMACS_INT size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 if (pure_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 pure_lossage += size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 else if (pureptr + size > PURESIZE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 {
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
219 /* This can cause recursive bad behavior, we'll yell at the end */
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
220 /* when we're done. */
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
221 /* message ("\nERROR: Pure Lisp storage exhausted!\n"); */
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 pure_lossage = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 return (0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 return (1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 #ifndef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 #define bump_purestat(p,b) do {} while (0) /* Do nothing */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 #else /* PURESTAT */
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 purecopying_for_bytecode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 static int pure_sizeof (Lisp_Object /*, int recurse */);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 /* Keep statistics on how much of what is in purespace */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 struct purestat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 int nobjects;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 int nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 CONST char *name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 #define FMH(s,n) static struct purestat s = { 0, 0, n }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 FMH (purestat_cons, "cons cells:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 FMH (purestat_float, "float objects:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 FMH (purestat_string_pname, "symbol-name strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 FMH (purestat_bytecode, "compiled-function objects:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 FMH (purestat_string_bytecodes, "byte-code strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 FMH (purestat_vector_bytecode_constants, "byte-constant vectors:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 FMH (purestat_string_interactive, "interactive strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 FMH (purestat_string_domain, "domain strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 FMH (purestat_string_documentation, "documentation strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 FMH (purestat_string_other_function, "other function strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 FMH (purestat_vector_other, "other vectors:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 FMH (purestat_string_other, "other strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 FMH (purestat_string_all, "all strings:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 FMH (purestat_vector_all, "all vectors:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 static struct purestat *purestats[] =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 &purestat_cons,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 &purestat_float,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 &purestat_string_pname,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 &purestat_bytecode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 &purestat_string_bytecodes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 &purestat_vector_bytecode_constants,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 &purestat_string_interactive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 &purestat_string_domain,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 &purestat_string_documentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 &purestat_string_other_function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 &purestat_vector_other,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 &purestat_string_other,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 &purestat_string_all,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 &purestat_vector_all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 #undef FMH
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 bump_purestat (struct purestat *purestat, int nbytes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 if (pure_lossage) return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 purestat->nobjects += 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 purestat->nbytes += nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 /* Maximum amount of C stack to save when a GC happens. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 #ifndef MAX_SAVE_STACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 #define MAX_SAVE_STACK 16000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 /* Buffer in which we save a copy of the C stack at each GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 static char *stack_copy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 static int stack_copy_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 /* Non-zero means ignore malloc warnings. Set during initialization. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 int ignore_malloc_warnings;
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 *breathing_space;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 release_breathing_space (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 if (breathing_space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 void *tmp = breathing_space;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 breathing_space = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 xfree (tmp);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 /* malloc calls this if it finds we are near exhausting storage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 malloc_warning (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 if (ignore_malloc_warnings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 warn_when_safe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (Qmemory, Qcritical,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 "%s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 "Killing some buffers may delay running out of memory.\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 "However, certainly by the time you receive the 95%% warning,\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 "you should clean up, kill this Emacs, and start a new one.",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 /* Called if malloc returns zero */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 DOESNT_RETURN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 memory_full (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 /* Force a GC next time eval is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 It's better to loop garbage-collecting (we might reclaim enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 to win) than to loop beeping and barfing "Memory exhausted"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 consing_since_gc = gc_cons_threshold + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 release_breathing_space ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 #ifndef standalone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 /* Flush some histories which might conceivably contain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 * garbalogical inhibitors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 if (!NILP (Fboundp (Qvalues)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 Fset (Qvalues, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 Vcommand_history = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 error ("Memory exhausted");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 /* like malloc and realloc but check for no memory left, and block input. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 xmalloc (int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 void *val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 val = (void *) malloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 if (!val && (size != 0)) memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 xmalloc_and_zero (int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 void *val = xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 memset (val, 0, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 xrealloc (void *block, int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 void *val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 /* We must call malloc explicitly when BLOCK is 0, since some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 reallocs don't do this. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 if (! block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 val = (void *) malloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 val = (void *) realloc (block, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 if (!val && (size != 0)) memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 #ifdef ERROR_CHECK_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 xfree_1 (void *block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 xfree (void *block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 #ifdef ERROR_CHECK_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 error until much later on for many system mallocs, such as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 the one that comes with Solaris 2.3. FMH!! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 assert (block != (void *) 0xDEADBEEF);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 assert (block);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 free (block);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 #if INTBITS == 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 # define FOUR_BYTE_TYPE unsigned int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 #elif LONGBITS == 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 # define FOUR_BYTE_TYPE unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 #elif SHORTBITS == 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 # define FOUR_BYTE_TYPE unsigned short
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 What kind of strange-ass system are we running on?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 #ifdef WORDS_BIGENDIAN
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 static unsigned char deadbeef_as_char[] = {0xDE, 0xAD, 0xBE, 0xEF};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 static unsigned char deadbeef_as_char[] = {0xEF, 0xBE, 0xAD, 0xDE};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 deadbeef_memory (void *ptr, unsigned long size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 unsigned long long_length = size / sizeof (FOUR_BYTE_TYPE);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 unsigned long i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 unsigned long bytes_left_over = size - sizeof (FOUR_BYTE_TYPE) * long_length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 for (i = 0; i < long_length; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ((FOUR_BYTE_TYPE *) ptr)[i] = 0xdeadbeef;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 for (i = i; i < bytes_left_over; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ((unsigned char *) ptr + long_length)[i] = deadbeef_as_char[i];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 #define deadbeef_memory(ptr, size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 xstrdup (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 char *val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 int len = strlen (str) + 1; /* for stupid terminating 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 val = xmalloc (len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 if (val == 0) return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 memcpy (val, str, len);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 return (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 #ifdef NEED_STRDUP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 char *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 strdup (CONST char *s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 return xstrdup (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 #endif /* NEED_STRDUP */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 static void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 allocate_lisp_storage (int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 void *p = xmalloc (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 char *lim = ((char *) p) + size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 Lisp_Object val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 XSETCONS (val, lim);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 if ((char *) XCONS (val) != lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 xfree (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 memory_full ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 return (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 #define MARKED_RECORD_HEADER_P(lheader) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (((lheader)->implementation->finalizer) == this_marks_a_marked_record)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 #define UNMARKABLE_RECORD_HEADER_P(lheader) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (((lheader)->implementation->marker) == this_one_is_unmarkable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 #define MARK_RECORD_HEADER(lheader) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 do { (((lheader)->implementation)++); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 #define UNMARK_RECORD_HEADER(lheader) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 do { (((lheader)->implementation)--); } while (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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 /* lrecords are chained together through their "next.v" field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 * After doing the mark phase, the GC will walk this linked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 * list and free any record which hasn't been marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 static struct lcrecord_header *all_lcrecords;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 alloc_lcrecord (int size, CONST struct lrecord_implementation *implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 struct lcrecord_header *lcheader;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 if (size <= 0) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 if (implementation->static_size == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 if (!implementation->size_in_bytes_method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 else if (implementation->static_size != size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 lcheader = allocate_lisp_storage (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 lcheader->lheader.implementation = implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 lcheader->next = all_lcrecords;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 #if 1 /* mly prefers to see small ID numbers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 lcheader->uid = lrecord_uid_counter++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 #else /* jwz prefers to see real addrs */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 lcheader->uid = (int) &lcheader;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 lcheader->free = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 all_lcrecords = lcheader;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 INCREMENT_CONS_COUNTER (size, implementation->name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 return (lcheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 #if 0 /* Presently unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 /* Very, very poor man's EGC?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 * This may be slow and thrash pages all over the place.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 * Only call it if you really feel you must (and if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 * lrecord was fairly recently allocated).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 * 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
544 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 free_lcrecord (struct lcrecord_header *lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 if (all_lcrecords == lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 all_lcrecords = lcrecord->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 struct lrecord_header *header = all_lcrecords;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 for (;;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 struct lrecord_header *next = header->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 if (next == lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 header->next = lrecord->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 else if (next == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 header = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 if (lrecord->implementation->finalizer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ((lrecord->implementation->finalizer) (lrecord, 0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 xfree (lrecord);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 #endif /* Unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 disksave_object_finalization_1 (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 struct lcrecord_header *header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 for (header = all_lcrecords; header; header = header->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 if (header->lheader.implementation->finalizer && !header->free)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ((header->lheader.implementation->finalizer) (header, 1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 /* This must not be called -- it just serves as for EQ test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 * If lheader->implementation->finalizer is this_marks_a_marked_record,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 * then lrecord has been marked by the GC sweeper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 * header->implementation is put back to its correct value by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 * sweep_records */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 this_marks_a_marked_record (void *dummy0, int dummy1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 /* Semi-kludge -- lrecord_symbol_value_forward objects get stuck
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 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
603 This sits in lheader->implementation->marker. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 this_one_is_unmarkable (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 /* XGCTYPE for records */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 gc_record_type_p (Lisp_Object frob, CONST struct lrecord_implementation *type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 return (XGCTYPE (frob) == Lisp_Record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 && (XRECORD_LHEADER (frob)->implementation == type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 || XRECORD_LHEADER (frob)->implementation == type + 1));
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 /* Fixed-size type macros */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 /* For fixed-size types that are commonly used, we malloc() large blocks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 of memory at a time and subdivide them into chunks of the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 size for an object of that type. This is more efficient than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 malloc()ing each object separately because we save on malloc() time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 and overhead due to the fewer number of malloc()ed blocks, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 also because we don't need any extra pointers within each object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 to keep them threaded together for GC purposes. For less common
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (and frequently large-size) types, we use lcrecords, which are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 malloc()ed individually and chained together through a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 in the lcrecord header. lcrecords do not need to be fixed-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (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
637 however, the size of a particular object cannot vary dynamically).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 It is also much easier to create a new lcrecord type because no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 additional code needs to be added to alloc.c. Finally, lcrecords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 may be more efficient when there are only a small number of them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 The types that are stored in these large blocks (or "frob blocks")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 are cons, float, compiled-function, symbol, marker, extent, event,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 and string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 Note that strings are special in that they are actually stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 two parts: a structure containing information about the string, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 the actual data associated with the string. The former structure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (a struct Lisp_String) is a fixed-size structure and is managed the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 same way as all the other such types. This structure contains a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 pointer to the actual string data, which is stored in structures of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 type struct string_chars_block. Each string_chars_block consists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 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
654 string, followed by another pointer to a struct Lisp_String,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 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
656 these blocks is compacted by searching sequentially through all the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 blocks and compressing out any holes created by unmarked strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 Strings that are more than a certain size (bigger than the size of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 a string_chars_block, although something like half as big might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 make more sense) are malloc()ed separately and not stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 string_chars_blocks. Furthermore, no one string stretches across
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 two string_chars_blocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 Vectors are each malloc()ed separately, similar to lcrecords.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 In the following discussion, we use conses, but it applies equally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 well to the other fixed-size types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 We store cons cells inside of cons_blocks, allocating a new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 cons_block with malloc() whenever necessary. Cons cells reclaimed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 by GC are put on a free list to be reallocated before allocating
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 any new cons cells from the latest cons_block. Each cons_block is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 the versions in malloc.c and gmalloc.c) really allocates in units
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 of powers of two and uses 4 bytes for its own overhead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 What GC actually does is to search through all the cons_blocks,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 from the most recently allocated to the oldest, and put all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 cons cells that are not marked (whether or not they're already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 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
681 so the cons cells in the oldest-allocated cons_block end up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 at the head of the stack and are the first to be reallocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 If any cons_block is entirely free, it is freed with free()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 and its cons cells removed from the cons_free_list. Because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 the cons_free_list ends up basically in memory order, we have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 a high locality of reference (assuming a reasonable turnover
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 of allocating and freeing) and have a reasonable probability
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 of entirely freeing up cons_blocks that have been more recently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 allocated. This stage is called the "sweep stage" of GC, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 is executed after the "mark stage", which involves starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 from all places that are known to point to in-use Lisp objects
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (e.g. the obarray, where are all symbols are stored; the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 current catches and condition-cases; the backtrace list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 currently executing functions; the gcpro list; etc.) and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 recursively marking all objects that are accessible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 At the beginning of the sweep stage, the conses in the cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 blocks are in one of three states: in use and marked, in use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 but not marked, and not in use (already freed). Any conses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 that are marked have been marked in the mark stage just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 executed, because as part of the sweep stage we unmark any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 marked objects. The way we tell whether or not a cons cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 is in use is through the FREE_STRUCT_P macro. This basically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 looks at the first 4 bytes (or however many bytes a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 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
706 resulting value (0xFFFFFFFF) is not a valid pointer and is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 not a valid Lisp_Object. All current fixed-size types have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 a pointer or Lisp_Object as their first element with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 exception of strings; they have a size value, which can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 never be less than zero, and so 0xFFFFFFFF is invalid for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 strings as well. Now assuming that a cons cell is in use,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 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
713 the mark bit of its car (each Lisp_Object has one bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 reserved as a mark bit, in case it's needed). Note that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 different types of objects use different fields to indicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 whether the object is marked, but the principle is the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 Conses on the free_cons_list are threaded through a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 stored in the bytes directly after the bytes that are set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 to 0xFFFFFFFF (we cannot overwrite these because the cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 is still in a cons_block and needs to remain marked as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 not in use for the next time that GC happens). This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 implies that all fixed-size types must be at least big
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 enough to store two pointers, which is indeed the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 for all current fixed-size types.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 Some types of objects need additional "finalization" done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 when an object is converted from in use to not in use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 this is the purpose of the ADDITIONAL_FREE_type macro.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 For example, markers need to be removed from the chain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 of markers that is kept in each buffer. This is because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 markers in a buffer automatically disappear if the marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 is no longer referenced anywhere (the same does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 apply to extents, however).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 WARNING: Things are in an extremely bizarre state when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 the ADDITIONAL_FREE_type macros are called, so beware!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 When ERROR_CHECK_GC is defined, we do things differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 so as to maximize our chances of catching places where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 there is insufficient GCPROing. The thing we want to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 avoid is having an object that we're using but didn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 GCPRO get freed by GC and then reallocated while we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 in the process of using it -- this will result in something
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 seemingly unrelated getting trashed, and is extremely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 difficult to track down. If the object gets freed but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 not reallocated, we can usually catch this because we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 set all bytes of a freed object to 0xDEADBEEF. (The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 first four bytes, however, are 0xFFFFFFFF, and the next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 four are a pointer used to chain freed objects together;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 we play some tricks with this pointer to make it more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 bogus, so crashes are more likely to occur right away.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 We want freed objects to stay free as long as possible,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 so instead of doing what we do above, we maintain the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 free objects in a first-in first-out queue. We also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 don't recompute the free list each GC, unlike above;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 this ensures that the queue ordering is preserved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 [This means that we are likely to have worse locality
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 of reference, and that we can never free a frob block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 once it's allocated. (Even if we know that all cells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 in it are free, there's no easy way to remove all those
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 cells from the free list because the objects on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 free list are unlikely to be in memory order.)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 Furthermore, we never take objects off the free list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 unless there's a large number (usually 1000, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 varies depending on type) of them already on the list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 This way, we ensure that an object that gets freed will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 remain free for the next 1000 (or whatever) times that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 an object of that type is allocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 #ifndef MALLOC_OVERHEAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 #ifdef GNU_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 #define MALLOC_OVERHEAD 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 #elif defined (rcheck)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 #define MALLOC_OVERHEAD 20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 #define MALLOC_OVERHEAD 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 #ifdef ALLOC_NO_POOLS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 # define TYPE_ALLOC_SIZE(type, structtype) 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 # define TYPE_ALLOC_SIZE(type, structtype) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 / sizeof (structtype))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 struct type##_block \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 struct type##_block *prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 }; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 static struct type##_block *current_##type##_block; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 static int current_##type##_block_index; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 static structtype *type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 static structtype *type##_free_list_tail; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 static void \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 init_##type##_alloc (void) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 current_##type##_block = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 current_##type##_block_index = countof (current_##type##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 type##_free_list = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 type##_free_list_tail = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 static int gc_count_num_##type##_in_use, gc_count_num_##type##_freelist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 if (current_##type##_block_index \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 == countof (current_##type##_block->block)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 struct type##_block *__new__ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 = allocate_lisp_storage (sizeof (struct type##_block)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 __new__->prev = current_##type##_block; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 current_##type##_block = __new__; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 current_##type##_block_index = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (result) = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 &(current_##type##_block->block[current_##type##_block_index++]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 /* Allocate an instance of a type that is stored in blocks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 TYPE is the "name" of the type, STRUCTTYPE is the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 structure type. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 /* Note: if you get crashes in this function, suspect incorrect calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 to free_cons() and friends. This happened once because the cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 cell was not GC-protected and was getting collected before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 free_cons() was called. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 if (gc_count_num_##type##_freelist > \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 result = type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 /* Before actually using the chain pointer, we complement all its \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 bits; see FREE_FIXED_TYPE(). */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 type##_free_list = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (structtype *) ~(unsigned long) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (* (structtype **) ((char *) result + sizeof (void *))); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 gc_count_num_##type##_freelist--; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 MARK_STRUCT_AS_NOT_FREE (result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 if (type##_free_list) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 result = type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 type##_free_list = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 * (structtype **) ((char *) result + sizeof (void *)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 MARK_STRUCT_AS_NOT_FREE (result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 do \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 /* INVALID_POINTER_VALUE should be a value that is invalid as a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 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
895 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
896 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
897 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
898 be a pointer, and the pointer will be misaligned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 Even if Emacs is run on some weirdo system that allows and allocates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 byte-aligned pointers, this pointer is at the very top of the address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 space and so it's almost inconceivable that it could ever be valid. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 #if INTBITS == 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 # define INVALID_POINTER_VALUE 0xFFFFFFFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 #elif INTBITS == 48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 #elif INTBITS == 64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFFFFFF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 You have some weird system and need to supply a reasonable value here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 #define FREE_STRUCT_P(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (* (void **) ptr == (void *) INVALID_POINTER_VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 #define MARK_STRUCT_AS_FREE(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (* (void **) ptr = (void *) INVALID_POINTER_VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 #define MARK_STRUCT_AS_NOT_FREE(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (* (void **) ptr = 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 do { if (type##_free_list_tail) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 /* When we store the chain pointer, we complement all \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 its bits; this should significantly increase its \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 bogosity in case someone tries to use the value, and \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 should make us dump faster if someone stores something \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 over the pointer because when it gets un-complemented in \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 extremely bogus. */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 * (structtype **) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 ((char *) type##_free_list_tail + sizeof (void *)) = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (structtype *) ~(unsigned long) ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 type##_free_list = ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 type##_free_list_tail = ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 do { * (structtype **) ((char *) ptr + sizeof (void *)) = \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 type##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 type##_free_list = ptr; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_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 #define FREE_FIXED_TYPE(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 do { structtype *_weird_ = (ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 ADDITIONAL_FREE_##type (_weird_); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 deadbeef_memory (ptr, sizeof (structtype)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 MARK_STRUCT_AS_FREE (_weird_); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 /* Like FREE_FIXED_TYPE() but used when we are explicitly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 freeing a structure through free_cons(), free_marker(), etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 rather than through the normal process of sweeping.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 We attempt to undo the changes made to the allocation counters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 as a result of this structure being allocated. This is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 completely necessary but helps keep things saner: e.g. this way,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 repeatedly allocating and freeing a cons will not result in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 the consing-since-gc counter advancing, which would cause a GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 and somewhat defeat the purpose of explicitly freeing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 do { FREE_FIXED_TYPE (type, structtype, ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 DECREMENT_CONS_COUNTER (sizeof (structtype)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 gc_count_num_##type##_freelist++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 /* Cons allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 DECLARE_FIXED_TYPE_ALLOC (cons, struct Lisp_Cons);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 /* conses are used and freed so often that we set this really high */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
989 DEFUN ("cons", Fcons, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 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
991 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
992 (car, cdr))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 Lisp_Object val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 struct Lisp_Cons *c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 XSETCONS (val, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 XCAR (val) = car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 XCDR (val) = cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 /* This is identical to Fcons() but it used for conses that we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 going to free later, and is useful when trying to track down
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 "real" consing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 noseeum_cons (Lisp_Object car, Lisp_Object cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 Lisp_Object val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 struct Lisp_Cons *c;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 NOSEEUM_ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 XSETCONS (val, c);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 XCAR (val) = car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 XCDR (val) = cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1021 DEFUN ("list", Flist, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 Return a newly created list with specified arguments as elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 Any number of arguments, even zero arguments, are allowed.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1024 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1025 (int nargs, Lisp_Object *args))
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 Lisp_Object len, val, val_tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 len = make_int (nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 val = Fmake_list (len, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 val_tail = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 while (!NILP (val_tail))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 XCAR (val_tail) = *args++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 val_tail = XCDR (val_tail);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 list1 (Lisp_Object obj0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 return (Fcons (obj0, Qnil));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 list2 (Lisp_Object obj0, Lisp_Object obj1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 return Fcons (obj0, list1 (obj1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 return Fcons (obj0, list2 (obj1, obj2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 return Fcons (obj0, Fcons (obj1, obj2));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 return Fcons (obj0, list3 (obj1, obj2, obj3));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 Lisp_Object obj4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 return Fcons (obj0, list4 (obj1, obj2, obj3, obj4));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 Lisp_Object obj4, Lisp_Object obj5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 /* This cannot GC. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 return Fcons (obj0, list5 (obj1, obj2, obj3, obj4, obj5));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1091 DEFUN ("make-list", Fmake_list, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 Return a newly created list of length LENGTH, with each element being INIT.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1093 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1094 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 CHECK_NATNUM (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 size = XINT (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 while (size-- > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 val = Fcons (init, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 /* Float allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 DECLARE_FIXED_TYPE_ALLOC (float, struct Lisp_Float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 make_float (double float_value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 struct Lisp_Float *f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 ALLOCATE_FIXED_TYPE (float, struct Lisp_Float, f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 f->lheader.implementation = lrecord_float;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 float_next (f) = ((struct Lisp_Float *) -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 float_data (f) = float_value;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 XSETFLOAT (val, f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 return (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 /* Vector allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 static Lisp_Object all_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 /* #### should allocate `small' vectors from a frob-block */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 static struct Lisp_Vector *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 make_vector_internal (EMACS_INT sizei)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 EMACS_INT sizem = (sizeof (struct Lisp_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 /* -1 because struct Lisp_Vector includes 1 slot,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 * +1 to account for vector_next */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 + (sizei - 1 + 1) * sizeof (Lisp_Object)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 struct Lisp_Vector *p = allocate_lisp_storage (sizem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 #ifdef LRECORD_VECTOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 set_lheader_implementation (&(p->lheader), lrecord_vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 INCREMENT_CONS_COUNTER (sizem, "vector");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 p->size = sizei;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 vector_next (p) = all_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 XSETVECTOR (all_vectors, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 return (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 make_vector (EMACS_INT length, Lisp_Object init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 EMACS_INT elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 Lisp_Object vector = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 struct Lisp_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 if (length < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 p = make_vector_internal (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 XSETVECTOR (vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 /* Initialize big arrays full of 0's quickly, for what that's worth */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 char *travesty = (char *) &init;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 for (i = 1; i < sizeof (Lisp_Object); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 if (travesty[i] != travesty[0])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 goto fill;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 memset (vector_data (p), travesty[0], length * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 return (vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 fill:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 for (elt = 0; elt < length; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 vector_data(p)[elt] = init;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 return (vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1196 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 Return a newly created vector of length LENGTH, with each element being INIT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 See also the function `vector'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1199 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1200 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 if (!INTP (length) || XINT (length) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 length = wrong_type_argument (Qnatnump, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 return (make_vector (XINT (length), init));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1208 DEFUN ("vector", Fvector, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 Return a newly created vector with specified arguments as elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 Any number of arguments, even zero arguments, are allowed.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1211 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1212 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 Lisp_Object vector = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 int elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 struct Lisp_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 p = make_vector_internal (nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 XSETVECTOR (vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 for (elt = 0; elt < nargs; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 vector_data(p)[elt] = args[elt];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 return (vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 vector1 (Lisp_Object obj0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 return Fvector (1, &obj0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 vector2 (Lisp_Object obj0, Lisp_Object obj1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 Lisp_Object args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 return Fvector (2, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 Lisp_Object args[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 return Fvector (3, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 Lisp_Object obj3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 Lisp_Object args[4];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 return Fvector (4, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 Lisp_Object obj3, Lisp_Object obj4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 Lisp_Object args[5];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 return Fvector (5, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 Lisp_Object args[6];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 args[5] = obj5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 return Fvector (6, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 Lisp_Object obj6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 Lisp_Object args[7];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 args[5] = obj5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 args[6] = obj6;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 return Fvector (7, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 Lisp_Object obj6, Lisp_Object obj7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 Lisp_Object args[8];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 args[0] = obj0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 args[1] = obj1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 args[2] = obj2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 args[3] = obj3;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 args[4] = obj4;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 args[5] = obj5;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 args[6] = obj6;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 args[7] = obj7;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 return Fvector (8, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 /* Bit Vector allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 static Lisp_Object all_bit_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 /* #### should allocate `small' bit vectors from a frob-block */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 static struct Lisp_Bit_Vector *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 make_bit_vector_internal (EMACS_INT sizei)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 EMACS_INT sizem = (sizeof (struct Lisp_Bit_Vector) +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 /* -1 because struct Lisp_Bit_Vector includes 1 slot */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 sizeof (long) * (BIT_VECTOR_LONG_STORAGE (sizei) - 1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 struct Lisp_Bit_Vector *p = allocate_lisp_storage (sizem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 set_lheader_implementation (&(p->lheader), lrecord_bit_vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 INCREMENT_CONS_COUNTER (sizem, "bit-vector");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 bit_vector_length (p) = sizei;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 bit_vector_next (p) = all_bit_vectors;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 /* make sure the extra bits in the last long are 0; the calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 functions might not set them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 p->bits[BIT_VECTOR_LONG_STORAGE (sizei) - 1] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 XSETBIT_VECTOR (all_bit_vectors, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 return (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 make_bit_vector (EMACS_INT length, Lisp_Object init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 Lisp_Object bit_vector = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 struct Lisp_Bit_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 EMACS_INT num_longs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 if (length < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 CHECK_BIT (init);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 num_longs = BIT_VECTOR_LONG_STORAGE (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 p = make_bit_vector_internal (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 XSETBIT_VECTOR (bit_vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 if (ZEROP (init))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 memset (p->bits, 0, num_longs * sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 EMACS_INT bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 memset (p->bits, ~0, num_longs * sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 /* But we have to make sure that the unused bits in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 last integer are 0, so that equal/hash is easy. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 if (bits_in_last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 return (bit_vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 make_bit_vector_from_byte_vector (unsigned char *bytevec, EMACS_INT length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 Lisp_Object bit_vector = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 struct Lisp_Bit_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 EMACS_INT i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 if (length < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 p = make_bit_vector_internal (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 XSETBIT_VECTOR (bit_vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 for (i = 0; i < length; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 set_bit_vector_bit (p, i, bytevec[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 return bit_vector;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1401 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 Return a newly created bit vector of length LENGTH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 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
1404 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1405 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 if (!INTP (length) || XINT (length) < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 length = wrong_type_argument (Qnatnump, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 return (make_bit_vector (XINT (length), init));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1413 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 Return a newly created bit vector with specified arguments as elements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 Any number of arguments, even zero arguments, are allowed.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1416 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1417 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 Lisp_Object bit_vector = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 int elt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 struct Lisp_Bit_Vector *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 for (elt = 0; elt < nargs; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 CHECK_BIT (args[elt]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 p = make_bit_vector_internal (nargs);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 XSETBIT_VECTOR (bit_vector, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 for (elt = 0; elt < nargs; elt++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 set_bit_vector_bit (p, elt, !ZEROP (args[elt]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 return (bit_vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 /* Compiled-function allocation */
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 DECLARE_FIXED_TYPE_ALLOC (compiled_function, struct Lisp_Compiled_Function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 make_compiled_function (int make_pure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 struct Lisp_Compiled_Function *b;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 int size = sizeof (struct Lisp_Compiled_Function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 if (make_pure && check_purespace (size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 b = (struct Lisp_Compiled_Function *) (PUREBEG + pureptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 pureptr += size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 bump_purestat (&purestat_bytecode, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 ALLOCATE_FIXED_TYPE (compiled_function, struct Lisp_Compiled_Function,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 b->maxdepth = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 b->flags.documentationp = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 b->flags.interactivep = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 b->flags.domainp = 0; /* I18N3 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 b->bytecodes = Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 b->constants = Qzero;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 b->arglist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 b->doc_and_interactive = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 b->annotated = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 XSETCOMPILED_FUNCTION (new, b);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 return (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1478 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 Create a compiled-function object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 Usage: (arglist instructions constants stack-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 &optional doc-string interactive-spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 Note that, unlike all other emacs-lisp functions, calling this with five
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 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
1484 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
1485 that this function was defined with `(interactive)'. If the arg is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 specified, then that means the function is not interactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 This is terrible behavior which is retained for compatibility with old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 `.elc' files which expected these semantics.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1489 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1490 (int nargs, Lisp_Object *args))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 /* In a non-insane world this function would have this arglist...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (arglist, instructions, constants, stack_size, doc_string, interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 Lisp_Object arglist, instructions, constants, stack_size, doc_string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 interactive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 Lisp_Object arglist = args[0];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 Lisp_Object instructions = args[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 Lisp_Object constants = args[2];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 Lisp_Object stack_size = args[3];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 Lisp_Object doc_string = ((nargs > 4) ? args[4] : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 Lisp_Object interactive = ((nargs > 5) ? args[5] : Qunbound);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 /* Don't purecopy the doc references in instructions because it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 wasteful; they will get fixed up later.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 #### If something goes wrong and they don't get fixed up,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 we're screwed, because pure stuff isn't marked and thus the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 cons references won't be marked and will get reused.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 Note: there will be a window after the byte code is created and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 before the doc references are fixed up in which there will be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 impure objects inside a pure object, which apparently won't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 get marked, leading the trouble. But during that entire window,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 the objects are sitting on Vload_force_doc_string_list, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 is staticpro'd, so we're OK. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 int purecopy_instructions = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 if (nargs > 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 return Fsignal (Qwrong_number_of_arguments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 list2 (intern ("make-byte-code"), make_int (nargs)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 CHECK_LIST (arglist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 /* instructions is a string or a cons (string . int) for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 lazy-loaded function. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 if (CONSP (instructions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 CHECK_STRING (XCAR (instructions));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 CHECK_INT (XCDR (instructions));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 if (!NILP (constants))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 CHECK_VECTOR (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 purecopy_instructions = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 CHECK_STRING (instructions);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 CHECK_VECTOR (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 CHECK_NATNUM (stack_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 /* doc_string may be nil, string, int, or a cons (string . int). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 /* interactive may be list or string (or unbound). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 if (purify_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 if (!purified (arglist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 arglist = Fpurecopy (arglist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 if (purecopy_instructions && !purified (instructions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 instructions = Fpurecopy (instructions);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 if (!purified (doc_string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 doc_string = Fpurecopy (doc_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 if (!purified (interactive) && !UNBOUNDP (interactive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 interactive = Fpurecopy (interactive);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 /* Statistics are kept differently for the constants */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 if (!purified (constants))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 int old = purecopying_for_bytecode;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 purecopying_for_bytecode = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 constants = Fpurecopy (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 purecopying_for_bytecode = old;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 constants = Fpurecopy (constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 if (STRINGP (instructions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 bump_purestat (&purestat_string_bytecodes, pure_sizeof (instructions));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 if (VECTORP (constants))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 bump_purestat (&purestat_vector_bytecode_constants,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 pure_sizeof (constants));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 if (STRINGP (doc_string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 /* These should be have been snagged by make-docfile... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 bump_purestat (&purestat_string_documentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 pure_sizeof (doc_string));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 if (STRINGP (interactive))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 bump_purestat (&purestat_string_interactive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 pure_sizeof (interactive));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 int docp = !NILP (doc_string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 int intp = !UNBOUNDP (interactive);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 int domp = !NILP (Vfile_domain);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 Lisp_Object val = make_compiled_function (purify_flag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 b->flags.documentationp = docp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 b->flags.interactivep = intp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 b->flags.domainp = domp;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 b->maxdepth = XINT (stack_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 b->bytecodes = instructions;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 b->constants = constants;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 b->arglist = arglist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 if (!NILP (Vcurrent_compiled_function_annotation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 b->annotated = Fpurecopy (Vcurrent_compiled_function_annotation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 else if (!NILP (Vload_file_name_internal_the_purecopy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 b->annotated = Vload_file_name_internal_the_purecopy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 else if (!NILP (Vload_file_name_internal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 Vload_file_name_internal_the_purecopy =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 Fpurecopy (Ffile_name_nondirectory (Vload_file_name_internal));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 b->annotated = Vload_file_name_internal_the_purecopy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 if (docp && intp && domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (doc_string,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (interactive, Vfile_domain))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 else if (docp && domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (doc_string, Vfile_domain));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 else if (intp && domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (interactive, Vfile_domain));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 if (docp && intp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (doc_string, interactive));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 else if (intp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 b->doc_and_interactive = interactive;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 else if (domp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 b->doc_and_interactive = Vfile_domain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 b->doc_and_interactive = doc_string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 return (val);
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 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 /* Symbol allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 DECLARE_FIXED_TYPE_ALLOC (symbol, struct Lisp_Symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1651 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 Return a newly allocated uninterned symbol whose name is NAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 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
1654 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1655 (str))
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 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 struct Lisp_Symbol *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 CHECK_STRING (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 ALLOCATE_FIXED_TYPE (symbol, struct Lisp_Symbol, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 #ifdef LRECORD_SYMBOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 set_lheader_implementation (&(p->lheader), lrecord_symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 p->name = XSTRING (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 p->plist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 p->value = Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 p->function = Qunbound;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 symbol_next (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 XSETSYMBOL (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 /* Extent allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 struct extent *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 allocate_extent (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 struct extent *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 ALLOCATE_FIXED_TYPE (extent, struct extent, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 /* memset (e, 0, sizeof (struct extent)); */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 set_lheader_implementation (&(e->lheader), lrecord_extent);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 extent_object (e) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 set_extent_start (e, -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 set_extent_end (e, -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 e->plist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 memset (&e->flags, 0, sizeof (e->flags));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 extent_face (e) = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 e->flags.end_open = 1; /* default is for endpoints to behave like markers */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 e->flags.detachable = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 return (e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 /* Event allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 DECLARE_FIXED_TYPE_ALLOC (event, struct Lisp_Event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 allocate_event (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 struct Lisp_Event *e;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 ALLOCATE_FIXED_TYPE (event, struct Lisp_Event, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 set_lheader_implementation (&(e->lheader), lrecord_event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 XSETEVENT (val, e);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 /* Marker allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 DECLARE_FIXED_TYPE_ALLOC (marker, struct Lisp_Marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1734 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 Return a newly allocated marker which does not point at any place.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1736 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
1737 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 struct Lisp_Marker *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 set_lheader_implementation (&(p->lheader), lrecord_marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 p->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 p->memind = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 marker_next (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 marker_prev (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 p->insertion_type = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 XSETMARKER (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 noseeum_make_marker (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 struct Lisp_Marker *p;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 NOSEEUM_ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 set_lheader_implementation (&(p->lheader), lrecord_marker);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 p->buffer = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 p->memind = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 marker_next (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 marker_prev (p) = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 p->insertion_type = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 XSETMARKER (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 /* String allocation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 /* The data for "short" strings generally resides inside of structs of type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 string_chars_block. The Lisp_String structure is allocated just like any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 other Lisp object (except for vectors), and these are freelisted when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 they get garbage collected. The data for short strings get compacted,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 but the data for large strings do not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 Previously Lisp_String structures were relocated, but this caused a lot
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 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
1783 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
1784 that the reference would get relocated).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 This new method makes things somewhat bigger, but it is MUCH safer. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 DECLARE_FIXED_TYPE_ALLOC (string, struct Lisp_String);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 /* strings are used and freed quite often */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 /* String blocks contain this many useful bytes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 #define STRING_CHARS_BLOCK_SIZE \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (8192 - MALLOC_OVERHEAD - ((2 * sizeof (struct string_chars_block *)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 + sizeof (EMACS_INT)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 /* Block header for small strings. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 struct string_chars_block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 EMACS_INT pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 struct string_chars_block *next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 struct string_chars_block *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 /* Contents of string_chars_block->string_chars are interleaved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 string_chars structures (see below) and the actual string data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 struct string_chars_block *first_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 struct string_chars_block *current_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 /* If SIZE is the length of a string, this returns how many bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 * the string occupies in string_chars_block->string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 * (including alignment padding).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 #define STRING_FULLSIZE(s) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 ALIGN_SIZE (((s) + 1 + sizeof (struct Lisp_String *)),\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 ALIGNOF (struct Lisp_String *))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 #define CHARS_TO_STRING_CHAR(x) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 ((struct string_chars *) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (((char *) (x)) - (slot_offset (struct string_chars, chars))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 struct string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 struct Lisp_String *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 unsigned char chars[1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 struct unused_string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 struct Lisp_String *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 EMACS_INT fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 init_string_chars_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 first_string_chars_block =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (struct string_chars_block *) xmalloc (sizeof (struct string_chars_block));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 first_string_chars_block->prev = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 first_string_chars_block->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 first_string_chars_block->pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 current_string_chars_block = first_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 static struct string_chars *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 allocate_string_chars_struct (struct Lisp_String *string_it_goes_with,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 EMACS_INT fullsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 struct string_chars *s_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 /* Allocate the string's actual data */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 if (BIG_STRING_FULLSIZE_P (fullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 s_chars = (struct string_chars *) xmalloc (fullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 else if (fullsize <=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (countof (current_string_chars_block->string_chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 - current_string_chars_block->pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 /* This string can fit in the current string chars block */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 s_chars = (struct string_chars *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (current_string_chars_block->string_chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 + current_string_chars_block->pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 current_string_chars_block->pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 /* Make a new current string chars block */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 struct string_chars_block *new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 = (struct string_chars_block *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 xmalloc (sizeof (struct string_chars_block));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 current_string_chars_block->next = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 new->prev = current_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 new->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 current_string_chars_block = new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 new->pos = fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 s_chars = (struct string_chars *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 current_string_chars_block->string_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 s_chars->string = string_it_goes_with;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 INCREMENT_CONS_COUNTER (fullsize, "string chars");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 return s_chars;
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 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 make_uninit_string (Bytecount length)
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 Lisp_String *s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 struct string_chars *s_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 EMACS_INT fullsize = STRING_FULLSIZE (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 if ((length < 0) || (fullsize <= 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 /* Allocate the string header */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 ALLOCATE_FIXED_TYPE (string, struct Lisp_String, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 s_chars = allocate_string_chars_struct (s, fullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 set_string_data (s, &(s_chars->chars[0]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 set_string_length (s, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 s->plist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 set_string_byte (s, length, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 XSETSTRING (val, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 return (val);
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 #ifdef VERIFY_STRING_CHARS_INTEGRITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 static void verify_string_chars_integrity (void);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 /* Resize the string S so that DELTA bytes can be inserted starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 at POS. If DELTA < 0, it means deletion starting at POS. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 POS < 0, resize the string but don't copy any characters. Use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 this if you're planning on completely overwriting the string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 resize_string (struct Lisp_String *s, Bytecount pos, Bytecount delta)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 #ifdef VERIFY_STRING_CHARS_INTEGRITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 verify_string_chars_integrity ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 #ifdef ERROR_CHECK_BUFPOS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 assert (pos <= string_length (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 if (delta < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 assert (pos + (-delta) <= string_length (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 if (delta < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 assert ((-delta) <= string_length (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 if (pos >= 0 && delta < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 /* If DELTA < 0, the functions below will delete the characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 before POS. We want to delete characters *after* POS, however,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 so convert this to the appropriate form. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 pos += -delta;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 if (delta == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 /* simplest case: no size change. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 EMACS_INT oldfullsize = STRING_FULLSIZE (string_length (s));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 EMACS_INT newfullsize = STRING_FULLSIZE (string_length (s) + delta);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 if (oldfullsize == newfullsize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 /* next simplest case; size change but the necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 allocation size won't change (up or down; code somewhere
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 depends on there not being any unused allocation space,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 modulo any alignment constraints). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 Bufbyte *addroff = pos + string_data (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 memmove (addroff + delta, addroff,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 /* +1 due to zero-termination. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 string_length (s) + 1 - pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 else if (BIG_STRING_FULLSIZE_P (oldfullsize) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 BIG_STRING_FULLSIZE_P (newfullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 /* next simplest case; the string is big enough to be malloc()ed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 itself, so we just realloc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 It's important not to let the string get below the threshold
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 for making big strings and still remain malloc()ed; if that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 were the case, repeated calls to this function on the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 string could result in memory leakage. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 set_string_data (s, (Bufbyte *) xrealloc (string_data (s),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 newfullsize));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 Bufbyte *addroff = pos + string_data (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 memmove (addroff + delta, addroff,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 /* +1 due to zero-termination. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 string_length (s) + 1 - pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 /* worst case. We make a new string_chars struct and copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 the string's data into it, inserting/deleting the delta
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 in the process. The old string data will either get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 freed by us (if it was malloc()ed) or will be reclaimed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 in the normal course of garbage collection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 struct string_chars *s_chars =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 allocate_string_chars_struct (s, newfullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 Bufbyte *new_addr = &(s_chars->chars[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 Bufbyte *old_addr = string_data (s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 memcpy (new_addr, old_addr, pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 memcpy (new_addr + pos + delta, old_addr + pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 string_length (s) + 1 - pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 set_string_data (s, new_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 if (BIG_STRING_FULLSIZE_P (oldfullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 xfree (old_addr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 /* We need to mark this chunk of the string_chars_block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 as unused so that compact_string_chars() doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 freak. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 struct string_chars *old_s_chars =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (struct string_chars *) ((char *) old_addr -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 sizeof (struct Lisp_String *));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 /* Sanity check to make sure we aren't hosed by strange
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 alignment/padding. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 assert (old_s_chars->string == s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 MARK_STRUCT_AS_FREE (old_s_chars);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 ((struct unused_string_chars *) old_s_chars)->fullsize =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 oldfullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 set_string_length (s, string_length (s) + delta);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 /* If pos < 0, the string won't be zero-terminated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 Terminate now just to make sure. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 string_data (s)[string_length (s)] = '\0';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 if (pos >= 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 Lisp_Object string = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 XSETSTRING (string, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 /* We also have to adjust all of the extent indices after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 place we did the change. We say "pos - 1" because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 adjust_extents() is exclusive of the starting position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 passed to it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 adjust_extents (string, pos - 1, string_length (s),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 delta);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 #ifdef VERIFY_STRING_CHARS_INTEGRITY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 verify_string_chars_integrity ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2062 DEFUN ("make-string", Fmake_string, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 Return a newly created string of length LENGTH, with each element being INIT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 LENGTH must be an integer and INIT must be a character.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2065 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2066 (length, init))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 CHECK_NATNUM (length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 CHECK_CHAR_COERCE_INT (init);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 Bufbyte str[MAX_EMCHAR_LEN];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 int len = set_charptr_emchar (str, XCHAR (init));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 val = make_uninit_string (len * XINT (length));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 if (len == 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 /* Optimize the single-byte case */
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2079 memset (XSTRING_DATA (val), XCHAR (init), XSTRING_LENGTH (val));
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 int i, j, k;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2083 Bufbyte *ptr = XSTRING_DATA (val);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 k = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 for (i = 0; i < XINT (length); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 for (j = 0; j < len; j++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ptr[k++] = str[j];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 return (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 /* Take some raw memory, which MUST already be in internal format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 and package it up it into a Lisp string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 make_string (CONST Bufbyte *contents, Bytecount length)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 val = make_uninit_string (length);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2102 memcpy (XSTRING_DATA (val), contents, length);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 return (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 /* Take some raw memory, encoded in some external data format,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 and convert it into a Lisp string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 make_ext_string (CONST Extbyte *contents, EMACS_INT length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 enum external_data_format fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 CONST Bufbyte *intstr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 Bytecount intlen;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 GET_CHARPTR_INT_DATA_ALLOCA (contents, length, fmt, intstr, intlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 return make_string (intstr, intlen);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 build_string (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 Bytecount length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 /* Some strlen crash and burn if passed null. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 if (!str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 length = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 length = strlen (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 return make_string ((CONST Bufbyte *) str, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 build_ext_string (CONST char *str, enum external_data_format fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 Bytecount length;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 /* Some strlen crash and burn if passed null. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 if (!str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 length = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 length = strlen (str);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 return make_ext_string ((Extbyte *) str, length, fmt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 build_translated_string (CONST char *str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 return build_string (GETTEXT (str));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 /* lcrecord lists */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 /* Lcrecord lists are used to manage the allocation of particular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 sorts of lcrecords, to avoid calling alloc_lcrecord() (and thus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 malloc() and garbage-collection junk) as much as possible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 It is similar to the Blocktype class.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 It works like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 1) Create an lcrecord-list object using make_lcrecord_list().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 This is often done at initialization. Remember to staticpro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 this object! The arguments to make_lcrecord_list() are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 same as would be passed to alloc_lcrecord().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 2) Instead of calling alloc_lcrecord(), call allocate_managed_lcrecord()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 and pass the lcrecord-list earlier created.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 3) When done with the lcrecord, call free_managed_lcrecord().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 The standard freeing caveats apply: ** make sure there are no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 pointers to the object anywhere! **
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 4) Calling free_managed_lcrecord() is just like kissing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 lcrecord goodbye as if it were garbage-collected. This means:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 -- the contents of the freed lcrecord are undefined, and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 contents of something produced by allocate_managed_lcrecord()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 are undefined, just like for alloc_lcrecord().
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 -- the mark method for the lcrecord's type will *NEVER* be called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 on freed lcrecords.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 -- the finalize method for the lcrecord's type will be called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 at the time that free_managed_lcrecord() is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 static Lisp_Object mark_lcrecord_list (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 mark_lcrecord_list, internal_object_printer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 0, 0, 0, struct lcrecord_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 mark_lcrecord_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 struct lcrecord_list *list = XLCRECORD_LIST (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 Lisp_Object chain = list->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 while (!NILP (chain))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 struct lrecord_header *lheader = XRECORD_LHEADER (chain);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 struct free_lcrecord_header *free_header =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (struct free_lcrecord_header *) lheader;
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2202
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2203 #ifdef ERROR_CHECK_GC
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 CONST struct lrecord_implementation *implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 = lheader->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 /* There should be no other pointers to the free list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 assert (!MARKED_RECORD_HEADER_P (lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 /* Only lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 assert (!implementation->basic_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 /* Only free lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 assert (free_header->lcheader.free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 /* The type of the lcrecord must be right. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 assert (implementation == list->implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 /* So must the size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 assert (implementation->static_size == 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 || implementation->static_size == list->size);
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2218 #endif /* ERROR_CHECK_GC */
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
2219
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 MARK_RECORD_HEADER (lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 chain = free_header->chain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 make_lcrecord_list (int size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 CONST struct lrecord_implementation *implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 struct lcrecord_list *p = alloc_lcrecord (sizeof (*p),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 lrecord_lcrecord_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 Lisp_Object val = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 p->implementation = implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 p->size = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 p->free = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 XSETLCRECORD_LIST (val, p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 allocate_managed_lcrecord (Lisp_Object lcrecord_list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 if (!NILP (list->free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 Lisp_Object val = list->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 struct free_lcrecord_header *free_header =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (struct free_lcrecord_header *) XPNTR (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 struct lrecord_header *lheader =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (struct lrecord_header *) free_header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 CONST struct lrecord_implementation *implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 = lheader->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 /* There should be no other pointers to the free list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 assert (!MARKED_RECORD_HEADER_P (lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 /* Only lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 assert (!implementation->basic_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 /* Only free lcrecords should be here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 assert (free_header->lcheader.free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 /* The type of the lcrecord must be right. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 assert (implementation == list->implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 /* So must the size. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 assert (implementation->static_size == 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 || implementation->static_size == list->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 list->free = free_header->chain;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 free_header->lcheader.free = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 Lisp_Object foo = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 XSETOBJ (foo, Lisp_Record,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 alloc_lcrecord (list->size, list->implementation));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 return foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 struct free_lcrecord_header *free_header =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (struct free_lcrecord_header *) XPNTR (lcrecord);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 struct lrecord_header *lheader =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (struct lrecord_header *) free_header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 CONST struct lrecord_implementation *implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 = lheader->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 /* Make sure the size is correct. This will catch, for example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 putting a window configuration on the wrong free list. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 if (implementation->size_in_bytes_method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 assert (((implementation->size_in_bytes_method) (lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 == list->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 assert (implementation->static_size == list->size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 if (implementation->finalizer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 ((implementation->finalizer) (lheader, 0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 free_header->chain = list->free;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 free_header->lcheader.free = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 list->free = lcrecord;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 /* Purity of essence, peace on earth */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 static int symbols_initialized;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 make_pure_string (CONST Bufbyte *data, Bytecount length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 Lisp_Object plist, int no_need_to_copy_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 struct Lisp_String *s;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 int size = (sizeof (struct Lisp_String) + ((no_need_to_copy_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 ? 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 /* + 1 for terminating 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 : (length + 1)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 size = ALIGN_SIZE (size, ALIGNOF (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 if (symbols_initialized && !pure_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 /* Try to share some names. Saves a few kbytes. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 Lisp_Object tem = oblookup (Vobarray, data, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 if (SYMBOLP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 s = XSYMBOL (tem)->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 if (!PURIFIED (s)) abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 XSETSTRING (new, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 return (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 if (!check_purespace (size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 return (make_string (data, length));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 s = (struct Lisp_String *) (PUREBEG + pureptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 set_string_length (s, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 if (no_need_to_copy_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 set_string_data (s, (Bufbyte *) data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 set_string_data (s, (Bufbyte *) s + sizeof (struct Lisp_String));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 memcpy (string_data (s), data, length);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 set_string_byte (s, length, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 s->plist = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 pureptr += size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 bump_purestat (&purestat_string_all, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 if (purecopying_for_bytecode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 bump_purestat (&purestat_string_other_function, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 /* Do this after the official "completion" of the purecopying. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 s->plist = Fpurecopy (plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 XSETSTRING (new, s);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 return (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 make_pure_pname (CONST Bufbyte *data, Bytecount length,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 int no_need_to_copy_data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 Lisp_Object name = make_pure_string (data, length, Qnil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 no_need_to_copy_data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 bump_purestat (&purestat_string_pname, pure_sizeof (name));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 /* 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
2385 symbols_initialized = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 return (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 pure_cons (Lisp_Object car, Lisp_Object cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 if (!check_purespace (sizeof (struct Lisp_Cons)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 return (Fcons (Fpurecopy (car), Fpurecopy (cdr)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 XSETCONS (new, PUREBEG + pureptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 pureptr += sizeof (struct Lisp_Cons);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 bump_purestat (&purestat_cons, sizeof (struct Lisp_Cons));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 XCAR (new) = Fpurecopy (car);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 XCDR (new) = Fpurecopy (cdr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 return (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 pure_list (int nargs, Lisp_Object *args)
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 foo = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 for (--nargs; nargs >= 0; nargs--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 foo = pure_cons (args[nargs], foo);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 return foo;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 make_pure_float (double num)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 struct Lisp_Float *f;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 /* Make sure that PUREBEG + pureptr is aligned on at least a sizeof
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (double) boundary. Some architectures (like the sparc) require
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 this, and I suspect that floats are rare enough that it's no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 tragedy for those that don't. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 #if defined (__GNUC__) && (__GNUC__ >= 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 /* In gcc, we can directly ask what the alignment constraints of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 structure are, but in general, that's not possible... Arrgh!!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 int alignment = __alignof (struct Lisp_Float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 #else /* !GNUC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 /* Best guess is to make the `double' slot be aligned to the size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 of double (which is probably 8 bytes). This assumes that it's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 ok to align the beginning of the structure to the same boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 that the `double' slot in it is supposed to be aligned to; this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 should be ok because presumably there is padding in the layout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 of the struct to account for this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 int alignment = sizeof (float_data (f));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 char *p = ((char *) PUREBEG + pureptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 p = (char *) (((unsigned EMACS_INT) p + alignment - 1) & - alignment);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 pureptr = p - (char *) PUREBEG;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 if (!check_purespace (sizeof (struct Lisp_Float)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 return (make_float (num));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 f = (struct Lisp_Float *) (PUREBEG + pureptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 set_lheader_implementation (&(f->lheader), lrecord_float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 pureptr += sizeof (struct Lisp_Float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 bump_purestat (&purestat_float, sizeof (struct Lisp_Float));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 float_next (f) = ((struct Lisp_Float *) -1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 float_data (f) = num;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 XSETFLOAT (val, f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 return (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 make_pure_vector (EMACS_INT len, Lisp_Object init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 Lisp_Object new;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 EMACS_INT size = (sizeof (struct Lisp_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 + (len - 1) * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 init = Fpurecopy (init);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 if (!check_purespace (size))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 return (make_vector (len, init));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 XSETVECTOR (new, PUREBEG + pureptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 pureptr += size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 bump_purestat (&purestat_vector_all, size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 XVECTOR (new)->size = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 for (size = 0; size < len; size++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 vector_data (XVECTOR (new))[size] = init;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 return (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 /* Presently unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 void *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 alloc_pure_lrecord (int size, struct lrecord_implementation *implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 struct lrecord_header *header = (void *) (PUREBEG + pureptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 if (pureptr + size > PURESIZE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 pure_storage_exhausted ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 set_lheader_implementation (header, implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 header->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 return (header);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2511 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 Make a copy of OBJECT in pure storage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 Recursively copies contents of vectors and cons cells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 Does not copy symbols.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2515 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
2516 (obj))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 if (!purify_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 return (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 if (!POINTER_TYPE_P (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 || PURIFIED (XPNTR (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 return (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 switch (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 case Lisp_Cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 return pure_cons (XCAR (obj), XCDR (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 case Lisp_String:
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2532 return make_pure_string (XSTRING_DATA (obj),
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 14
diff changeset
2533 XSTRING_LENGTH (obj),
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 XSTRING (obj)->plist,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 case Lisp_Vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 struct Lisp_Vector *o = XVECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 Lisp_Object new = make_pure_vector (vector_length (o), Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 for (i = 0; i < vector_length (o); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 vector_data (XVECTOR (new))[i] = Fpurecopy (o->contents[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 return (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 if (COMPILED_FUNCTIONP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 struct Lisp_Compiled_Function *o = XCOMPILED_FUNCTION (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 Lisp_Object new = make_compiled_function (1);
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2552 /* How on earth could this code have worked before? -sb */
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2553 struct Lisp_Compiled_Function *n = XCOMPILED_FUNCTION (new);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 n->flags = o->flags;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 n->bytecodes = Fpurecopy (o->bytecodes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 n->constants = Fpurecopy (o->constants);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 n->arglist = Fpurecopy (o->arglist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 n->doc_and_interactive = Fpurecopy (o->doc_and_interactive);
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2559 n->maxdepth = o->maxdepth;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 return (new);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 else if (FLOATP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 return make_pure_float (float_data (XFLOAT (obj)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 else if (!SYMBOLP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 signal_simple_error ("Can't purecopy %S", obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 return (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2575 static void
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2576 PURESIZE_h(long int puresize)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2577 {
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2578 int fd;
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 26
diff changeset
2579 char *PURESIZE_h_file = "puresize_adjust.h";
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2580 char *WARNING = "/* This file is generated by XEmacs, DO NOT MODIFY!!! */\n";
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2581 char define_PURESIZE[256];
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2582
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 26
diff changeset
2583 if ((fd = open(PURESIZE_h_file, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) {
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 26
diff changeset
2584 report_file_error("Can't write PURESIZE_ADJUSTMENT",
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2585 Fcons(build_ext_string(PURESIZE_h_file, FORMAT_FILENAME),
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2586 Qnil));
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2587 }
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2588
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2589 write(fd, WARNING, strlen(WARNING));
28
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 26
diff changeset
2590 sprintf(define_PURESIZE, "# define PURESIZE_ADJUSTMENT %ld\n",
1917ad0d78d7 Import from CVS: tag r19-15b97
cvs
parents: 26
diff changeset
2591 puresize - RAW_PURESIZE);
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2592 write(fd, define_PURESIZE, strlen(define_PURESIZE));
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2593 close(fd);
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2594 }
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2595
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 report_pure_usage (int report_impurities,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 int die_if_pure_storage_exceeded)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 {
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2600 int rc = 0;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2601
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 if (pure_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 CONST long report_round = 5000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 message ("\n****\tPure Lisp storage exhausted!\n"
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2607 "\tPurespace usage: %ld of %ld\n"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 "****",
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 28
diff changeset
2609 PURESIZE+pure_lossage, PURESIZE);
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2610 if (die_if_pure_storage_exceeded) {
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2611 PURESIZE_h(PURESIZE + pure_lossage);
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2612 rc = -1;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2613 }
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 int lost = (PURESIZE - pureptr) / 1024;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 char buf[200];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 sprintf (buf, "Purespace usage: %ld of %ld (%d%%",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 pureptr, (long) PURESIZE,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (int) (pureptr / (PURESIZE / 100.0) + 0.5));
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2623 if (lost > 2) {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 sprintf (buf + strlen (buf), " -- %dk wasted", lost);
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2625 if (die_if_pure_storage_exceeded) {
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2626 PURESIZE_h(pureptr + 16);
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2627 rc = -1;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2628 }
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2629 }
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2630
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 strcat (buf, ").");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 message ("%s", buf);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 int iii;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 purestat_vector_other.nbytes =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 purestat_vector_all.nbytes - purestat_vector_bytecode_constants.nbytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 purestat_vector_other.nobjects =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 purestat_vector_all.nobjects -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 purestat_vector_bytecode_constants.nobjects;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 purestat_string_other.nbytes =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 purestat_string_all.nbytes - (purestat_string_pname.nbytes +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 purestat_string_bytecodes.nbytes +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 purestat_string_interactive.nbytes +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 purestat_string_documentation.nbytes +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 purestat_string_domain.nbytes +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 purestat_string_other_function.nbytes);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 purestat_string_other.nobjects =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 purestat_string_all.nobjects - (purestat_string_pname.nobjects +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 purestat_string_bytecodes.nobjects +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 purestat_string_interactive.nobjects +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 purestat_string_documentation.nobjects +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 purestat_string_domain.nobjects +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 purestat_string_other_function.nobjects);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 message (" %-24stotal: bytes:", "");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 for (iii = 0; iii < countof (purestats); iii++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 if (!purestats[iii])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 clear_message ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 message (" %-24s%5d %7d %2d%%",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 purestats[iii]->name,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 purestats[iii]->nobjects,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 purestats[iii]->nbytes,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (int) (purestats[iii]->nbytes / (pureptr / 100.0) + 0.5));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 if (report_impurities)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 Lisp_Object tem = Felt (Fgarbage_collect (), make_int (5));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 GCPRO1 (tem);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 message ("\nImpurities:");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 while (!NILP (tem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 if (CONSP (tem) && SYMBOLP (Fcar (tem)) && CONSP (Fcdr (tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 int total = XINT (Fcar (Fcdr (tem)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 if (total > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 char buf [100];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 char *s = buf;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 memcpy (buf, string_data (XSYMBOL (Fcar (tem))->name),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 string_length (XSYMBOL (Fcar (tem))->name) + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 while (*s++) if (*s == '-') *s = ' ';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 s--; *s++ = ':'; *s = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 message (" %-32s%6d", buf, total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 tem = Fcdr (Fcdr (tem));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 else /* WTF?! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 Fprin1 (tem, Qexternal_debugging_output);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 tem = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 garbage_collect_1 (); /* GC garbage_collect's garbage */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 clear_message ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2713 if (rc < 0) {
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2714 fatal ("Pure size adjusted, will restart `make'");
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2715 } else if (pure_lossage && die_if_pure_storage_exceeded) {
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 fatal ("Pure storage exhausted");
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2717 }
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
2718 (void)sys_unlink("SATISFIED");
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 /* staticpro */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 /**********************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 struct gcpro *gcprolist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 /* 415 used Mly 29-Jun-93 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 #define NSTATICS 1500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 /* Not "static" because of linker lossage on some systems */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 Lisp_Object *staticvec[NSTATICS]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 /* Force it into data space! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 = {0};
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 static int staticidx;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 /* Put an entry in staticvec, pointing at the variable whose address is given
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 staticpro (Lisp_Object *varaddress)
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 (staticidx >= countof (staticvec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 staticvec[staticidx++] = varaddress;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 /* 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
2748 seen yet, recursively mark all the references contained in it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 mark_object (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 tail_recurse:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 if (!POINTER_TYPE_P (XGCTYPE (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 if (PURIFIED (XPNTR (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 switch (XGCTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 case Lisp_Cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 struct Lisp_Cons *ptr = XCONS (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 if (CONS_MARKED_P (ptr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 MARK_CONS (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 /* If the cdr is nil, tail-recurse on the car. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 if (NILP (ptr->cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 obj = ptr->car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 mark_object (ptr->car);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 obj = ptr->cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 case Lisp_Record:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 /* case Lisp_Symbol_Value_Magic: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 CONST struct lrecord_implementation *implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 = lheader->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 if (! MARKED_RECORD_HEADER_P (lheader) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 ! UNMARKABLE_RECORD_HEADER_P (lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 MARK_RECORD_HEADER (lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 if (!implementation->basic_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 assert (! ((struct lcrecord_header *) lheader)->free);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 if (implementation->marker != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 obj = ((implementation->marker) (obj, mark_object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 if (!NILP (obj)) goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 case Lisp_String:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 struct Lisp_String *ptr = XSTRING (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 if (!XMARKBIT (ptr->plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 if (CONSP (ptr->plist) &&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 EXTENT_INFOP (XCAR (ptr->plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 flush_cached_extent_info (XCAR (ptr->plist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 XMARK (ptr->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 obj = ptr->plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 case Lisp_Vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 struct Lisp_Vector *ptr = XVECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 int len = vector_length (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 if (len < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 break; /* Already marked */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 ptr->size = -1 - len; /* Else mark it */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 for (i = 0; i < len - 1; i++) /* and then mark its elements */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 mark_object (ptr->contents[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 if (len > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 obj = ptr->contents[len - 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 #ifndef LRECORD_SYMBOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 case Lisp_Symbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 struct Lisp_Symbol *sym = XSYMBOL (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 while (!XMARKBIT (sym->plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 XMARK (sym->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 mark_object (sym->value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 mark_object (sym->function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 /* Open-code mark_string */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 /* symbol->name is a struct Lisp_String *, not a Lisp_Object */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 struct Lisp_String *pname = sym->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 if (!PURIFIED (pname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 && !XMARKBIT (pname->plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 XMARK (pname->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 mark_object (pname->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 if (!symbol_next (sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 obj = sym->plist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 mark_object (sym->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 /* Mark the rest of the symbols in the hash-chain */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 sym = symbol_next (sym);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 #endif /* !LRECORD_SYMBOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 /* 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
2879 DO NOT mark the cars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 Use only for internal lists! There should never be other pointers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 to the cons cells, because if so, the cars will remain unmarked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 even when they maybe should be marked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 mark_conses_in_list (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 for (rest = obj; CONSP (rest); rest = XCDR (rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 if (CONS_MARKED_P (XCONS (rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 MARK_CONS (XCONS (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 mark_object (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 /* Simpler than mark-object, because pure structure can't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 have any circularities
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 static int idiot_c_doesnt_have_closures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 idiot_c (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 idiot_c_doesnt_have_closures += pure_sizeof (obj, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 /* recurse arg isn't actually used */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 pure_sizeof (Lisp_Object obj /*, int recurse */)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 int total = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920 /*tail_recurse: */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 if (!POINTER_TYPE_P (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 || !PURIFIED (XPNTR (obj)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 return (total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 /* symbol's sizes are accounted for separately */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 if (SYMBOLP (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 return (total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 switch (XTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 case Lisp_String:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 struct Lisp_String *ptr = XSTRING (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 int size = string_length (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 if (string_data (ptr) !=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 (unsigned char *) ptr + sizeof (struct Lisp_String))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 /* string-data not allocated contiguously.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 Probably (better be!!) a pointer constant "C" data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 size = sizeof (struct Lisp_String);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 size = sizeof (struct Lisp_String) + size + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 size = ALIGN_SIZE (size, sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 total += size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 case Lisp_Vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 struct Lisp_Vector *ptr = XVECTOR (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 int len = vector_length (ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 total += (sizeof (struct Lisp_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 + (len - 1) * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 if (!recurse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 for (i = 0; i < len - 1; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 total += pure_sizeof (ptr->contents[i], 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 if (len > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 obj = ptr->contents[len - 1];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 case Lisp_Record:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 CONST struct lrecord_implementation *implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 = lheader->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 if (implementation->size_in_bytes_method)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 total += ((implementation->size_in_bytes_method) (lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 total += implementation->static_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 if (!recurse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 if (implementation->marker != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 int old = idiot_c_doesnt_have_closures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 idiot_c_doesnt_have_closures = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 obj = ((implementation->marker) (obj, idiot_c));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 total += idiot_c_doesnt_have_closures;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 idiot_c_doesnt_have_closures = old;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 if (!NILP (obj)) goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 case Lisp_Cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 struct Lisp_Cons *ptr = XCONS (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 total += sizeof (*ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 #if 0 /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 if (!recurse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 /* If the cdr is nil, tail-recurse on the car. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 if (NILP (ptr->cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 obj = ptr->car;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 total += pure_sizeof (ptr->car, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 obj = ptr->cdr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 goto tail_recurse;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 #endif /* unused */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 /* Others can't be purified */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 return (total);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 #endif /* PURESTAT */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 /* Find all structures not marked, and free them. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 static int gc_count_num_vector_used, gc_count_vector_total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 static int gc_count_vector_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 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
3044 static int gc_count_bit_vector_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 static int gc_count_num_short_string_in_use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 static int gc_count_string_total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 static int gc_count_short_string_total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 /* static int gc_count_total_records_used, gc_count_records_total_size; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 /* This will be used more extensively In The Future */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 static int last_lrecord_type_index_assigned;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 static CONST struct lrecord_implementation *lrecord_implementations_table[128];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 #define max_lrecord_type (countof (lrecord_implementations_table) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 lrecord_type_index (CONST struct lrecord_implementation *implementation)
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 type_index = *(implementation->lrecord_type_index);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 /* Have to do this circuitous and validation test because of problems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 dumping out initialized variables (ie can't set xxx_type_index to -1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 because that would make xxx_type_index read-only in a dumped emacs. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 if (type_index < 0 || type_index > max_lrecord_type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 || lrecord_implementations_table[type_index] != implementation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 if (last_lrecord_type_index_assigned == max_lrecord_type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 type_index = ++last_lrecord_type_index_assigned;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 lrecord_implementations_table[type_index] = implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 *(implementation->lrecord_type_index) = type_index;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 return (type_index);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 /* stats on lcrecords in use - kinda kludgy */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 static struct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 int instances_in_use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 int bytes_in_use;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 int instances_freed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 int bytes_freed;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 int instances_on_free_list;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 } lcrecord_stats [countof (lrecord_implementations_table)];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 reset_lcrecord_stats (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 for (i = 0; i < countof (lcrecord_stats); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 lcrecord_stats[i].instances_in_use = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 lcrecord_stats[i].bytes_in_use = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 lcrecord_stats[i].instances_freed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 lcrecord_stats[i].bytes_freed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 lcrecord_stats[i].instances_on_free_list = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 tick_lcrecord_stats (CONST struct lrecord_header *h, int free_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 CONST struct lrecord_implementation *implementation = h->implementation;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 int type_index = lrecord_type_index (implementation);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 if (((struct lcrecord_header *) h)->free)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 assert (!free_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 lcrecord_stats[type_index].instances_on_free_list++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 unsigned int sz = (implementation->size_in_bytes_method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 ? ((implementation->size_in_bytes_method) (h))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 : implementation->static_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 if (free_p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 lcrecord_stats[type_index].instances_freed++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 lcrecord_stats[type_index].bytes_freed += sz;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 lcrecord_stats[type_index].instances_in_use++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 lcrecord_stats[type_index].bytes_in_use += sz;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 /* Free all unmarked records */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 struct lcrecord_header *header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 int num_used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 /* int total_size = 0; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 reset_lcrecord_stats ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 /* First go through and call all the finalize methods.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 Then go through and free the objects. There used to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 be only one loop here, with the call to the finalizer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 occurring directly before the xfree() below. That
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 is marginally faster but much less safe -- if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 finalize method for an object needs to reference any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 other objects contained within it (and many do),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 we could easily be screwed by having already freed that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 other object. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 for (header = *prev; header; header = header->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 struct lrecord_header *h = &(header->lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 if (!MARKED_RECORD_HEADER_P (h) && ! (header->free))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 if (h->implementation->finalizer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 ((h->implementation->finalizer) (h, 0));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 for (header = *prev; header; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 struct lrecord_header *h = &(header->lheader);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 if (MARKED_RECORD_HEADER_P (h))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 UNMARK_RECORD_HEADER (h);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 num_used++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 /* total_size += ((n->implementation->size_in_bytes) (h));*/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 prev = &(header->next);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 header = *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 tick_lcrecord_stats (h, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 struct lcrecord_header *next = header->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 *prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 tick_lcrecord_stats (h, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 /* used to call finalizer right here. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 xfree (header);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 header = next;
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 *used = num_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 /* *total = total_size; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 sweep_vectors_1 (Lisp_Object *prev,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 int *used, int *total, int *storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 Lisp_Object vector;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 int num_used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 int total_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 int total_storage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 for (vector = *prev; VECTORP (vector); )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 struct Lisp_Vector *v = XVECTOR (vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 int len = v->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 if (len < 0) /* marked */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 len = - (len + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 v->size = len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 total_size += len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 total_storage += (MALLOC_OVERHEAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 + sizeof (struct Lisp_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 + (len - 1 + 1) * sizeof (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 num_used++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 prev = &(vector_next (v));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 vector = *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 Lisp_Object next = vector_next (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 *prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 xfree (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 vector = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 *used = num_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 *total = total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 *storage = total_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 sweep_bit_vectors_1 (Lisp_Object *prev,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 int *used, int *total, int *storage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 Lisp_Object bit_vector;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 int num_used = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 int total_size = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 int total_storage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 /* BIT_VECTORP fails because the objects are marked, which changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 their implementation */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 for (bit_vector = *prev; !EQ (bit_vector, Qzero); )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 struct Lisp_Bit_Vector *v = XBIT_VECTOR (bit_vector);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 int len = v->size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 if (MARKED_RECORD_P (bit_vector))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 UNMARK_RECORD_HEADER (&(v->lheader));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 total_size += len;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 total_storage += (MALLOC_OVERHEAD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 + sizeof (struct Lisp_Bit_Vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 + (BIT_VECTOR_LONG_STORAGE (len) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 * sizeof (long));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 num_used++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 prev = &(bit_vector_next (v));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 bit_vector = *prev;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 Lisp_Object next = bit_vector_next (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 *prev = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 xfree (v);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 bit_vector = next;
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 *used = num_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 *total = total_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 *storage = total_storage;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 /* And the Lord said: Thou shalt use the `c-backslash-region' command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 to make macros prettier. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 struct typename##_block *_frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 struct typename##_block **_frob_prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 int _frob_limit; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 int num_free = 0, num_used = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 for (_frob_prev = &current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 _frob_current = current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 _frob_limit = current_##typename##_block_index; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 _frob_current; \
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 int _frob_iii; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 if (FREE_STRUCT_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 else if (!MARKED_##typename##_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 num_used++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 UNMARK_##typename (_frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 _frob_prev = &(_frob_current->prev); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 _frob_current = _frob_current->prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 _frob_limit = countof (current_##typename##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 gc_count_num_##typename##_in_use = num_used; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 gc_count_num_##typename##_freelist = num_free; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 do { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 struct typename##_block *_frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 struct typename##_block **_frob_prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 int _frob_limit; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 int num_free = 0, num_used = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 typename##_free_list = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 for (_frob_prev = &current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 _frob_current = current_##typename##_block, \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 _frob_limit = current_##typename##_block_index; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 _frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 ) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 int _frob_iii; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 int _frob_empty = 1; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 obj_type *_frob_old_free_list = typename##_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 if (FREE_STRUCT_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, _frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 else if (!MARKED_##typename##_P (_frob_victim)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 num_free++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 _frob_empty = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 num_used++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 UNMARK_##typename (_frob_victim); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 } \
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 (!_frob_empty) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 _frob_prev = &(_frob_current->prev); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 _frob_current = _frob_current->prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 else if (_frob_current == current_##typename##_block \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 && !_frob_current->prev) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 /* No real point in freeing sole allocation block */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 break; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 else \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 struct typename##_block *_frob_victim_block = _frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 if (_frob_victim_block == current_##typename##_block) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 current_##typename##_block_index \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 = countof (current_##typename##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 _frob_current = _frob_current->prev; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376 *_frob_prev = _frob_current; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 xfree (_frob_victim_block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 /* Restore free list to what it was before victim was swept */ \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 typename##_free_list = _frob_old_free_list; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 num_free -= _frob_limit; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 _frob_limit = countof (current_##typename##_block->block); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 gc_count_num_##typename##_in_use = num_used; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 gc_count_num_##typename##_freelist = num_free; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 sweep_conses (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 #define MARKED_cons_P(ptr) XMARKBIT ((ptr)->car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 #define UNMARK_cons(ptr) do { XUNMARK ((ptr)->car); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 #define ADDITIONAL_FREE_cons(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 SWEEP_FIXED_TYPE_BLOCK (cons, struct Lisp_Cons);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 /* Explicitly free a cons cell. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 free_cons (struct Lisp_Cons *ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 /* 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
3411 always be four-byte aligned. If this cons cell has already been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 placed on the free list, however, its car will probably contain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 a chain pointer to the next cons on the list, which has cleverly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 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
3415 check to make sure we're not freeing something already freed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 if (POINTER_TYPE_P (XTYPE (ptr->car)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 ASSERT_VALID_POINTER (XPNTR (ptr->car));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 #ifndef ALLOC_NO_POOLS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, struct Lisp_Cons, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 #endif /* ALLOC_NO_POOLS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 /* explicitly free a list. You **must make sure** that you have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 created all the cons cells that make up this list and that there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 are no pointers to any of these cons cells anywhere else. If there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 are, you will lose. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 free_list (Lisp_Object list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 Lisp_Object rest, next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 for (rest = list; !NILP (rest); rest = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 next = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 free_cons (XCONS (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 /* explicitly free an alist. You **must make sure** that you have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 created all the cons cells that make up this alist and that there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 are no pointers to any of these cons cells anywhere else. If there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 are, you will lose. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 free_alist (Lisp_Object alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 Lisp_Object rest, next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 for (rest = alist; !NILP (rest); rest = next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 next = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 free_cons (XCONS (XCAR (rest)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 free_cons (XCONS (rest));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 sweep_compiled_functions (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 #define MARKED_compiled_function_P(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 #define ADDITIONAL_FREE_compiled_function(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 SWEEP_FIXED_TYPE_BLOCK (compiled_function, struct Lisp_Compiled_Function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 sweep_floats (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 #define MARKED_float_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 #define ADDITIONAL_FREE_float(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 SWEEP_FIXED_TYPE_BLOCK (float, struct Lisp_Float);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 sweep_symbols (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 #ifndef LRECORD_SYMBOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 # define MARKED_symbol_P(ptr) XMARKBIT ((ptr)->plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 # define UNMARK_symbol(ptr) do { XUNMARK ((ptr)->plist); } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 # define MARKED_symbol_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 # define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 #endif /* !LRECORD_SYMBOL */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 #define ADDITIONAL_FREE_symbol(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 SWEEP_FIXED_TYPE_BLOCK (symbol, struct Lisp_Symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 #ifndef standalone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 sweep_extents (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 #define MARKED_extent_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 #define ADDITIONAL_FREE_extent(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 sweep_events (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 #define MARKED_event_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 #define ADDITIONAL_FREE_event(ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 SWEEP_FIXED_TYPE_BLOCK (event, struct Lisp_Event);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 sweep_markers (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 #define MARKED_marker_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 #define ADDITIONAL_FREE_marker(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 do { Lisp_Object tem; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 XSETMARKER (tem, ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 unchain_marker (tem); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 SWEEP_FIXED_TYPE_BLOCK (marker, struct Lisp_Marker);
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 /* Explicitly free a marker. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 free_marker (struct Lisp_Marker *ptr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 #ifdef ERROR_CHECK_GC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 /* Perhaps this will catch freeing an already-freed marker. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 Lisp_Object temmy;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 XSETMARKER (temmy, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 assert (GC_MARKERP (temmy));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 #ifndef ALLOC_NO_POOLS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, struct Lisp_Marker, ptr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 #endif /* ALLOC_NO_POOLS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 #endif /* not standalone */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 /* Compactify string chars, relocating the reference to each --
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 free any empty string_chars_block we see. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 compact_string_chars (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 struct string_chars_block *to_sb = first_string_chars_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 int to_pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 struct string_chars_block *from_sb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 /* Scan each existing string block sequentially, string by string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 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
3564 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 int from_pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 /* FROM_POS is the index of the next string in the block. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 while (from_pos < from_sb->pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 struct string_chars *from_s_chars =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 (struct string_chars *) &(from_sb->string_chars[from_pos]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 struct string_chars *to_s_chars;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 struct Lisp_String *string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 int size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 int fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 /* If the string_chars struct is marked as free (i.e. the STRING
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 pointer is 0xFFFFFFFF) then this is an unused chunk of string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 storage. This happens under Mule when a string's size changes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 in such a way that its fullsize changes. (Strings can change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 size because a different-length character can be substituted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 for another character.) In this case, after the bogus string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 pointer is the "fullsize" of this entry, i.e. how many bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 to skip. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 if (FREE_STRUCT_P (from_s_chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 from_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 string = from_s_chars->string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 assert (!(FREE_STRUCT_P (string)));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 size = string_length (string);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 fullsize = STRING_FULLSIZE (size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 if (BIG_STRING_FULLSIZE_P (fullsize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 /* Just skip it if it isn't marked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 if (!XMARKBIT (string->plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 from_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 /* 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
3609 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
3610 cannot advance past FROM_SB here since FROM_SB is large enough
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 to currently contain this string. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 if ((to_pos + fullsize) > countof (to_sb->string_chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 to_sb->pos = to_pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 to_sb = to_sb->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 to_pos = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 /* Compute new address of this string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 and update TO_POS for the space being used. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 /* Copy the string_chars to the new place. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 if (from_s_chars != to_s_chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 memmove (to_s_chars, from_s_chars, fullsize);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 /* Relocate FROM_S_CHARS's reference */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 set_string_data (string, &(to_s_chars->chars[0]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 from_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 to_pos += fullsize;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 /* Set current to the last string chars block still used and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 free any that follow. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 struct string_chars_block *victim;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 for (victim = to_sb->next; victim; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 struct string_chars_block *next = victim->next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 xfree (victim);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 victim = next;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 current_string_chars_block = to_sb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 current_string_chars_block->pos = to_pos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 current_string_chars_block->next = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 #if 1 /* Hack to debug missing purecopy's */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 static int debug_string_purity;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 debug_string_purity_print (struct Lisp_String *p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 Charcount i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 Charcount s = string_char_length (p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 putc ('\"', stderr);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 for (i = 0; i < s; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 Emchar ch = string_char (p, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 if (ch < 32 || ch >= 126)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 stderr_out ("\\%03o", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 else if (ch == '\\' || ch == '\"')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 stderr_out ("\\%c", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 stderr_out ("%c", ch);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 stderr_out ("\"\n");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 sweep_strings (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 int num_small_used = 0, num_small_bytes = 0, num_bytes = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 int debug = debug_string_purity;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 #define MARKED_string_P(ptr) XMARKBIT ((ptr)->plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 #define UNMARK_string(ptr) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 do { struct Lisp_String *p = (ptr); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 int size = string_length (p); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 XUNMARK (p->plist); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 num_bytes += size; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 if (!BIG_STRING_SIZE_P (size)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 { num_small_bytes += size; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 num_small_used++; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 if (debug) debug_string_purity_print (p); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 #define ADDITIONAL_FREE_string(p) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 do { int size = string_length (p); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 if (BIG_STRING_SIZE_P (size)) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 xfree_1 (CHARS_TO_STRING_CHAR (string_data (p))); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 } while (0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 SWEEP_FIXED_TYPE_BLOCK (string, struct Lisp_String);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 gc_count_num_short_string_in_use = num_small_used;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 gc_count_string_total_size = num_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 gc_count_short_string_total_size = num_small_bytes;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 /* I hate duplicating all this crap! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 marked_p (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 if (!POINTER_TYPE_P (XGCTYPE (obj))) return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 if (PURIFIED (XPNTR (obj))) return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 switch (XGCTYPE (obj))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 case Lisp_Cons:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 return XMARKBIT (XCAR (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 case Lisp_Record:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 return MARKED_RECORD_HEADER_P (XRECORD_LHEADER (obj));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 case Lisp_String:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 return XMARKBIT (XSTRING (obj)->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 case Lisp_Vector:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 return (vector_length (XVECTOR (obj)) < 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 #ifndef LRECORD_SYMBOL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 case Lisp_Symbol:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 return XMARKBIT (XSYMBOL (obj)->plist);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 default:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 abort ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 return 0; /* suppress compiler warning */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 gc_sweep (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 /* Free all unmarked records. Do this at the very beginning,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 before anything else, so that the finalize methods can safely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 examine items in the objects. sweep_lcrecords_1() makes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 sure to call all the finalize methods *before* freeing anything,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 to complete the safety. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 int ignored;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 sweep_lcrecords_1 (&all_lcrecords, &ignored);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 compact_string_chars ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 /* Finalize methods below (called through the ADDITIONAL_FREE_foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 macros) must be *extremely* careful to make sure they're not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 referencing freed objects. The only two existing finalize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 methods (for strings and markers) pass muster -- the string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 finalizer doesn't look at anything but its own specially-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 created block, and the marker finalizer only looks at live
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 buffers (which will never be freed) and at the markers before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 and after it in the chain (which, by induction, will never be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 freed because if so, they would have already removed themselves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 from the chain). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 /* Put all unmarked strings on free list, free'ing the string chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 of large unmarked strings */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 sweep_strings ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 /* Put all unmarked conses on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 sweep_conses ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 /* Free all unmarked vectors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 sweep_vectors_1 (&all_vectors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 &gc_count_num_vector_used, &gc_count_vector_total_size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 &gc_count_vector_storage);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 /* Free all unmarked bit vectors */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 sweep_bit_vectors_1 (&all_bit_vectors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 &gc_count_num_bit_vector_used,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 &gc_count_bit_vector_total_size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 &gc_count_bit_vector_storage);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 /* Free all unmarked compiled-function objects */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 sweep_compiled_functions ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 /* Put all unmarked floats on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 sweep_floats ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 /* Put all unmarked symbols on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 sweep_symbols ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 /* Put all unmarked extents on free list */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 sweep_extents ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 /* Put all unmarked markers on free list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 Dechain each one first from the buffer into which it points. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 sweep_markers ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 sweep_events ();
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 /* Clearing for disksave. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 extern Lisp_Object Vprocess_environment;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 extern Lisp_Object Vdoc_directory;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 extern Lisp_Object Vconfigure_info_directory;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 extern Lisp_Object Vload_path;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 extern Lisp_Object Vload_history;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 extern Lisp_Object Vshell_file_name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 disksave_object_finalization (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 /* It's important that certain information from the environment not get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 dumped with the executable (pathnames, environment variables, etc.).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 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
3816 clear some known-to-be-garbage blocks of memory, so that leftover
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 results of old evaluation don't look like potential problems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 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
3819 to turn those strings into garbage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 /* Yeah, this list is pretty ad-hoc... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 Vprocess_environment = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 Vexec_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 Vdata_directory = Qnil;
32
e04119814345 Import from CVS: tag r19-15b99
cvs
parents: 30
diff changeset
3826 Vsite_directory = Qnil;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 Vdoc_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 Vconfigure_info_directory = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 Vexec_path = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 Vload_path = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831 /* Vdump_load_path = Qnil; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 Vload_history = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 Vshell_file_name = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 garbage_collect_1 ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 /* Run the disksave finalization methods of all live objects. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 disksave_object_finalization_1 ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 /* Zero out the unused portion of purespace */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 if (!pure_lossage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 memset ( (char *) (PUREBEG + pureptr), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 (((char *) (PUREBEG + PURESIZE)) -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844 ((char *) (PUREBEG + pureptr))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 /* Zero out the uninitialized (really, unused) part of the containers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 for the live strings. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 struct string_chars_block *scb;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 for (scb = first_string_chars_block; scb; scb = scb->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 /* from the block's fill ptr to the end */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 memset ((scb->string_chars + scb->pos), 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 sizeof (scb->string_chars) - scb->pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 /* There, that ought to be enough... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 restore_gc_inhibit (Lisp_Object val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 gc_currently_forbidden = XINT (val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 return val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 /* 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
3869 static int gc_hooks_inhibited;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 garbage_collect_1 (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 char stack_top_variable;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 extern char *stack_bottom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878 struct frame *f = selected_frame ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 int speccount = specpdl_depth ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 Lisp_Object pre_gc_cursor = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 struct gcpro gcpro1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 int cursor_changed = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 if (gc_in_progress != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 if (gc_currently_forbidden || in_display)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 if (preparing_for_armageddon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 GCPRO1 (pre_gc_cursor);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 /* Very important to prevent GC during any of the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 stuff that might run Lisp code; otherwise, we'll likely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 have infinite GC recursion. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 record_unwind_protect (restore_gc_inhibit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 make_int (gc_currently_forbidden));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 gc_currently_forbidden = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 if (!gc_hooks_inhibited)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 run_hook_trapping_errors ("Error in pre-gc-hook", Qpre_gc_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 /* Now show the GC cursor/message. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 if (!noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 if (FRAME_WIN_P (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911 Lisp_Object frame = make_frame (f);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912 Lisp_Object cursor = glyph_image_instance (Vgc_pointer_glyph,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913 FRAME_SELECTED_WINDOW (f),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 ERROR_ME_NOT, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 pre_gc_cursor = f->pointer;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916 if (POINTER_IMAGE_INSTANCEP (cursor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 /* don't change if we don't know how to change back. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918 && POINTER_IMAGE_INSTANCEP (pre_gc_cursor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920 cursor_changed = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921 Fset_frame_pointer (frame, cursor);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 /* Don't print messages to the stream device. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 if (!cursor_changed && !FRAME_STREAM_P (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 char *msg = (STRINGP (Vgc_message)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
3929 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 : 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 Lisp_Object args[2], whole_msg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932 args[0] = build_string (msg ? msg :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933 GETTEXT ((CONST char *) gc_default_message));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934 args[1] = build_string ("...");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 whole_msg = Fconcat (2, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 echo_area_message (f, (Bufbyte *) 0, whole_msg, 0, -1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 Qgarbage_collecting);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 /***** Now we actually start the garbage collection. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943 gc_in_progress = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 gc_generation_number[0]++;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 #if MAX_SAVE_STACK > 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 /* Save a copy of the contents of the stack, for debugging. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 if (!purify_flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 i = &stack_top_variable - stack_bottom;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 if (i < 0) i = -i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 if (i < MAX_SAVE_STACK)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 if (stack_copy == 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 stack_copy = (char *) malloc (stack_copy_size = i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 else if (stack_copy_size < i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 stack_copy = (char *) realloc (stack_copy, (stack_copy_size = i));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 if (stack_copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 if ((int) (&stack_top_variable - stack_bottom) > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 memcpy (stack_copy, stack_bottom, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965 memcpy (stack_copy, &stack_top_variable, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969 #endif /* MAX_SAVE_STACK > 0 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 /* Do some totally ad-hoc resource clearing. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3972 /* #### generalize this? */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973 clear_event_resource ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 cleanup_specifiers ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 /* Mark all the special slots that serve as the roots of accessibility. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 struct gcpro *tail;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 struct catchtag *catch;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 struct backtrace *backlist;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 struct specbinding *bind;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 for (i = 0; i < staticidx; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 #ifdef GDB_SUCKS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986 printf ("%d\n", i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 debug_print (*staticvec[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 mark_object (*(staticvec[i]));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 for (tail = gcprolist; tail; tail = tail->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 for (i = 0; i < tail->nvars; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 mark_object (tail->var[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 for (bind = specpdl; bind != specpdl_ptr; bind++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3999 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 mark_object (bind->symbol);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 mark_object (bind->old_value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 for (catch = catchlist; catch; catch = catch->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 mark_object (catch->tag);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007 mark_object (catch->val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 for (backlist = backtrace_list; backlist; backlist = backlist->next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 int nargs = backlist->nargs;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 mark_object (*backlist->function);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 if (nargs == UNEVALLED || nargs == MANY)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4016 mark_object (backlist->args[0]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 for (i = 0; i < nargs; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019 mark_object (backlist->args[i]);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 mark_redisplay (mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4023 mark_profiling_info (mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4024 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026 /* OK, now do the after-mark stuff. This is for things that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 are only marked when something else is marked (e.g. weak hashtables).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4028 There may be complex dependencies between such objects -- e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 a weak hashtable might be unmarked, but after processing a later
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030 weak hashtable, the former one might get marked. So we have to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 iterate until nothing more gets marked. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033 int did_mark;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034 /* Need to iterate until there's nothing more to mark, in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035 of chains of mark dependencies. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038 did_mark = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 did_mark += !!finish_marking_weak_hashtables (marked_p, mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 did_mark += !!finish_marking_weak_lists (marked_p, mark_object);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042 while (did_mark);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 /* And prune (this needs to be called after everything else has been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046 marked and before we do any sweeping). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 /* #### this is somewhat ad-hoc and should probably be an object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 method */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049 prune_weak_hashtables (marked_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 prune_weak_lists (marked_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 prune_specifiers (marked_p);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 gc_sweep ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 consing_since_gc = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 #ifndef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4057 /* Allow you to set it really fucking low if you really want ... */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4058 if (gc_cons_threshold < 10000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4059 gc_cons_threshold = 10000;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062 gc_in_progress = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 /******* End of garbage collection ********/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066 run_hook_trapping_errors ("Error in post-gc-hook", Qpost_gc_hook);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068 /* Now remove the GC cursor/message */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 if (!noninteractive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 if (cursor_changed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072 Fset_frame_pointer (make_frame (f), pre_gc_cursor);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 else if (!FRAME_STREAM_P (f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075 char *msg = (STRINGP (Vgc_message)
14
9ee227acff29 Import from CVS: tag r19-15b90
cvs
parents: 0
diff changeset
4076 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4077 : 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079 /* Show "...done" only if the echo area would otherwise be empty. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 if (NILP (clear_echo_area (selected_frame (),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 Qgarbage_collecting, 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 Lisp_Object args[2], whole_msg;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 args[0] = build_string (msg ? msg :
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085 GETTEXT ((CONST char *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 gc_default_message));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 args[1] = build_string ("... done");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4088 whole_msg = Fconcat (2, args);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089 echo_area_message (selected_frame (), (Bufbyte *) 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090 whole_msg, 0, -1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 Qgarbage_collecting);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 /* now stop inhibiting GC */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 unbind_to (speccount, Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 if (!breathing_space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 breathing_space = (void *) malloc (4096 - MALLOC_OVERHEAD);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 UNGCPRO;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 #ifdef EMACS_BTL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 /* This isn't actually called. BTL recognizes the stack frame of the top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 of the garbage collector by noting that PC is between &garbage_collect_1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 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
4112 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
4113 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 void BTL_after_garbage_collect_1_stub () { abort (); }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 /* Debugging aids. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120 gc_plist_hack (CONST char *name, int value, Lisp_Object tail)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4121 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4122 /* C doesn't have local functions (or closures, or GC, or readable syntax,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4123 or portable numeric datatypes, or bit-vectors, or characters, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4124 arrays, or exceptions, or ...) */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4125 return (cons3 (intern (name), make_int (value), tail));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4126 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4128 #define HACK_O_MATIC(type, name, pl) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4129 { \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4130 int s = 0; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4131 struct type##_block *x = current_##type##_block; \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4132 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4133 (pl) = gc_plist_hack ((name), s, (pl)); \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4134 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4136 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 Reclaim storage for Lisp objects no longer needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138 Returns info on amount of space in use:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141 PLIST)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 where `PLIST' is a list of alternating keyword/value pairs providing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 more detailed information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144 Garbage collection happens automatically if you cons more than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4146 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4147 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149 Lisp_Object pl = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 Lisp_Object ret[6];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
4153 if (purify_flag && pure_lossage)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
4154 {
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
4155 return Qnil;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
4156 }
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents: 20
diff changeset
4157
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158 garbage_collect_1 ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160 for (i = 0; i < last_lrecord_type_index_assigned; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4161 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4162 if (lcrecord_stats[i].bytes_in_use != 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4163 || lcrecord_stats[i].bytes_freed != 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4164 || lcrecord_stats[i].instances_on_free_list != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 char buf [255];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 CONST char *name = lrecord_implementations_table[i]->name;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168 int len = strlen (name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 sprintf (buf, "%s-storage", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 /* Okay, simple pluralization check for `symbol-value-varalias' */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172 if (name[len-1] == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173 sprintf (buf, "%ses-freed", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 sprintf (buf, "%ss-freed", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4176 if (lcrecord_stats[i].instances_freed != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 if (name[len-1] == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 sprintf (buf, "%ses-on-free-list", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 sprintf (buf, "%ss-on-free-list", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 if (lcrecord_stats[i].instances_on_free_list != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184 pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 if (name[len-1] == 's')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 sprintf (buf, "%ses-used", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188 sprintf (buf, "%ss-used", name);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl);
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 HACK_O_MATIC (extent, "extent-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 HACK_O_MATIC (event, "event-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 HACK_O_MATIC (marker, "marker-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4201 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4202 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203 HACK_O_MATIC (float, "float-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4204 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4205 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 HACK_O_MATIC (string, "string-header-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208 pl = gc_plist_hack ("long-strings-total-length",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 gc_count_string_total_size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210 - gc_count_short_string_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 HACK_O_MATIC (string_chars, "short-string-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 pl = gc_plist_hack ("short-strings-total-length",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213 gc_count_short_string_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215 pl = gc_plist_hack ("long-strings-used",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4216 gc_count_num_string_in_use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 - gc_count_num_short_string_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 pl = gc_plist_hack ("short-strings-used",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4219 gc_count_num_short_string_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 pl = gc_plist_hack ("compiled-functions-free",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 gc_count_num_compiled_function_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224 pl = gc_plist_hack ("compiled-functions-used",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225 gc_count_num_compiled_function_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227 pl = gc_plist_hack ("vector-storage", gc_count_vector_storage, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 pl = gc_plist_hack ("vectors-total-length",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 gc_count_vector_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 pl = gc_plist_hack ("vectors-used", gc_count_num_vector_used, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 pl = gc_plist_hack ("bit-vector-storage", gc_count_bit_vector_storage, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 pl = gc_plist_hack ("bit-vectors-total-length",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 gc_count_bit_vector_total_size, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235 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
4236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 HACK_O_MATIC (symbol, "symbol-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4238 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4239 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4240
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4241 HACK_O_MATIC (cons, "cons-storage", pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245 /* The things we do for backwards-compatibility */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 ret[0] = Fcons (make_int (gc_count_num_cons_in_use),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247 make_int (gc_count_num_cons_freelist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 ret[1] = Fcons (make_int (gc_count_num_symbol_in_use),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249 make_int (gc_count_num_symbol_freelist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250 ret[2] = Fcons (make_int (gc_count_num_marker_in_use),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 make_int (gc_count_num_marker_freelist));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252 ret[3] = make_int (gc_count_string_total_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 ret[4] = make_int (gc_count_vector_total_size);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254 ret[5] = pl;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255 return (Flist (6, ret));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257 #undef HACK_O_MATIC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4258
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4259 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 Return the number of bytes consed since the last garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 \"Consed\" is a misnomer in that this actually counts allocation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 of all different kinds of objects, not just conses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264 If this value exceeds `gc-cons-threshold', a garbage collection happens.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4265 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4266 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 return (make_int (consing_since_gc));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4271 DEFUN ("memory-limit", Fmemory_limit, 0, 0, "", /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4272 Return the address of the last byte Emacs has allocated, divided by 1024.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273 This may be helpful in debugging Emacs's memory usage.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4274 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
4275 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4276 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4277 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4278 return (make_int ((EMACS_INT) sbrk (0) / 1024));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4279 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4283 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4284 object_dead_p (Lisp_Object obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4285 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4286 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4287 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4288 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4289 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4290 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4291 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) ||
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4292 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj))));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4294 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4296 #ifdef MEMORY_USAGE_STATS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298 /* Attempt to determine the actual amount of space that is used for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4301 It seems that the following holds:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4302
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 1. When using the old allocator (malloc.c):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4305 -- blocks are always allocated in chunks of powers of two. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306 each block, there is an overhead of 8 bytes if rcheck is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 defined, 20 bytes if it is defined. In other words, a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4308 one-byte allocation needs 8 bytes of overhead for a total of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4309 9 bytes, and needs to have 16 bytes of memory chunked out for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310 it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312 2. When using the new allocator (gmalloc.c):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 -- blocks are always allocated in chunks of powers of two up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315 to 4096 bytes. Larger blocks are allocated in chunks of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316 an integral multiple of 4096 bytes. The minimum block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4317 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4318 is defined. There is no per-block overhead, but there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4319 is an overhead of 3*sizeof (size_t) for each 4096 bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4320 allocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4322 3. When using the system malloc, anything goes, but they are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 generally slower and more space-efficient than the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324 allocators. One possibly reasonable assumption to make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325 for want of better data is that sizeof (void *), or maybe
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326 2 * sizeof (void *), is required as overhead and that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 blocks are allocated in the minimum required size except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 that some minimum block size is imposed (e.g. 16 bytes). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4330 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 malloced_storage_size (void *ptr, int claimed_size,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 struct overhead_stats *stats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4333 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4334 int orig_claimed_size = claimed_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4336 #ifdef GNU_MALLOC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 if (claimed_size < 2 * sizeof (void *))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 claimed_size = 2 * sizeof (void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 # ifdef SUNOS_LOCALTIME_BUG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 if (claimed_size < 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 claimed_size = 16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4343 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4344 if (claimed_size < 4096)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4345 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4346 int log = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4348 /* compute the log base two, more or less, then use it to compute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4349 the block size needed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4350 claimed_size--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4351 /* It's big, it's heavy, it's wood! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352 while ((claimed_size /= 2) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4353 ++log;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 claimed_size = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355 /* It's better than bad, it's good! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 while (log > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4357 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358 claimed_size *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4359 log--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4360 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4361 /* We have to come up with some average about the amount of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4362 blocks used. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4363 if ((rand () & 4095) < claimed_size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4364 claimed_size += 3 * sizeof (void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368 claimed_size += 4095;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369 claimed_size &= ~4095;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 #elif defined (SYSTEM_MALLOC)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 if (claimed_size < 16)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4376 claimed_size = 16;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4377 claimed_size += 2 * sizeof (void *);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4379 #else /* old GNU allocator */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4381 # ifdef rcheck /* #### may not be defined here */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4382 claimed_size += 20;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4383 # else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4384 claimed_size += 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4385 # endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4386 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4387 int log = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4389 /* compute the log base two, more or less, then use it to compute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4390 the block size needed. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4391 claimed_size--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4392 /* It's big, it's heavy, it's wood! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4393 while ((claimed_size /= 2) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4394 ++log;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4395 claimed_size = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4396 /* It's better than bad, it's good! */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4397 while (log > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4398 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4399 claimed_size *= 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4400 log--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4401 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4402 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4404 #endif /* old GNU allocator */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4405
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4406 if (stats)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4407 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4408 stats->was_requested += orig_claimed_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4409 stats->malloc_overhead += claimed_size - orig_claimed_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4411 return claimed_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4412 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4414 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4415 fixed_type_block_overhead (int size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4416 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4417 int per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4418 int overhead = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4419 int storage_size = malloced_storage_size (0, per_block, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4420 while (size >= per_block)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4422 size -= per_block;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4423 overhead += sizeof (void *) + per_block - storage_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4426 if (rand () % per_block < size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4427 overhead += sizeof (void *) + per_block - storage_size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4428 return overhead;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4429 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4431 #endif /* MEMORY_USAGE_STATS */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4434 /* Initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4435 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4436 init_alloc_once_early (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4437 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4438 int iii;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4440 #ifdef PURESTAT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4441 for (iii = 0; iii < countof (purestats); iii++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4442 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4443 if (! purestats[iii]) continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4444 purestats[iii]->nobjects = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 purestats[iii]->nbytes = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4447 purecopying_for_bytecode = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450 last_lrecord_type_index_assigned = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451 for (iii = 0; iii < countof (lrecord_implementations_table); iii++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4452 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 lrecord_implementations_table[iii] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4454 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4455
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4456 symbols_initialized = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4457
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4458 gc_generation_number[0] = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4459 /* purify_flag 1 is correct even if CANNOT_DUMP.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4460 * loadup.el will set to nil at end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 purify_flag = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4462 pureptr = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 pure_lossage = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4464 breathing_space = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4465 XSETINT (all_vectors, 0); /* Qzero may not be set yet. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4466 XSETINT (all_bit_vectors, 0); /* Qzero may not be set yet. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4467 XSETINT (Vgc_message, 0);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4468 all_lcrecords = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4469 ignore_malloc_warnings = 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4470 init_string_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 init_string_chars_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 init_cons_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 init_symbol_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474 init_compiled_function_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 #ifdef LISP_FLOAT_TYPE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 init_float_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477 #endif /* LISP_FLOAT_TYPE */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478 #ifndef standalone
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479 init_marker_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4480 init_extent_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481 init_event_alloc ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483 ignore_malloc_warnings = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484 staticidx = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 consing_since_gc = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486 #if 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 gc_cons_threshold = 500000; /* XEmacs change */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4489 gc_cons_threshold = 15000; /* debugging */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 #ifdef VIRT_ADDR_VARIES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492 malloc_sbrk_unused = 1<<22; /* A large number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 malloc_sbrk_used = 100000; /* as reasonable as any number */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 #endif /* VIRT_ADDR_VARIES */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495 lrecord_uid_counter = 259;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496 debug_string_purity = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 gcprolist = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 gc_currently_forbidden = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500 gc_hooks_inhibited = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4502 #ifdef ERROR_CHECK_TYPECHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 666;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 ERROR_ME_NOT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507 ERROR_ME_WARN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4508 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509 3333632;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4513 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 reinit_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 gcprolist = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4518
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4519 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520 syms_of_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 defsymbol (&Qpre_gc_hook, "pre-gc-hook");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523 defsymbol (&Qpost_gc_hook, "post-gc-hook");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524 defsymbol (&Qgarbage_collecting, "garbage-collecting");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4526 DEFSUBR (Fcons);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4527 DEFSUBR (Flist);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4528 DEFSUBR (Fvector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4529 DEFSUBR (Fbit_vector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4530 DEFSUBR (Fmake_byte_code);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4531 DEFSUBR (Fmake_list);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4532 DEFSUBR (Fmake_vector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4533 DEFSUBR (Fmake_bit_vector);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4534 DEFSUBR (Fmake_string);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4535 DEFSUBR (Fmake_symbol);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4536 DEFSUBR (Fmake_marker);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4537 DEFSUBR (Fpurecopy);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4538 DEFSUBR (Fgarbage_collect);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4539 DEFSUBR (Fmemory_limit);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 16
diff changeset
4540 DEFSUBR (Fconsing_since_gc);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 vars_of_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4547 *Number of bytes of consing between garbage collections.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548 \"Consing\" is a misnomer in that this actually counts allocation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549 of all different kinds of objects, not just conses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550 Garbage collection can happen automatically once this many bytes have been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551 allocated since the last garbage collection. All data types count.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 Garbage collection happens automatically when `eval' or `funcall' are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554 called. (Note that `funcall' is called implicitly as part of evaluation.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 By binding this temporarily to a large number, you can effectively
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4556 prevent garbage collection during a part of the program.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 See also `consing-since-gc'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 DEFVAR_INT ("pure-bytes-used", &pureptr /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4562 Number of bytes of sharable Lisp data allocated so far.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565 #if 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567 Number of bytes of unshared memory allocated in this session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 Number of bytes of unshared memory remaining available in this session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 #ifdef DEBUG_XEMACS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4576 DEFVAR_INT ("debug-allocation", &debug_allocation /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4577 If non-zero, print out information to stderr about all objects allocated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4578 See also `debug-allocation-backtrace-length'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580 debug_allocation = 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 DEFVAR_INT ("debug-allocation-backtrace-length",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583 &debug_allocation_backtrace_length /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 Length (in stack frames) of short backtrace printed out by `debug-allocation'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4585 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586 debug_allocation_backtrace_length = 2;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 DEFVAR_BOOL ("purify-flag", &purify_flag /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 Non-nil means loading Lisp code in order to dump an executable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591 This means that certain objects should be allocated in shared (pure) space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4592 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4594 DEFVAR_LISP ("pre-gc-hook", &Vpre_gc_hook /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4595 Function or functions to be run just before each garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 Interrupts, garbage collection, and errors are inhibited while this hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 runs, so be extremely careful in what you add here. In particular, avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 consing, and do not interact with the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600 Vpre_gc_hook = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603 Function or functions to be run just after each garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4604 Interrupts, garbage collection, and errors are inhibited while this hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 runs, so be extremely careful in what you add here. In particular, avoid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4606 consing, and do not interact with the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4608 Vpost_gc_hook = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 DEFVAR_LISP ("gc-message", &Vgc_message /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611 String to print to indicate that a garbage collection is in progress.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612 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
4613 window system and `gc-pointer-glyph' specifies a value (i.e. a pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 image instance) in the domain of the selected frame, the mouse pointer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615 will change instead of this message being printed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 Vgc_message = make_pure_string ((CONST Bufbyte *) gc_default_message,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618 countof (gc_default_message) - 1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 Qnil, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621 DEFVAR_LISP ("gc-pointer-glyph", &Vgc_pointer_glyph /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 Pointer glyph used to indicate that a garbage collection is in progress.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623 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
4624 value (i.e. a pointer image instance) in the domain of the selected
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 window, the pointer will be changed as specified during garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 Otherwise, a message will be printed in the echo area, as controlled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 by `gc-message'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628 */ );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4629 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4631 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632 complex_vars_of_alloc (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 Vgc_pointer_glyph = Fmake_glyph_internal (Qpointer);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635 }