Mercurial > emacs
annotate src/alloc.c @ 1537:8531c6d96e5c
(make-directory): Renamed from make-directory-path.
Optional argument says whether to create parent dirs.
Invoke file-name handler here.
(after-find-file): Delete code that offers to create dir.
Instead, just print a message.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 03 Nov 1992 07:07:02 +0000 |
parents | 6489d5182a64 |
children | 00ba13693a97 |
rev | line source |
---|---|
300 | 1 /* Storage allocation and gc for GNU Emacs Lisp interpreter. |
590 | 2 Copyright (C) 1985, 1986, 1988, 1992 Free Software Foundation, Inc. |
300 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include "config.h" | |
22 #include "lisp.h" | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
23 #include "intervals.h" |
356 | 24 #include "puresize.h" |
300 | 25 #ifndef standalone |
26 #include "buffer.h" | |
27 #include "window.h" | |
764 | 28 #ifdef MULTI_FRAME |
29 #include "frame.h" | |
30 #endif /* MULTI_FRAME */ | |
300 | 31 #endif |
32 | |
638 | 33 #include "syssignal.h" |
34 | |
300 | 35 #define max(A,B) ((A) > (B) ? (A) : (B)) |
36 | |
37 /* Macro to verify that storage intended for Lisp objects is not | |
38 out of range to fit in the space for a pointer. | |
39 ADDRESS is the start of the block, and SIZE | |
40 is the amount of space within which objects can start. */ | |
41 #define VALIDATE_LISP_STORAGE(address, size) \ | |
42 do \ | |
43 { \ | |
44 Lisp_Object val; \ | |
45 XSET (val, Lisp_Cons, (char *) address + size); \ | |
46 if ((char *) XCONS (val) != (char *) address + size) \ | |
47 { \ | |
48 free (address); \ | |
49 memory_full (); \ | |
50 } \ | |
51 } while (0) | |
52 | |
53 /* Number of bytes of consing done since the last gc */ | |
54 int consing_since_gc; | |
55 | |
56 /* Number of bytes of consing since gc before another gc should be done. */ | |
57 int gc_cons_threshold; | |
58 | |
59 /* Nonzero during gc */ | |
60 int gc_in_progress; | |
61 | |
62 #ifndef VIRT_ADDR_VARIES | |
63 extern | |
64 #endif /* VIRT_ADDR_VARIES */ | |
65 int malloc_sbrk_used; | |
66 | |
67 #ifndef VIRT_ADDR_VARIES | |
68 extern | |
69 #endif /* VIRT_ADDR_VARIES */ | |
70 int malloc_sbrk_unused; | |
71 | |
764 | 72 /* Two limits controlling how much undo information to keep. */ |
73 int undo_limit; | |
74 int undo_strong_limit; | |
300 | 75 |
76 /* Non-nil means defun should do purecopy on the function definition */ | |
77 Lisp_Object Vpurify_flag; | |
78 | |
79 #ifndef HAVE_SHM | |
80 int pure[PURESIZE / sizeof (int)] = {0,}; /* Force it into data space! */ | |
81 #define PUREBEG (char *) pure | |
82 #else | |
83 #define pure PURE_SEG_BITS /* Use shared memory segment */ | |
84 #define PUREBEG (char *)PURE_SEG_BITS | |
356 | 85 |
86 /* This variable is used only by the XPNTR macro when HAVE_SHM is | |
87 defined. If we used the PURESIZE macro directly there, that would | |
88 make most of emacs dependent on puresize.h, which we don't want - | |
89 you should be able to change that without too much recompilation. | |
90 So map_in_data initializes pure_size, and the dependencies work | |
91 out. */ | |
92 int pure_size; | |
300 | 93 #endif /* not HAVE_SHM */ |
94 | |
95 /* Index in pure at which next pure object will be allocated. */ | |
96 int pureptr; | |
97 | |
98 /* If nonzero, this is a warning delivered by malloc and not yet displayed. */ | |
99 char *pending_malloc_warning; | |
100 | |
101 /* Maximum amount of C stack to save when a GC happens. */ | |
102 | |
103 #ifndef MAX_SAVE_STACK | |
104 #define MAX_SAVE_STACK 16000 | |
105 #endif | |
106 | |
107 /* Buffer in which we save a copy of the C stack at each GC. */ | |
108 | |
109 char *stack_copy; | |
110 int stack_copy_size; | |
111 | |
112 /* Non-zero means ignore malloc warnings. Set during initialization. */ | |
113 int ignore_warnings; | |
1318 | 114 |
115 static void mark_object (), mark_buffer (); | |
116 static void clear_marks (), gc_sweep (); | |
117 static void compact_strings (); | |
300 | 118 |
119 Lisp_Object | |
120 malloc_warning_1 (str) | |
121 Lisp_Object str; | |
122 { | |
123 Fprinc (str, Vstandard_output); | |
124 write_string ("\nKilling some buffers may delay running out of memory.\n", -1); | |
125 write_string ("However, certainly by the time you receive the 95% warning,\n", -1); | |
126 write_string ("you should clean up, kill this Emacs, and start a new one.", -1); | |
127 return Qnil; | |
128 } | |
129 | |
130 /* malloc calls this if it finds we are near exhausting storage */ | |
131 malloc_warning (str) | |
132 char *str; | |
133 { | |
134 pending_malloc_warning = str; | |
135 } | |
136 | |
137 display_malloc_warning () | |
138 { | |
139 register Lisp_Object val; | |
140 | |
141 val = build_string (pending_malloc_warning); | |
142 pending_malloc_warning = 0; | |
143 internal_with_output_to_temp_buffer (" *Danger*", malloc_warning_1, val); | |
144 } | |
145 | |
146 /* Called if malloc returns zero */ | |
147 memory_full () | |
148 { | |
149 error ("Memory exhausted"); | |
150 } | |
151 | |
152 /* like malloc and realloc but check for no memory left */ | |
153 | |
154 long * | |
155 xmalloc (size) | |
156 int size; | |
157 { | |
158 register long *val; | |
159 | |
160 val = (long *) malloc (size); | |
161 | |
162 if (!val && size) memory_full (); | |
163 return val; | |
164 } | |
165 | |
166 long * | |
167 xrealloc (block, size) | |
168 long *block; | |
169 int size; | |
170 { | |
171 register long *val; | |
172 | |
590 | 173 /* We must call malloc explicitly when BLOCK is 0, since some |
174 reallocs don't do this. */ | |
175 if (! block) | |
176 val = (long *) malloc (size); | |
600
a8d78999e46d
*** empty log message ***
Noah Friedman <friedman@splode.com>
parents:
590
diff
changeset
|
177 else |
590 | 178 val = (long *) realloc (block, size); |
300 | 179 |
180 if (!val && size) memory_full (); | |
181 return val; | |
182 } | |
183 | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
184 #ifdef USE_TEXT_PROPERTIES |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
185 #define INTERVAL_BLOCK_SIZE \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
186 ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval)) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
187 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
188 struct interval_block |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
189 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
190 struct interval_block *next; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
191 struct interval intervals[INTERVAL_BLOCK_SIZE]; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
192 }; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
193 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
194 struct interval_block *interval_block; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
195 static int interval_block_index; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
196 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
197 INTERVAL interval_free_list; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
198 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
199 static void |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
200 init_intervals () |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
201 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
202 interval_block |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
203 = (struct interval_block *) malloc (sizeof (struct interval_block)); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
204 interval_block->next = 0; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
205 bzero (interval_block->intervals, sizeof interval_block->intervals); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
206 interval_block_index = 0; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
207 interval_free_list = 0; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
208 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
209 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
210 #define INIT_INTERVALS init_intervals () |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
211 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
212 INTERVAL |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
213 make_interval () |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
214 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
215 INTERVAL val; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
216 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
217 if (interval_free_list) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
218 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
219 val = interval_free_list; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
220 interval_free_list = interval_free_list->parent; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
221 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
222 else |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
223 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
224 if (interval_block_index == INTERVAL_BLOCK_SIZE) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
225 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
226 register struct interval_block *newi |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
227 = (struct interval_block *) malloc (sizeof (struct interval_block)); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
228 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
229 if (!newi) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
230 memory_full (); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
231 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
232 VALIDATE_LISP_STORAGE (newi, sizeof *newi); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
233 newi->next = interval_block; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
234 interval_block = newi; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
235 interval_block_index = 0; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
236 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
237 val = &interval_block->intervals[interval_block_index++]; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
238 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
239 consing_since_gc += sizeof (struct interval); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
240 RESET_INTERVAL (val); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
241 return val; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
242 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
243 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
244 static int total_free_intervals, total_intervals; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
245 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
246 /* Mark the pointers of one interval. */ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
247 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
248 static void |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
249 mark_interval (i) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
250 register INTERVAL i; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
251 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
252 if (XMARKBIT (i->plist)) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
253 abort (); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
254 mark_object (&i->plist); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
255 XMARK (i->plist); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
256 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
257 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
258 static void |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
259 mark_interval_tree (tree) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
260 register INTERVAL tree; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
261 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
262 if (XMARKBIT (tree->plist)) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
263 return; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
264 |
1411
0b98dbec0738
* alloc.c (mark_interval_tree): Pass 0 as initial depth argument
Joseph Arceneaux <jla@gnu.org>
parents:
1362
diff
changeset
|
265 traverse_intervals (tree, 1, 0, &mark_interval); |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
266 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
267 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
268 #define MARK_INTERVAL_TREE(i) \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
269 { if (!NULL_INTERVAL_P (i)) mark_interval_tree (i); } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
270 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
271 #define UNMARK_BALANCE_INTERVALS(i) \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
272 { \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
273 if (! NULL_INTERVAL_P (i)) \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
274 { \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
275 XUNMARK ((Lisp_Object) (i->parent)); \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
276 i = balance_intervals (i); \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
277 } \ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
278 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
279 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
280 #else /* no interval use */ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
281 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
282 #define INIT_INTERVALS |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
283 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
284 #define UNMARK_BALANCE_INTERVALS(i) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
285 #define MARK_INTERVAL_TREE(i) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
286 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
287 #endif /* no interval use */ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
288 |
300 | 289 #ifdef LISP_FLOAT_TYPE |
290 /* Allocation of float cells, just like conses */ | |
291 /* We store float cells inside of float_blocks, allocating a new | |
292 float_block with malloc whenever necessary. Float cells reclaimed by | |
293 GC are put on a free list to be reallocated before allocating | |
294 any new float cells from the latest float_block. | |
295 | |
296 Each float_block is just under 1020 bytes long, | |
297 since malloc really allocates in units of powers of two | |
298 and uses 4 bytes for its own overhead. */ | |
299 | |
300 #define FLOAT_BLOCK_SIZE \ | |
301 ((1020 - sizeof (struct float_block *)) / sizeof (struct Lisp_Float)) | |
302 | |
303 struct float_block | |
304 { | |
305 struct float_block *next; | |
306 struct Lisp_Float floats[FLOAT_BLOCK_SIZE]; | |
307 }; | |
308 | |
309 struct float_block *float_block; | |
310 int float_block_index; | |
311 | |
312 struct Lisp_Float *float_free_list; | |
313 | |
314 void | |
315 init_float () | |
316 { | |
317 float_block = (struct float_block *) malloc (sizeof (struct float_block)); | |
318 float_block->next = 0; | |
319 bzero (float_block->floats, sizeof float_block->floats); | |
320 float_block_index = 0; | |
321 float_free_list = 0; | |
322 } | |
323 | |
324 /* Explicitly free a float cell. */ | |
325 free_float (ptr) | |
326 struct Lisp_Float *ptr; | |
327 { | |
328 XFASTINT (ptr->type) = (int) float_free_list; | |
329 float_free_list = ptr; | |
330 } | |
331 | |
332 Lisp_Object | |
333 make_float (float_value) | |
334 double float_value; | |
335 { | |
336 register Lisp_Object val; | |
337 | |
338 if (float_free_list) | |
339 { | |
340 XSET (val, Lisp_Float, float_free_list); | |
341 float_free_list = (struct Lisp_Float *) XFASTINT (float_free_list->type); | |
342 } | |
343 else | |
344 { | |
345 if (float_block_index == FLOAT_BLOCK_SIZE) | |
346 { | |
347 register struct float_block *new = (struct float_block *) malloc (sizeof (struct float_block)); | |
348 if (!new) memory_full (); | |
349 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
350 new->next = float_block; | |
351 float_block = new; | |
352 float_block_index = 0; | |
353 } | |
354 XSET (val, Lisp_Float, &float_block->floats[float_block_index++]); | |
355 } | |
356 XFLOAT (val)->data = float_value; | |
357 XFLOAT (val)->type = 0; /* bug chasing -wsr */ | |
358 consing_since_gc += sizeof (struct Lisp_Float); | |
359 return val; | |
360 } | |
361 | |
362 #endif /* LISP_FLOAT_TYPE */ | |
363 | |
364 /* Allocation of cons cells */ | |
365 /* We store cons cells inside of cons_blocks, allocating a new | |
366 cons_block with malloc whenever necessary. Cons cells reclaimed by | |
367 GC are put on a free list to be reallocated before allocating | |
368 any new cons cells from the latest cons_block. | |
369 | |
370 Each cons_block is just under 1020 bytes long, | |
371 since malloc really allocates in units of powers of two | |
372 and uses 4 bytes for its own overhead. */ | |
373 | |
374 #define CONS_BLOCK_SIZE \ | |
375 ((1020 - sizeof (struct cons_block *)) / sizeof (struct Lisp_Cons)) | |
376 | |
377 struct cons_block | |
378 { | |
379 struct cons_block *next; | |
380 struct Lisp_Cons conses[CONS_BLOCK_SIZE]; | |
381 }; | |
382 | |
383 struct cons_block *cons_block; | |
384 int cons_block_index; | |
385 | |
386 struct Lisp_Cons *cons_free_list; | |
387 | |
388 void | |
389 init_cons () | |
390 { | |
391 cons_block = (struct cons_block *) malloc (sizeof (struct cons_block)); | |
392 cons_block->next = 0; | |
393 bzero (cons_block->conses, sizeof cons_block->conses); | |
394 cons_block_index = 0; | |
395 cons_free_list = 0; | |
396 } | |
397 | |
398 /* Explicitly free a cons cell. */ | |
399 free_cons (ptr) | |
400 struct Lisp_Cons *ptr; | |
401 { | |
402 XFASTINT (ptr->car) = (int) cons_free_list; | |
403 cons_free_list = ptr; | |
404 } | |
405 | |
406 DEFUN ("cons", Fcons, Scons, 2, 2, 0, | |
407 "Create a new cons, give it CAR and CDR as components, and return it.") | |
408 (car, cdr) | |
409 Lisp_Object car, cdr; | |
410 { | |
411 register Lisp_Object val; | |
412 | |
413 if (cons_free_list) | |
414 { | |
415 XSET (val, Lisp_Cons, cons_free_list); | |
416 cons_free_list = (struct Lisp_Cons *) XFASTINT (cons_free_list->car); | |
417 } | |
418 else | |
419 { | |
420 if (cons_block_index == CONS_BLOCK_SIZE) | |
421 { | |
422 register struct cons_block *new = (struct cons_block *) malloc (sizeof (struct cons_block)); | |
423 if (!new) memory_full (); | |
424 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
425 new->next = cons_block; | |
426 cons_block = new; | |
427 cons_block_index = 0; | |
428 } | |
429 XSET (val, Lisp_Cons, &cons_block->conses[cons_block_index++]); | |
430 } | |
431 XCONS (val)->car = car; | |
432 XCONS (val)->cdr = cdr; | |
433 consing_since_gc += sizeof (struct Lisp_Cons); | |
434 return val; | |
435 } | |
436 | |
437 DEFUN ("list", Flist, Slist, 0, MANY, 0, | |
438 "Return a newly created list with specified arguments as elements.\n\ | |
439 Any number of arguments, even zero arguments, are allowed.") | |
440 (nargs, args) | |
441 int nargs; | |
442 register Lisp_Object *args; | |
443 { | |
444 register Lisp_Object len, val, val_tail; | |
445 | |
446 XFASTINT (len) = nargs; | |
447 val = Fmake_list (len, Qnil); | |
448 val_tail = val; | |
485 | 449 while (!NILP (val_tail)) |
300 | 450 { |
451 XCONS (val_tail)->car = *args++; | |
452 val_tail = XCONS (val_tail)->cdr; | |
453 } | |
454 return val; | |
455 } | |
456 | |
457 DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0, | |
458 "Return a newly created list of length LENGTH, with each element being INIT.") | |
459 (length, init) | |
460 register Lisp_Object length, init; | |
461 { | |
462 register Lisp_Object val; | |
463 register int size; | |
464 | |
465 if (XTYPE (length) != Lisp_Int || XINT (length) < 0) | |
466 length = wrong_type_argument (Qnatnump, length); | |
467 size = XINT (length); | |
468 | |
469 val = Qnil; | |
470 while (size-- > 0) | |
471 val = Fcons (init, val); | |
472 return val; | |
473 } | |
474 | |
475 /* Allocation of vectors */ | |
476 | |
477 struct Lisp_Vector *all_vectors; | |
478 | |
479 DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0, | |
480 "Return a newly created vector of length LENGTH, with each element being INIT.\n\ | |
481 See also the function `vector'.") | |
482 (length, init) | |
483 register Lisp_Object length, init; | |
484 { | |
485 register int sizei, index; | |
486 register Lisp_Object vector; | |
487 register struct Lisp_Vector *p; | |
488 | |
489 if (XTYPE (length) != Lisp_Int || XINT (length) < 0) | |
490 length = wrong_type_argument (Qnatnump, length); | |
491 sizei = XINT (length); | |
492 | |
493 p = (struct Lisp_Vector *) malloc (sizeof (struct Lisp_Vector) + (sizei - 1) * sizeof (Lisp_Object)); | |
494 if (p == 0) | |
495 memory_full (); | |
496 VALIDATE_LISP_STORAGE (p, 0); | |
497 | |
498 XSET (vector, Lisp_Vector, p); | |
499 consing_since_gc += sizeof (struct Lisp_Vector) + (sizei - 1) * sizeof (Lisp_Object); | |
500 | |
501 p->size = sizei; | |
502 p->next = all_vectors; | |
503 all_vectors = p; | |
504 | |
505 for (index = 0; index < sizei; index++) | |
506 p->contents[index] = init; | |
507 | |
508 return vector; | |
509 } | |
510 | |
511 DEFUN ("vector", Fvector, Svector, 0, MANY, 0, | |
512 "Return a newly created vector with specified arguments as elements.\n\ | |
513 Any number of arguments, even zero arguments, are allowed.") | |
514 (nargs, args) | |
515 register int nargs; | |
516 Lisp_Object *args; | |
517 { | |
518 register Lisp_Object len, val; | |
519 register int index; | |
520 register struct Lisp_Vector *p; | |
521 | |
522 XFASTINT (len) = nargs; | |
523 val = Fmake_vector (len, Qnil); | |
524 p = XVECTOR (val); | |
525 for (index = 0; index < nargs; index++) | |
526 p->contents[index] = args[index]; | |
527 return val; | |
528 } | |
529 | |
530 DEFUN ("make-byte-code", Fmake_byte_code, Smake_byte_code, 4, MANY, 0, | |
531 "Create a byte-code object with specified arguments as elements.\n\ | |
532 The arguments should be the arglist, bytecode-string, constant vector,\n\ | |
533 stack size, (optional) doc string, and (optional) interactive spec.\n\ | |
534 The first four arguments are required; at most six have any\n\ | |
535 significance.") | |
536 (nargs, args) | |
537 register int nargs; | |
538 Lisp_Object *args; | |
539 { | |
540 register Lisp_Object len, val; | |
541 register int index; | |
542 register struct Lisp_Vector *p; | |
543 | |
544 XFASTINT (len) = nargs; | |
485 | 545 if (!NILP (Vpurify_flag)) |
300 | 546 val = make_pure_vector (len); |
547 else | |
548 val = Fmake_vector (len, Qnil); | |
549 p = XVECTOR (val); | |
550 for (index = 0; index < nargs; index++) | |
551 { | |
485 | 552 if (!NILP (Vpurify_flag)) |
300 | 553 args[index] = Fpurecopy (args[index]); |
554 p->contents[index] = args[index]; | |
555 } | |
556 XSETTYPE (val, Lisp_Compiled); | |
557 return val; | |
558 } | |
559 | |
560 /* Allocation of symbols. | |
561 Just like allocation of conses! | |
562 | |
563 Each symbol_block is just under 1020 bytes long, | |
564 since malloc really allocates in units of powers of two | |
565 and uses 4 bytes for its own overhead. */ | |
566 | |
567 #define SYMBOL_BLOCK_SIZE \ | |
568 ((1020 - sizeof (struct symbol_block *)) / sizeof (struct Lisp_Symbol)) | |
569 | |
570 struct symbol_block | |
571 { | |
572 struct symbol_block *next; | |
573 struct Lisp_Symbol symbols[SYMBOL_BLOCK_SIZE]; | |
574 }; | |
575 | |
576 struct symbol_block *symbol_block; | |
577 int symbol_block_index; | |
578 | |
579 struct Lisp_Symbol *symbol_free_list; | |
580 | |
581 void | |
582 init_symbol () | |
583 { | |
584 symbol_block = (struct symbol_block *) malloc (sizeof (struct symbol_block)); | |
585 symbol_block->next = 0; | |
586 bzero (symbol_block->symbols, sizeof symbol_block->symbols); | |
587 symbol_block_index = 0; | |
588 symbol_free_list = 0; | |
589 } | |
590 | |
591 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0, | |
592 "Return a newly allocated uninterned symbol whose name is NAME.\n\ | |
593 Its value and function definition are void, and its property list is nil.") | |
594 (str) | |
595 Lisp_Object str; | |
596 { | |
597 register Lisp_Object val; | |
598 register struct Lisp_Symbol *p; | |
599 | |
600 CHECK_STRING (str, 0); | |
601 | |
602 if (symbol_free_list) | |
603 { | |
604 XSET (val, Lisp_Symbol, symbol_free_list); | |
605 symbol_free_list | |
606 = (struct Lisp_Symbol *) XFASTINT (symbol_free_list->value); | |
607 } | |
608 else | |
609 { | |
610 if (symbol_block_index == SYMBOL_BLOCK_SIZE) | |
611 { | |
612 struct symbol_block *new = (struct symbol_block *) malloc (sizeof (struct symbol_block)); | |
613 if (!new) memory_full (); | |
614 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
615 new->next = symbol_block; | |
616 symbol_block = new; | |
617 symbol_block_index = 0; | |
618 } | |
619 XSET (val, Lisp_Symbol, &symbol_block->symbols[symbol_block_index++]); | |
620 } | |
621 p = XSYMBOL (val); | |
622 p->name = XSTRING (str); | |
623 p->plist = Qnil; | |
624 p->value = Qunbound; | |
625 p->function = Qunbound; | |
626 p->next = 0; | |
627 consing_since_gc += sizeof (struct Lisp_Symbol); | |
628 return val; | |
629 } | |
630 | |
631 /* Allocation of markers. | |
632 Works like allocation of conses. */ | |
633 | |
634 #define MARKER_BLOCK_SIZE \ | |
635 ((1020 - sizeof (struct marker_block *)) / sizeof (struct Lisp_Marker)) | |
636 | |
637 struct marker_block | |
638 { | |
639 struct marker_block *next; | |
640 struct Lisp_Marker markers[MARKER_BLOCK_SIZE]; | |
641 }; | |
642 | |
643 struct marker_block *marker_block; | |
644 int marker_block_index; | |
645 | |
646 struct Lisp_Marker *marker_free_list; | |
647 | |
648 void | |
649 init_marker () | |
650 { | |
651 marker_block = (struct marker_block *) malloc (sizeof (struct marker_block)); | |
652 marker_block->next = 0; | |
653 bzero (marker_block->markers, sizeof marker_block->markers); | |
654 marker_block_index = 0; | |
655 marker_free_list = 0; | |
656 } | |
657 | |
658 DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0, | |
659 "Return a newly allocated marker which does not point at any place.") | |
660 () | |
661 { | |
662 register Lisp_Object val; | |
663 register struct Lisp_Marker *p; | |
638 | 664 |
300 | 665 if (marker_free_list) |
666 { | |
667 XSET (val, Lisp_Marker, marker_free_list); | |
668 marker_free_list | |
669 = (struct Lisp_Marker *) XFASTINT (marker_free_list->chain); | |
670 } | |
671 else | |
672 { | |
673 if (marker_block_index == MARKER_BLOCK_SIZE) | |
674 { | |
675 struct marker_block *new = (struct marker_block *) malloc (sizeof (struct marker_block)); | |
676 if (!new) memory_full (); | |
677 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
678 new->next = marker_block; | |
679 marker_block = new; | |
680 marker_block_index = 0; | |
681 } | |
682 XSET (val, Lisp_Marker, &marker_block->markers[marker_block_index++]); | |
683 } | |
684 p = XMARKER (val); | |
685 p->buffer = 0; | |
686 p->bufpos = 0; | |
687 p->chain = Qnil; | |
688 consing_since_gc += sizeof (struct Lisp_Marker); | |
689 return val; | |
690 } | |
691 | |
692 /* Allocation of strings */ | |
693 | |
694 /* Strings reside inside of string_blocks. The entire data of the string, | |
695 both the size and the contents, live in part of the `chars' component of a string_block. | |
696 The `pos' component is the index within `chars' of the first free byte. | |
697 | |
698 first_string_block points to the first string_block ever allocated. | |
699 Each block points to the next one with its `next' field. | |
700 The `prev' fields chain in reverse order. | |
701 The last one allocated is the one currently being filled. | |
702 current_string_block points to it. | |
703 | |
704 The string_blocks that hold individual large strings | |
705 go in a separate chain, started by large_string_blocks. */ | |
706 | |
707 | |
708 /* String blocks contain this many useful bytes. | |
709 8188 is power of 2, minus 4 for malloc overhead. */ | |
710 #define STRING_BLOCK_SIZE (8188 - sizeof (struct string_block_head)) | |
711 | |
712 /* A string bigger than this gets its own specially-made string block | |
713 if it doesn't fit in the current one. */ | |
714 #define STRING_BLOCK_OUTSIZE 1024 | |
715 | |
716 struct string_block_head | |
717 { | |
718 struct string_block *next, *prev; | |
719 int pos; | |
720 }; | |
721 | |
722 struct string_block | |
723 { | |
724 struct string_block *next, *prev; | |
725 int pos; | |
726 char chars[STRING_BLOCK_SIZE]; | |
727 }; | |
728 | |
729 /* This points to the string block we are now allocating strings. */ | |
730 | |
731 struct string_block *current_string_block; | |
732 | |
733 /* This points to the oldest string block, the one that starts the chain. */ | |
734 | |
735 struct string_block *first_string_block; | |
736 | |
737 /* Last string block in chain of those made for individual large strings. */ | |
738 | |
739 struct string_block *large_string_blocks; | |
740 | |
741 /* If SIZE is the length of a string, this returns how many bytes | |
742 the string occupies in a string_block (including padding). */ | |
743 | |
744 #define STRING_FULLSIZE(size) (((size) + sizeof (struct Lisp_String) + PAD) \ | |
745 & ~(PAD - 1)) | |
746 #define PAD (sizeof (int)) | |
747 | |
748 #if 0 | |
749 #define STRING_FULLSIZE(SIZE) \ | |
750 (((SIZE) + 2 * sizeof (int)) & ~(sizeof (int) - 1)) | |
751 #endif | |
752 | |
753 void | |
754 init_strings () | |
755 { | |
756 current_string_block = (struct string_block *) malloc (sizeof (struct string_block)); | |
757 first_string_block = current_string_block; | |
758 consing_since_gc += sizeof (struct string_block); | |
759 current_string_block->next = 0; | |
760 current_string_block->prev = 0; | |
761 current_string_block->pos = 0; | |
762 large_string_blocks = 0; | |
763 } | |
764 | |
765 DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0, | |
766 "Return a newly created string of length LENGTH, with each element being INIT.\n\ | |
767 Both LENGTH and INIT must be numbers.") | |
768 (length, init) | |
769 Lisp_Object length, init; | |
770 { | |
771 register Lisp_Object val; | |
772 register unsigned char *p, *end, c; | |
773 | |
774 if (XTYPE (length) != Lisp_Int || XINT (length) < 0) | |
775 length = wrong_type_argument (Qnatnump, length); | |
776 CHECK_NUMBER (init, 1); | |
777 val = make_uninit_string (XINT (length)); | |
778 c = XINT (init); | |
779 p = XSTRING (val)->data; | |
780 end = p + XSTRING (val)->size; | |
781 while (p != end) | |
782 *p++ = c; | |
783 *p = 0; | |
784 return val; | |
785 } | |
786 | |
787 Lisp_Object | |
788 make_string (contents, length) | |
789 char *contents; | |
790 int length; | |
791 { | |
792 register Lisp_Object val; | |
793 val = make_uninit_string (length); | |
794 bcopy (contents, XSTRING (val)->data, length); | |
795 return val; | |
796 } | |
797 | |
798 Lisp_Object | |
799 build_string (str) | |
800 char *str; | |
801 { | |
802 return make_string (str, strlen (str)); | |
803 } | |
804 | |
805 Lisp_Object | |
806 make_uninit_string (length) | |
807 int length; | |
808 { | |
809 register Lisp_Object val; | |
810 register int fullsize = STRING_FULLSIZE (length); | |
811 | |
812 if (length < 0) abort (); | |
813 | |
814 if (fullsize <= STRING_BLOCK_SIZE - current_string_block->pos) | |
815 /* This string can fit in the current string block */ | |
816 { | |
817 XSET (val, Lisp_String, | |
818 (struct Lisp_String *) (current_string_block->chars + current_string_block->pos)); | |
819 current_string_block->pos += fullsize; | |
820 } | |
821 else if (fullsize > STRING_BLOCK_OUTSIZE) | |
822 /* This string gets its own string block */ | |
823 { | |
824 register struct string_block *new | |
825 = (struct string_block *) malloc (sizeof (struct string_block_head) + fullsize); | |
826 VALIDATE_LISP_STORAGE (new, 0); | |
827 if (!new) memory_full (); | |
828 consing_since_gc += sizeof (struct string_block_head) + fullsize; | |
829 new->pos = fullsize; | |
830 new->next = large_string_blocks; | |
831 large_string_blocks = new; | |
832 XSET (val, Lisp_String, | |
833 (struct Lisp_String *) ((struct string_block_head *)new + 1)); | |
834 } | |
835 else | |
836 /* Make a new current string block and start it off with this string */ | |
837 { | |
838 register struct string_block *new | |
839 = (struct string_block *) malloc (sizeof (struct string_block)); | |
840 if (!new) memory_full (); | |
841 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
842 consing_since_gc += sizeof (struct string_block); | |
843 current_string_block->next = new; | |
844 new->prev = current_string_block; | |
845 new->next = 0; | |
846 current_string_block = new; | |
847 new->pos = fullsize; | |
848 XSET (val, Lisp_String, | |
849 (struct Lisp_String *) current_string_block->chars); | |
850 } | |
851 | |
852 XSTRING (val)->size = length; | |
853 XSTRING (val)->data[length] = 0; | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
854 INITIALIZE_INTERVAL (XSTRING (val), NULL_INTERVAL); |
300 | 855 |
856 return val; | |
857 } | |
858 | |
859 /* Return a newly created vector or string with specified arguments as | |
860 elements. If all the arguments are characters, make a string; | |
861 otherwise, make a vector. Any number of arguments, even zero | |
862 arguments, are allowed. */ | |
863 | |
864 Lisp_Object | |
434 | 865 make_array (nargs, args) |
300 | 866 register int nargs; |
867 Lisp_Object *args; | |
868 { | |
869 int i; | |
870 | |
871 for (i = 0; i < nargs; i++) | |
872 if (XTYPE (args[i]) != Lisp_Int | |
873 || (unsigned) XINT (args[i]) >= 0400) | |
874 return Fvector (nargs, args); | |
875 | |
876 /* Since the loop exited, we know that all the things in it are | |
877 characters, so we can make a string. */ | |
878 { | |
879 Lisp_Object result = Fmake_string (nargs, make_number (0)); | |
880 | |
881 for (i = 0; i < nargs; i++) | |
882 XSTRING (result)->data[i] = XINT (args[i]); | |
883 | |
884 return result; | |
885 } | |
886 } | |
887 | |
888 /* Note: the user cannot manipulate ropes portably by referring | |
889 to the chars of the string, because combining two chars to make a GLYPH | |
890 depends on endianness. */ | |
891 | |
892 DEFUN ("make-rope", Fmake_rope, Smake_rope, 0, MANY, 0, | |
363 | 893 "Return a newly created rope containing the arguments of this function.\n\ |
300 | 894 A rope is a string, except that its contents will be treated as an\n\ |
895 array of glyphs, where a glyph is an integer type that may be larger\n\ | |
896 than a character. Emacs is normally configured to use 8-bit glyphs,\n\ | |
897 so ropes are normally no different from strings. But Emacs may be\n\ | |
898 configured to use 16-bit glyphs, to allow the use of larger fonts.\n\ | |
899 \n\ | |
900 Each argument (which must be an integer) specifies one glyph, whatever\n\ | |
901 size glyphs may be.\n\ | |
902 \n\ | |
903 See variable `buffer-display-table' for the uses of ropes.") | |
904 (nargs, args) | |
905 register int nargs; | |
906 Lisp_Object *args; | |
907 { | |
908 register int i; | |
909 register Lisp_Object val; | |
910 register GLYPH *p; | |
911 | |
912 val = make_uninit_string (nargs * sizeof (GLYPH)); | |
913 | |
914 p = (GLYPH *) XSTRING (val)->data; | |
915 for (i = 0; i < nargs; i++) | |
916 { | |
917 CHECK_NUMBER (args[i], i); | |
918 p[i] = XFASTINT (args[i]); | |
919 } | |
920 return val; | |
921 } | |
922 | |
923 DEFUN ("rope-elt", Frope_elt, Srope_elt, 2, 2, 0, | |
924 "Return an element of rope R at index N.\n\ | |
925 A rope is a string in which each pair of bytes is considered an element.\n\ | |
926 See variable `buffer-display-table' for the uses of ropes.") | |
927 (r, n) | |
1500
6489d5182a64
* alloc.c (Frope_elt): Declare arguments to be Lisp_Objects.
Jim Blandy <jimb@redhat.com>
parents:
1411
diff
changeset
|
928 Lisp_Object r, n; |
300 | 929 { |
930 CHECK_STRING (r, 0); | |
931 CHECK_NUMBER (n, 1); | |
932 if ((XSTRING (r)->size / sizeof (GLYPH)) <= XINT (n) || XINT (n) < 0) | |
933 args_out_of_range (r, n); | |
934 return ((GLYPH *) XSTRING (r)->data)[XFASTINT (n)]; | |
935 } | |
936 | |
937 /* Must get an error if pure storage is full, | |
938 since if it cannot hold a large string | |
939 it may be able to hold conses that point to that string; | |
940 then the string is not protected from gc. */ | |
941 | |
942 Lisp_Object | |
943 make_pure_string (data, length) | |
944 char *data; | |
945 int length; | |
946 { | |
947 register Lisp_Object new; | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
948 register int size = sizeof (int) + INTERVAL_PTR_SIZE + length + 1; |
300 | 949 |
950 if (pureptr + size > PURESIZE) | |
951 error ("Pure Lisp storage exhausted"); | |
952 XSET (new, Lisp_String, PUREBEG + pureptr); | |
953 XSTRING (new)->size = length; | |
954 bcopy (data, XSTRING (new)->data, length); | |
955 XSTRING (new)->data[length] = 0; | |
956 pureptr += (size + sizeof (int) - 1) | |
957 / sizeof (int) * sizeof (int); | |
958 return new; | |
959 } | |
960 | |
961 Lisp_Object | |
962 pure_cons (car, cdr) | |
963 Lisp_Object car, cdr; | |
964 { | |
965 register Lisp_Object new; | |
966 | |
967 if (pureptr + sizeof (struct Lisp_Cons) > PURESIZE) | |
968 error ("Pure Lisp storage exhausted"); | |
969 XSET (new, Lisp_Cons, PUREBEG + pureptr); | |
970 pureptr += sizeof (struct Lisp_Cons); | |
971 XCONS (new)->car = Fpurecopy (car); | |
972 XCONS (new)->cdr = Fpurecopy (cdr); | |
973 return new; | |
974 } | |
975 | |
976 #ifdef LISP_FLOAT_TYPE | |
977 | |
978 Lisp_Object | |
979 make_pure_float (num) | |
980 double num; | |
981 { | |
982 register Lisp_Object new; | |
983 | |
984 if (pureptr + sizeof (struct Lisp_Float) > PURESIZE) | |
985 error ("Pure Lisp storage exhausted"); | |
986 XSET (new, Lisp_Float, PUREBEG + pureptr); | |
987 pureptr += sizeof (struct Lisp_Float); | |
988 XFLOAT (new)->data = num; | |
989 XFLOAT (new)->type = 0; /* bug chasing -wsr */ | |
990 return new; | |
991 } | |
992 | |
993 #endif /* LISP_FLOAT_TYPE */ | |
994 | |
995 Lisp_Object | |
996 make_pure_vector (len) | |
997 int len; | |
998 { | |
999 register Lisp_Object new; | |
1000 register int size = sizeof (struct Lisp_Vector) + (len - 1) * sizeof (Lisp_Object); | |
1001 | |
1002 if (pureptr + size > PURESIZE) | |
1003 error ("Pure Lisp storage exhausted"); | |
1004 | |
1005 XSET (new, Lisp_Vector, PUREBEG + pureptr); | |
1006 pureptr += size; | |
1007 XVECTOR (new)->size = len; | |
1008 return new; | |
1009 } | |
1010 | |
1011 DEFUN ("purecopy", Fpurecopy, Spurecopy, 1, 1, 0, | |
1012 "Make a copy of OBJECT in pure storage.\n\ | |
1013 Recursively copies contents of vectors and cons cells.\n\ | |
1014 Does not copy symbols.") | |
1015 (obj) | |
1016 register Lisp_Object obj; | |
1017 { | |
1018 register Lisp_Object new, tem; | |
1019 register int i; | |
1020 | |
485 | 1021 if (NILP (Vpurify_flag)) |
300 | 1022 return obj; |
1023 | |
1024 if ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) ((char *) pure + PURESIZE) | |
1025 && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure) | |
1026 return obj; | |
1027 | |
1028 #ifdef SWITCH_ENUM_BUG | |
1029 switch ((int) XTYPE (obj)) | |
1030 #else | |
1031 switch (XTYPE (obj)) | |
1032 #endif | |
1033 { | |
1034 case Lisp_Marker: | |
1035 error ("Attempt to copy a marker to pure storage"); | |
1036 | |
1037 case Lisp_Cons: | |
1038 return pure_cons (XCONS (obj)->car, XCONS (obj)->cdr); | |
1039 | |
1040 #ifdef LISP_FLOAT_TYPE | |
1041 case Lisp_Float: | |
1042 return make_pure_float (XFLOAT (obj)->data); | |
1043 #endif /* LISP_FLOAT_TYPE */ | |
1044 | |
1045 case Lisp_String: | |
1046 return make_pure_string (XSTRING (obj)->data, XSTRING (obj)->size); | |
1047 | |
1048 case Lisp_Compiled: | |
1049 case Lisp_Vector: | |
1050 new = make_pure_vector (XVECTOR (obj)->size); | |
1051 for (i = 0; i < XVECTOR (obj)->size; i++) | |
1052 { | |
1053 tem = XVECTOR (obj)->contents[i]; | |
1054 XVECTOR (new)->contents[i] = Fpurecopy (tem); | |
1055 } | |
1056 XSETTYPE (new, XTYPE (obj)); | |
1057 return new; | |
1058 | |
1059 default: | |
1060 return obj; | |
1061 } | |
1062 } | |
1063 | |
1064 /* Recording what needs to be marked for gc. */ | |
1065 | |
1066 struct gcpro *gcprolist; | |
1067 | |
727 | 1068 #define NSTATICS 512 |
300 | 1069 |
1070 Lisp_Object *staticvec[NSTATICS] = {0}; | |
1071 | |
1072 int staticidx = 0; | |
1073 | |
1074 /* Put an entry in staticvec, pointing at the variable whose address is given */ | |
1075 | |
1076 void | |
1077 staticpro (varaddress) | |
1078 Lisp_Object *varaddress; | |
1079 { | |
1080 staticvec[staticidx++] = varaddress; | |
1081 if (staticidx >= NSTATICS) | |
1082 abort (); | |
1083 } | |
1084 | |
1085 struct catchtag | |
1086 { | |
1087 Lisp_Object tag; | |
1088 Lisp_Object val; | |
1089 struct catchtag *next; | |
1090 /* jmp_buf jmp; /* We don't need this for GC purposes */ | |
1091 }; | |
1092 | |
1093 struct backtrace | |
1094 { | |
1095 struct backtrace *next; | |
1096 Lisp_Object *function; | |
1097 Lisp_Object *args; /* Points to vector of args. */ | |
1098 int nargs; /* length of vector */ | |
1099 /* if nargs is UNEVALLED, args points to slot holding list of unevalled args */ | |
1100 char evalargs; | |
1101 }; | |
1102 | |
1103 /* Two flags that are set during GC in the `size' component | |
1104 of a string or vector. On some machines, these flags | |
1105 are defined by the m- file to be different bits. */ | |
1106 | |
1107 /* On vector, means it has been marked. | |
1108 On string size field or a reference to a string, | |
1109 means not the last reference in the chain. */ | |
1110 | |
1111 #ifndef ARRAY_MARK_FLAG | |
1112 #define ARRAY_MARK_FLAG ((MARKBIT >> 1) & ~MARKBIT) | |
1113 #endif /* no ARRAY_MARK_FLAG */ | |
1114 | |
1115 /* Any slot that is a Lisp_Object can point to a string | |
1116 and thus can be put on a string's reference-chain | |
1117 and thus may need to have its ARRAY_MARK_FLAG set. | |
1118 This includes the slots whose markbits are used to mark | |
1119 the containing objects. */ | |
1120 | |
1121 #if ARRAY_MARK_FLAG == MARKBIT | |
1122 you lose | |
1123 #endif | |
1124 | |
1125 int total_conses, total_markers, total_symbols, total_string_size, total_vector_size; | |
1126 int total_free_conses, total_free_markers, total_free_symbols; | |
1127 #ifdef LISP_FLOAT_TYPE | |
1128 int total_free_floats, total_floats; | |
1129 #endif /* LISP_FLOAT_TYPE */ | |
1130 | |
1131 DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "", | |
1132 "Reclaim storage for Lisp objects no longer needed.\n\ | |
1133 Returns info on amount of space in use:\n\ | |
1134 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)\n\ | |
1135 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS\n\ | |
1136 (USED-FLOATS . FREE-FLOATS))\n\ | |
1137 Garbage collection happens automatically if you cons more than\n\ | |
1138 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.") | |
1139 () | |
1140 { | |
1141 register struct gcpro *tail; | |
1142 register struct specbinding *bind; | |
1143 struct catchtag *catch; | |
1144 struct handler *handler; | |
1145 register struct backtrace *backlist; | |
1146 register Lisp_Object tem; | |
1147 char *omessage = echo_area_glyphs; | |
1148 char stack_top_variable; | |
1149 register int i; | |
1150 | |
1151 /* Save a copy of the contents of the stack, for debugging. */ | |
1152 #if MAX_SAVE_STACK > 0 | |
485 | 1153 if (NILP (Vpurify_flag)) |
300 | 1154 { |
1155 i = &stack_top_variable - stack_bottom; | |
1156 if (i < 0) i = -i; | |
1157 if (i < MAX_SAVE_STACK) | |
1158 { | |
1159 if (stack_copy == 0) | |
1160 stack_copy = (char *) malloc (stack_copy_size = i); | |
1161 else if (stack_copy_size < i) | |
1162 stack_copy = (char *) realloc (stack_copy, (stack_copy_size = i)); | |
1163 if (stack_copy) | |
1164 { | |
1165 if ((int) (&stack_top_variable - stack_bottom) > 0) | |
1166 bcopy (stack_bottom, stack_copy, i); | |
1167 else | |
1168 bcopy (&stack_top_variable, stack_copy, i); | |
1169 } | |
1170 } | |
1171 } | |
1172 #endif /* MAX_SAVE_STACK > 0 */ | |
1173 | |
1174 if (!noninteractive) | |
1175 message1 ("Garbage collecting..."); | |
1176 | |
1177 /* Don't keep command history around forever */ | |
1178 tem = Fnthcdr (make_number (30), Vcommand_history); | |
1179 if (CONSP (tem)) | |
1180 XCONS (tem)->cdr = Qnil; | |
648 | 1181 |
300 | 1182 /* Likewise for undo information. */ |
1183 { | |
1184 register struct buffer *nextb = all_buffers; | |
1185 | |
1186 while (nextb) | |
1187 { | |
648 | 1188 /* If a buffer's undo list is Qt, that means that undo is |
1189 turned off in that buffer. Calling truncate_undo_list on | |
1190 Qt tends to return NULL, which effectively turns undo back on. | |
1191 So don't call truncate_undo_list if undo_list is Qt. */ | |
1192 if (! EQ (nextb->undo_list, Qt)) | |
1193 nextb->undo_list | |
764 | 1194 = truncate_undo_list (nextb->undo_list, undo_limit, |
1195 undo_strong_limit); | |
300 | 1196 nextb = nextb->next; |
1197 } | |
1198 } | |
1199 | |
1200 gc_in_progress = 1; | |
1201 | |
1202 /* clear_marks (); */ | |
1203 | |
1204 /* In each "large string", set the MARKBIT of the size field. | |
1205 That enables mark_object to recognize them. */ | |
1206 { | |
1207 register struct string_block *b; | |
1208 for (b = large_string_blocks; b; b = b->next) | |
1209 ((struct Lisp_String *)(&b->chars[0]))->size |= MARKBIT; | |
1210 } | |
1211 | |
1212 /* Mark all the special slots that serve as the roots of accessibility. | |
1213 | |
1214 Usually the special slots to mark are contained in particular structures. | |
1215 Then we know no slot is marked twice because the structures don't overlap. | |
1216 In some cases, the structures point to the slots to be marked. | |
1217 For these, we use MARKBIT to avoid double marking of the slot. */ | |
1218 | |
1219 for (i = 0; i < staticidx; i++) | |
1220 mark_object (staticvec[i]); | |
1221 for (tail = gcprolist; tail; tail = tail->next) | |
1222 for (i = 0; i < tail->nvars; i++) | |
1223 if (!XMARKBIT (tail->var[i])) | |
1224 { | |
1225 mark_object (&tail->var[i]); | |
1226 XMARK (tail->var[i]); | |
1227 } | |
1228 for (bind = specpdl; bind != specpdl_ptr; bind++) | |
1229 { | |
1230 mark_object (&bind->symbol); | |
1231 mark_object (&bind->old_value); | |
1232 } | |
1233 for (catch = catchlist; catch; catch = catch->next) | |
1234 { | |
1235 mark_object (&catch->tag); | |
1236 mark_object (&catch->val); | |
1237 } | |
1238 for (handler = handlerlist; handler; handler = handler->next) | |
1239 { | |
1240 mark_object (&handler->handler); | |
1241 mark_object (&handler->var); | |
1242 } | |
1243 for (backlist = backtrace_list; backlist; backlist = backlist->next) | |
1244 { | |
1245 if (!XMARKBIT (*backlist->function)) | |
1246 { | |
1247 mark_object (backlist->function); | |
1248 XMARK (*backlist->function); | |
1249 } | |
1250 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) | |
1251 i = 0; | |
1252 else | |
1253 i = backlist->nargs - 1; | |
1254 for (; i >= 0; i--) | |
1255 if (!XMARKBIT (backlist->args[i])) | |
1256 { | |
1257 mark_object (&backlist->args[i]); | |
1258 XMARK (backlist->args[i]); | |
1259 } | |
1260 } | |
1261 | |
1262 gc_sweep (); | |
1263 | |
1264 /* Clear the mark bits that we set in certain root slots. */ | |
1265 | |
1266 for (tail = gcprolist; tail; tail = tail->next) | |
1267 for (i = 0; i < tail->nvars; i++) | |
1268 XUNMARK (tail->var[i]); | |
1269 for (backlist = backtrace_list; backlist; backlist = backlist->next) | |
1270 { | |
1271 XUNMARK (*backlist->function); | |
1272 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) | |
1273 i = 0; | |
1274 else | |
1275 i = backlist->nargs - 1; | |
1276 for (; i >= 0; i--) | |
1277 XUNMARK (backlist->args[i]); | |
1278 } | |
1279 XUNMARK (buffer_defaults.name); | |
1280 XUNMARK (buffer_local_symbols.name); | |
1281 | |
1282 /* clear_marks (); */ | |
1283 gc_in_progress = 0; | |
1284 | |
1285 consing_since_gc = 0; | |
1286 if (gc_cons_threshold < 10000) | |
1287 gc_cons_threshold = 10000; | |
1288 | |
1289 if (omessage) | |
1290 message1 (omessage); | |
1291 else if (!noninteractive) | |
1292 message1 ("Garbage collecting...done"); | |
1293 | |
1294 return Fcons (Fcons (make_number (total_conses), | |
1295 make_number (total_free_conses)), | |
1296 Fcons (Fcons (make_number (total_symbols), | |
1297 make_number (total_free_symbols)), | |
1298 Fcons (Fcons (make_number (total_markers), | |
1299 make_number (total_free_markers)), | |
1300 Fcons (make_number (total_string_size), | |
1301 Fcons (make_number (total_vector_size), | |
1302 | |
1303 #ifdef LISP_FLOAT_TYPE | |
1304 Fcons (Fcons (make_number (total_floats), | |
1305 make_number (total_free_floats)), | |
1306 Qnil) | |
1307 #else /* not LISP_FLOAT_TYPE */ | |
1308 Qnil | |
1309 #endif /* not LISP_FLOAT_TYPE */ | |
1310 ))))); | |
1311 } | |
1312 | |
1313 #if 0 | |
1314 static void | |
1315 clear_marks () | |
1316 { | |
1317 /* Clear marks on all conses */ | |
1318 { | |
1319 register struct cons_block *cblk; | |
1320 register int lim = cons_block_index; | |
1321 | |
1322 for (cblk = cons_block; cblk; cblk = cblk->next) | |
1323 { | |
1324 register int i; | |
1325 for (i = 0; i < lim; i++) | |
1326 XUNMARK (cblk->conses[i].car); | |
1327 lim = CONS_BLOCK_SIZE; | |
1328 } | |
1329 } | |
1330 /* Clear marks on all symbols */ | |
1331 { | |
1332 register struct symbol_block *sblk; | |
1333 register int lim = symbol_block_index; | |
1334 | |
1335 for (sblk = symbol_block; sblk; sblk = sblk->next) | |
1336 { | |
1337 register int i; | |
1338 for (i = 0; i < lim; i++) | |
1339 { | |
1340 XUNMARK (sblk->symbols[i].plist); | |
1341 } | |
1342 lim = SYMBOL_BLOCK_SIZE; | |
1343 } | |
1344 } | |
1345 /* Clear marks on all markers */ | |
1346 { | |
1347 register struct marker_block *sblk; | |
1348 register int lim = marker_block_index; | |
1349 | |
1350 for (sblk = marker_block; sblk; sblk = sblk->next) | |
1351 { | |
1352 register int i; | |
1353 for (i = 0; i < lim; i++) | |
1354 XUNMARK (sblk->markers[i].chain); | |
1355 lim = MARKER_BLOCK_SIZE; | |
1356 } | |
1357 } | |
1358 /* Clear mark bits on all buffers */ | |
1359 { | |
1360 register struct buffer *nextb = all_buffers; | |
1361 | |
1362 while (nextb) | |
1363 { | |
1364 XUNMARK (nextb->name); | |
1365 nextb = nextb->next; | |
1366 } | |
1367 } | |
1368 } | |
1369 #endif | |
1370 | |
1371 /* Mark reference to a Lisp_Object. If the object referred to | |
1372 has not been seen yet, recursively mark all the references contained in it. | |
1373 | |
1374 If the object referenced is a short string, the referrencing slot | |
1375 is threaded into a chain of such slots, pointed to from | |
1376 the `size' field of the string. The actual string size | |
1377 lives in the last slot in the chain. We recognize the end | |
1378 because it is < (unsigned) STRING_BLOCK_SIZE. */ | |
1379 | |
1168
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1380 #define LAST_MARKED_SIZE 500 |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1381 Lisp_Object *last_marked[LAST_MARKED_SIZE]; |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1382 int last_marked_index; |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1383 |
300 | 1384 static void |
1385 mark_object (objptr) | |
1386 Lisp_Object *objptr; | |
1387 { | |
1388 register Lisp_Object obj; | |
1389 | |
1390 obj = *objptr; | |
1391 XUNMARK (obj); | |
1392 | |
1393 loop: | |
1394 | |
1395 if ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) ((char *) pure + PURESIZE) | |
1396 && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure) | |
1397 return; | |
1398 | |
1168
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1399 last_marked[last_marked_index++] = objptr; |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1400 if (last_marked_index == LAST_MARKED_SIZE) |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1401 last_marked_index = 0; |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1402 |
300 | 1403 #ifdef SWITCH_ENUM_BUG |
1404 switch ((int) XGCTYPE (obj)) | |
1405 #else | |
1406 switch (XGCTYPE (obj)) | |
1407 #endif | |
1408 { | |
1409 case Lisp_String: | |
1410 { | |
1411 register struct Lisp_String *ptr = XSTRING (obj); | |
1412 | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1413 MARK_INTERVAL_TREE (ptr->intervals); |
300 | 1414 if (ptr->size & MARKBIT) |
1415 /* A large string. Just set ARRAY_MARK_FLAG. */ | |
1416 ptr->size |= ARRAY_MARK_FLAG; | |
1417 else | |
1418 { | |
1419 /* A small string. Put this reference | |
1420 into the chain of references to it. | |
1421 The address OBJPTR is even, so if the address | |
1422 includes MARKBIT, put it in the low bit | |
1423 when we store OBJPTR into the size field. */ | |
1424 | |
1425 if (XMARKBIT (*objptr)) | |
1426 { | |
1427 XFASTINT (*objptr) = ptr->size; | |
1428 XMARK (*objptr); | |
1429 } | |
1430 else | |
1431 XFASTINT (*objptr) = ptr->size; | |
1432 if ((int)objptr & 1) abort (); | |
1433 ptr->size = (int) objptr & ~MARKBIT; | |
1434 if ((int) objptr & MARKBIT) | |
1435 ptr->size ++; | |
1436 } | |
1437 } | |
1438 break; | |
1439 | |
1440 case Lisp_Vector: | |
1441 case Lisp_Window: | |
1442 case Lisp_Process: | |
1443 case Lisp_Window_Configuration: | |
1444 { | |
1445 register struct Lisp_Vector *ptr = XVECTOR (obj); | |
1446 register int size = ptr->size; | |
1168
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1447 struct Lisp_Vector *volatile ptr1 = ptr; |
300 | 1448 register int i; |
1449 | |
1450 if (size & ARRAY_MARK_FLAG) break; /* Already marked */ | |
1451 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ | |
1452 for (i = 0; i < size; i++) /* and then mark its elements */ | |
1168
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1453 { |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1454 if (ptr != ptr1) |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1455 abort (); |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1456 mark_object (&ptr->contents[i]); |
2b07af77d7ec
(mark_object): Save last 500 values of objptr.
Richard M. Stallman <rms@gnu.org>
parents:
1114
diff
changeset
|
1457 } |
300 | 1458 } |
1459 break; | |
1460 | |
1295
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1461 case Lisp_Compiled: |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1462 /* We could treat this just like a vector, but it is better |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1463 to save the COMPILED_CONSTANTS element for last and avoid recursion |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1464 there. */ |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1465 { |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1466 register struct Lisp_Vector *ptr = XVECTOR (obj); |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1467 register int size = ptr->size; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1468 struct Lisp_Vector *volatile ptr1 = ptr; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1469 register int i; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1470 |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1471 if (size & ARRAY_MARK_FLAG) break; /* Already marked */ |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1472 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1473 for (i = 0; i < size; i++) /* and then mark its elements */ |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1474 { |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1475 if (ptr != ptr1) |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1476 abort (); |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1477 if (i != COMPILED_CONSTANTS) |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1478 mark_object (&ptr->contents[i]); |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1479 } |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1480 objptr = &ptr->contents[COMPILED_CONSTANTS]; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1481 obj = *objptr; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1482 goto loop; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1483 } |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1484 |
764 | 1485 #ifdef MULTI_FRAME |
1486 case Lisp_Frame: | |
300 | 1487 { |
764 | 1488 register struct frame *ptr = XFRAME (obj); |
300 | 1489 register int size = ptr->size; |
1490 register int i; | |
1491 | |
1492 if (size & ARRAY_MARK_FLAG) break; /* Already marked */ | |
1493 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */ | |
1494 | |
1495 mark_object (&ptr->name); | |
764 | 1496 mark_object (&ptr->focus_frame); |
300 | 1497 mark_object (&ptr->width); |
1498 mark_object (&ptr->height); | |
1499 mark_object (&ptr->selected_window); | |
1500 mark_object (&ptr->minibuffer_window); | |
1501 mark_object (&ptr->param_alist); | |
1502 } | |
1503 break; | |
989
dc3fda1e21d0
* alloc.c (Fgarbage_collect): Doc fix.
Jim Blandy <jimb@redhat.com>
parents:
764
diff
changeset
|
1504 #endif /* not MULTI_FRAME */ |
300 | 1505 |
1506 case Lisp_Symbol: | |
1507 { | |
1508 register struct Lisp_Symbol *ptr = XSYMBOL (obj); | |
1509 struct Lisp_Symbol *ptrx; | |
1510 | |
1511 if (XMARKBIT (ptr->plist)) break; | |
1512 XMARK (ptr->plist); | |
1513 mark_object ((Lisp_Object *) &ptr->value); | |
1514 mark_object (&ptr->function); | |
1515 mark_object (&ptr->plist); | |
1114
903883eed4de
* alloc.c (mark_object): mark a symbol's name after marking its
Jim Blandy <jimb@redhat.com>
parents:
1000
diff
changeset
|
1516 XSETTYPE (*(Lisp_Object *) &ptr->name, Lisp_String); |
903883eed4de
* alloc.c (mark_object): mark a symbol's name after marking its
Jim Blandy <jimb@redhat.com>
parents:
1000
diff
changeset
|
1517 mark_object (&ptr->name); |
300 | 1518 ptr = ptr->next; |
1519 if (ptr) | |
1520 { | |
1521 ptrx = ptr; /* Use pf ptrx avoids compiler bug on Sun */ | |
1522 XSETSYMBOL (obj, ptrx); | |
1523 goto loop; | |
1524 } | |
1525 } | |
1526 break; | |
1527 | |
1528 case Lisp_Marker: | |
1529 XMARK (XMARKER (obj)->chain); | |
1530 /* DO NOT mark thru the marker's chain. | |
1531 The buffer's markers chain does not preserve markers from gc; | |
1295
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1532 instead, markers are removed from the chain when freed by gc. */ |
300 | 1533 break; |
1534 | |
1535 case Lisp_Cons: | |
1536 case Lisp_Buffer_Local_Value: | |
1537 case Lisp_Some_Buffer_Local_Value: | |
1538 { | |
1539 register struct Lisp_Cons *ptr = XCONS (obj); | |
1540 if (XMARKBIT (ptr->car)) break; | |
1541 XMARK (ptr->car); | |
1295
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1542 /* If the cdr is nil, avoid recursion for the car. */ |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1543 if (EQ (ptr->cdr, Qnil)) |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1544 { |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1545 objptr = &ptr->car; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1546 obj = ptr->car; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1547 XUNMARK (obj); |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1548 goto loop; |
a9241dc503ab
(mark_object): Avoid car recursion on cons with nil in cdr.
Richard M. Stallman <rms@gnu.org>
parents:
1168
diff
changeset
|
1549 } |
300 | 1550 mark_object (&ptr->car); |
1551 objptr = &ptr->cdr; | |
1552 obj = ptr->cdr; | |
1553 goto loop; | |
1554 } | |
1555 | |
1556 #ifdef LISP_FLOAT_TYPE | |
1557 case Lisp_Float: | |
1558 XMARK (XFLOAT (obj)->type); | |
1559 break; | |
1560 #endif /* LISP_FLOAT_TYPE */ | |
1561 | |
1562 case Lisp_Buffer: | |
1563 if (!XMARKBIT (XBUFFER (obj)->name)) | |
1564 mark_buffer (obj); | |
1565 break; | |
1566 | |
1567 case Lisp_Int: | |
1568 case Lisp_Void: | |
1569 case Lisp_Subr: | |
1570 case Lisp_Intfwd: | |
1571 case Lisp_Boolfwd: | |
1572 case Lisp_Objfwd: | |
1573 case Lisp_Buffer_Objfwd: | |
1574 case Lisp_Internal_Stream: | |
1575 /* Don't bother with Lisp_Buffer_Objfwd, | |
1576 since all markable slots in current buffer marked anyway. */ | |
1577 /* Don't need to do Lisp_Objfwd, since the places they point | |
1578 are protected with staticpro. */ | |
1579 break; | |
1580 | |
1581 default: | |
1582 abort (); | |
1583 } | |
1584 } | |
1585 | |
1586 /* Mark the pointers in a buffer structure. */ | |
1587 | |
1588 static void | |
1589 mark_buffer (buf) | |
1590 Lisp_Object buf; | |
1591 { | |
1592 Lisp_Object tem; | |
1593 register struct buffer *buffer = XBUFFER (buf); | |
1594 register Lisp_Object *ptr; | |
1595 | |
1596 /* This is the buffer's markbit */ | |
1597 mark_object (&buffer->name); | |
1598 XMARK (buffer->name); | |
1599 | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1600 MARK_INTERVAL_TREE (buffer->intervals); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1601 |
300 | 1602 #if 0 |
1603 mark_object (buffer->syntax_table); | |
1604 | |
1605 /* Mark the various string-pointers in the buffer object. | |
1606 Since the strings may be relocated, we must mark them | |
1607 in their actual slots. So gc_sweep must convert each slot | |
1608 back to an ordinary C pointer. */ | |
1609 XSET (*(Lisp_Object *)&buffer->upcase_table, | |
1610 Lisp_String, buffer->upcase_table); | |
1611 mark_object ((Lisp_Object *)&buffer->upcase_table); | |
1612 XSET (*(Lisp_Object *)&buffer->downcase_table, | |
1613 Lisp_String, buffer->downcase_table); | |
1614 mark_object ((Lisp_Object *)&buffer->downcase_table); | |
1615 | |
1616 XSET (*(Lisp_Object *)&buffer->sort_table, | |
1617 Lisp_String, buffer->sort_table); | |
1618 mark_object ((Lisp_Object *)&buffer->sort_table); | |
1619 XSET (*(Lisp_Object *)&buffer->folding_sort_table, | |
1620 Lisp_String, buffer->folding_sort_table); | |
1621 mark_object ((Lisp_Object *)&buffer->folding_sort_table); | |
1622 #endif | |
1623 | |
1624 for (ptr = &buffer->name + 1; | |
1625 (char *)ptr < (char *)buffer + sizeof (struct buffer); | |
1626 ptr++) | |
1627 mark_object (ptr); | |
1628 } | |
1629 | |
1630 /* Find all structures not marked, and free them. */ | |
1631 | |
1632 static void | |
1633 gc_sweep () | |
1634 { | |
1635 total_string_size = 0; | |
1636 compact_strings (); | |
1637 | |
1638 /* Put all unmarked conses on free list */ | |
1639 { | |
1640 register struct cons_block *cblk; | |
1641 register int lim = cons_block_index; | |
1642 register int num_free = 0, num_used = 0; | |
1643 | |
1644 cons_free_list = 0; | |
1645 | |
1646 for (cblk = cons_block; cblk; cblk = cblk->next) | |
1647 { | |
1648 register int i; | |
1649 for (i = 0; i < lim; i++) | |
1650 if (!XMARKBIT (cblk->conses[i].car)) | |
1651 { | |
1652 XFASTINT (cblk->conses[i].car) = (int) cons_free_list; | |
1653 num_free++; | |
1654 cons_free_list = &cblk->conses[i]; | |
1655 } | |
1656 else | |
1657 { | |
1658 num_used++; | |
1659 XUNMARK (cblk->conses[i].car); | |
1660 } | |
1661 lim = CONS_BLOCK_SIZE; | |
1662 } | |
1663 total_conses = num_used; | |
1664 total_free_conses = num_free; | |
1665 } | |
1666 | |
1667 #ifdef LISP_FLOAT_TYPE | |
1668 /* Put all unmarked floats on free list */ | |
1669 { | |
1670 register struct float_block *fblk; | |
1671 register int lim = float_block_index; | |
1672 register int num_free = 0, num_used = 0; | |
1673 | |
1674 float_free_list = 0; | |
1675 | |
1676 for (fblk = float_block; fblk; fblk = fblk->next) | |
1677 { | |
1678 register int i; | |
1679 for (i = 0; i < lim; i++) | |
1680 if (!XMARKBIT (fblk->floats[i].type)) | |
1681 { | |
1682 XFASTINT (fblk->floats[i].type) = (int) float_free_list; | |
1683 num_free++; | |
1684 float_free_list = &fblk->floats[i]; | |
1685 } | |
1686 else | |
1687 { | |
1688 num_used++; | |
1689 XUNMARK (fblk->floats[i].type); | |
1690 } | |
1691 lim = FLOAT_BLOCK_SIZE; | |
1692 } | |
1693 total_floats = num_used; | |
1694 total_free_floats = num_free; | |
1695 } | |
1696 #endif /* LISP_FLOAT_TYPE */ | |
1697 | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1698 #ifdef USE_TEXT_PROPERTIES |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1699 /* Put all unmarked intervals on free list */ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1700 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1701 register struct interval_block *iblk; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1702 register int lim = interval_block_index; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1703 register int num_free = 0, num_used = 0; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1704 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1705 interval_free_list = 0; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1706 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1707 for (iblk = interval_block; iblk; iblk = iblk->next) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1708 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1709 register int i; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1710 |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1711 for (i = 0; i < lim; i++) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1712 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1713 if (! XMARKBIT (iblk->intervals[i].plist)) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1714 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1715 iblk->intervals[i].parent = interval_free_list; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1716 interval_free_list = &iblk->intervals[i]; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1717 num_free++; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1718 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1719 else |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1720 { |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1721 num_used++; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1722 XUNMARK (iblk->intervals[i].plist); |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1723 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1724 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1725 lim = INTERVAL_BLOCK_SIZE; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1726 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1727 total_intervals = num_used; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1728 total_free_intervals = num_free; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1729 } |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1730 #endif /* USE_TEXT_PROPERTIES */ |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1731 |
300 | 1732 /* Put all unmarked symbols on free list */ |
1733 { | |
1734 register struct symbol_block *sblk; | |
1735 register int lim = symbol_block_index; | |
1736 register int num_free = 0, num_used = 0; | |
1737 | |
1738 symbol_free_list = 0; | |
1739 | |
1740 for (sblk = symbol_block; sblk; sblk = sblk->next) | |
1741 { | |
1742 register int i; | |
1743 for (i = 0; i < lim; i++) | |
1744 if (!XMARKBIT (sblk->symbols[i].plist)) | |
1745 { | |
1746 XFASTINT (sblk->symbols[i].value) = (int) symbol_free_list; | |
1747 symbol_free_list = &sblk->symbols[i]; | |
1748 num_free++; | |
1749 } | |
1750 else | |
1751 { | |
1752 num_used++; | |
1753 sblk->symbols[i].name | |
1754 = XSTRING (*(Lisp_Object *) &sblk->symbols[i].name); | |
1755 XUNMARK (sblk->symbols[i].plist); | |
1756 } | |
1757 lim = SYMBOL_BLOCK_SIZE; | |
1758 } | |
1759 total_symbols = num_used; | |
1760 total_free_symbols = num_free; | |
1761 } | |
1762 | |
1763 #ifndef standalone | |
1764 /* Put all unmarked markers on free list. | |
1765 Dechain each one first from the buffer it points into. */ | |
1766 { | |
1767 register struct marker_block *mblk; | |
1768 struct Lisp_Marker *tem1; | |
1769 register int lim = marker_block_index; | |
1770 register int num_free = 0, num_used = 0; | |
1771 | |
1772 marker_free_list = 0; | |
1773 | |
1774 for (mblk = marker_block; mblk; mblk = mblk->next) | |
1775 { | |
1776 register int i; | |
1777 for (i = 0; i < lim; i++) | |
1778 if (!XMARKBIT (mblk->markers[i].chain)) | |
1779 { | |
1780 Lisp_Object tem; | |
1781 tem1 = &mblk->markers[i]; /* tem1 avoids Sun compiler bug */ | |
1782 XSET (tem, Lisp_Marker, tem1); | |
1783 unchain_marker (tem); | |
1784 XFASTINT (mblk->markers[i].chain) = (int) marker_free_list; | |
1785 marker_free_list = &mblk->markers[i]; | |
1786 num_free++; | |
1787 } | |
1788 else | |
1789 { | |
1790 num_used++; | |
1791 XUNMARK (mblk->markers[i].chain); | |
1792 } | |
1793 lim = MARKER_BLOCK_SIZE; | |
1794 } | |
1795 | |
1796 total_markers = num_used; | |
1797 total_free_markers = num_free; | |
1798 } | |
1799 | |
1800 /* Free all unmarked buffers */ | |
1801 { | |
1802 register struct buffer *buffer = all_buffers, *prev = 0, *next; | |
1803 | |
1804 while (buffer) | |
1805 if (!XMARKBIT (buffer->name)) | |
1806 { | |
1807 if (prev) | |
1808 prev->next = buffer->next; | |
1809 else | |
1810 all_buffers = buffer->next; | |
1811 next = buffer->next; | |
1812 free (buffer); | |
1813 buffer = next; | |
1814 } | |
1815 else | |
1816 { | |
1817 XUNMARK (buffer->name); | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1818 UNMARK_BALANCE_INTERVALS (buffer->intervals); |
300 | 1819 |
1820 #if 0 | |
1821 /* Each `struct Lisp_String *' was turned into a Lisp_Object | |
1822 for purposes of marking and relocation. | |
1823 Turn them back into C pointers now. */ | |
1824 buffer->upcase_table | |
1825 = XSTRING (*(Lisp_Object *)&buffer->upcase_table); | |
1826 buffer->downcase_table | |
1827 = XSTRING (*(Lisp_Object *)&buffer->downcase_table); | |
1828 buffer->sort_table | |
1829 = XSTRING (*(Lisp_Object *)&buffer->sort_table); | |
1830 buffer->folding_sort_table | |
1831 = XSTRING (*(Lisp_Object *)&buffer->folding_sort_table); | |
1832 #endif | |
1833 | |
1834 prev = buffer, buffer = buffer->next; | |
1835 } | |
1836 } | |
1837 | |
1838 #endif /* standalone */ | |
1839 | |
1840 /* Free all unmarked vectors */ | |
1841 { | |
1842 register struct Lisp_Vector *vector = all_vectors, *prev = 0, *next; | |
1843 total_vector_size = 0; | |
1844 | |
1845 while (vector) | |
1846 if (!(vector->size & ARRAY_MARK_FLAG)) | |
1847 { | |
1848 if (prev) | |
1849 prev->next = vector->next; | |
1850 else | |
1851 all_vectors = vector->next; | |
1852 next = vector->next; | |
1853 free (vector); | |
1854 vector = next; | |
1855 } | |
1856 else | |
1857 { | |
1858 vector->size &= ~ARRAY_MARK_FLAG; | |
1859 total_vector_size += vector->size; | |
1860 prev = vector, vector = vector->next; | |
1861 } | |
1862 } | |
1863 | |
1864 /* Free all "large strings" not marked with ARRAY_MARK_FLAG. */ | |
1865 { | |
1866 register struct string_block *sb = large_string_blocks, *prev = 0, *next; | |
1867 | |
1868 while (sb) | |
1869 if (!(((struct Lisp_String *)(&sb->chars[0]))->size & ARRAY_MARK_FLAG)) | |
1870 { | |
1871 if (prev) | |
1872 prev->next = sb->next; | |
1873 else | |
1874 large_string_blocks = sb->next; | |
1875 next = sb->next; | |
1876 free (sb); | |
1877 sb = next; | |
1878 } | |
1879 else | |
1880 { | |
1881 ((struct Lisp_String *)(&sb->chars[0]))->size | |
1882 &= ~ARRAY_MARK_FLAG & ~MARKBIT; | |
1883 total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size; | |
1884 prev = sb, sb = sb->next; | |
1885 } | |
1886 } | |
1887 } | |
1888 | |
1889 /* Compactify strings, relocate references to them, and | |
1890 free any string blocks that become empty. */ | |
1891 | |
1892 static void | |
1893 compact_strings () | |
1894 { | |
1895 /* String block of old strings we are scanning. */ | |
1896 register struct string_block *from_sb; | |
1897 /* A preceding string block (or maybe the same one) | |
1898 where we are copying the still-live strings to. */ | |
1899 register struct string_block *to_sb; | |
1900 int pos; | |
1901 int to_pos; | |
1902 | |
1903 to_sb = first_string_block; | |
1904 to_pos = 0; | |
1905 | |
1906 /* Scan each existing string block sequentially, string by string. */ | |
1907 for (from_sb = first_string_block; from_sb; from_sb = from_sb->next) | |
1908 { | |
1909 pos = 0; | |
1910 /* POS is the index of the next string in the block. */ | |
1911 while (pos < from_sb->pos) | |
1912 { | |
1913 register struct Lisp_String *nextstr | |
1914 = (struct Lisp_String *) &from_sb->chars[pos]; | |
1915 | |
1916 register struct Lisp_String *newaddr; | |
1917 register int size = nextstr->size; | |
1918 | |
1919 /* NEXTSTR is the old address of the next string. | |
1920 Just skip it if it isn't marked. */ | |
1921 if ((unsigned) size > STRING_BLOCK_SIZE) | |
1922 { | |
1923 /* It is marked, so its size field is really a chain of refs. | |
1924 Find the end of the chain, where the actual size lives. */ | |
1925 while ((unsigned) size > STRING_BLOCK_SIZE) | |
1926 { | |
1927 if (size & 1) size ^= MARKBIT | 1; | |
1928 size = *(int *)size & ~MARKBIT; | |
1929 } | |
1930 | |
1931 total_string_size += size; | |
1932 | |
1933 /* If it won't fit in TO_SB, close it out, | |
1934 and move to the next sb. Keep doing so until | |
1935 TO_SB reaches a large enough, empty enough string block. | |
1936 We know that TO_SB cannot advance past FROM_SB here | |
1937 since FROM_SB is large enough to contain this string. | |
1938 Any string blocks skipped here | |
1939 will be patched out and freed later. */ | |
1940 while (to_pos + STRING_FULLSIZE (size) | |
1941 > max (to_sb->pos, STRING_BLOCK_SIZE)) | |
1942 { | |
1943 to_sb->pos = to_pos; | |
1944 to_sb = to_sb->next; | |
1945 to_pos = 0; | |
1946 } | |
1947 /* Compute new address of this string | |
1948 and update TO_POS for the space being used. */ | |
1949 newaddr = (struct Lisp_String *) &to_sb->chars[to_pos]; | |
1950 to_pos += STRING_FULLSIZE (size); | |
1951 | |
1952 /* Copy the string itself to the new place. */ | |
1953 if (nextstr != newaddr) | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1954 bcopy (nextstr, newaddr, size + 1 + sizeof (int) |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
1955 + INTERVAL_PTR_SIZE); |
300 | 1956 |
1957 /* Go through NEXTSTR's chain of references | |
1958 and make each slot in the chain point to | |
1959 the new address of this string. */ | |
1960 size = newaddr->size; | |
1961 while ((unsigned) size > STRING_BLOCK_SIZE) | |
1962 { | |
1963 register Lisp_Object *objptr; | |
1964 if (size & 1) size ^= MARKBIT | 1; | |
1965 objptr = (Lisp_Object *)size; | |
1966 | |
1967 size = XFASTINT (*objptr) & ~MARKBIT; | |
1968 if (XMARKBIT (*objptr)) | |
1969 { | |
1970 XSET (*objptr, Lisp_String, newaddr); | |
1971 XMARK (*objptr); | |
1972 } | |
1973 else | |
1974 XSET (*objptr, Lisp_String, newaddr); | |
1975 } | |
1976 /* Store the actual size in the size field. */ | |
1977 newaddr->size = size; | |
1978 } | |
1979 pos += STRING_FULLSIZE (size); | |
1980 } | |
1981 } | |
1982 | |
1983 /* Close out the last string block still used and free any that follow. */ | |
1984 to_sb->pos = to_pos; | |
1985 current_string_block = to_sb; | |
1986 | |
1987 from_sb = to_sb->next; | |
1988 to_sb->next = 0; | |
1989 while (from_sb) | |
1990 { | |
1991 to_sb = from_sb->next; | |
1992 free (from_sb); | |
1993 from_sb = to_sb; | |
1994 } | |
1995 | |
1996 /* Free any empty string blocks further back in the chain. | |
1997 This loop will never free first_string_block, but it is very | |
1998 unlikely that that one will become empty, so why bother checking? */ | |
1999 | |
2000 from_sb = first_string_block; | |
2001 while (to_sb = from_sb->next) | |
2002 { | |
2003 if (to_sb->pos == 0) | |
2004 { | |
2005 if (from_sb->next = to_sb->next) | |
2006 from_sb->next->prev = from_sb; | |
2007 free (to_sb); | |
2008 } | |
2009 else | |
2010 from_sb = to_sb; | |
2011 } | |
2012 } | |
2013 | |
1327
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2014 /* Debugging aids. */ |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2015 |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2016 DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, "", |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2017 "Return the address of the last byte Emacs has allocated, divided by 1024.\n\ |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2018 This may be helpful in debugging Emacs's memory usage.\n\ |
1362
4bea5980f778
* alloc.c (Fmemory_limit): Explain why we divide by 1024.
Jim Blandy <jimb@redhat.com>
parents:
1327
diff
changeset
|
2019 The value is divided by 1024 to make sure it will fit in a lisp integer.") |
1327
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2020 () |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2021 { |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2022 Lisp_Object end; |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2023 |
1362
4bea5980f778
* alloc.c (Fmemory_limit): Explain why we divide by 1024.
Jim Blandy <jimb@redhat.com>
parents:
1327
diff
changeset
|
2024 XSET (end, Lisp_Int, (int) sbrk (0) / 1024); |
1327
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2025 |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2026 return end; |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2027 } |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2028 |
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2029 |
300 | 2030 /* Initialization */ |
2031 | |
2032 init_alloc_once () | |
2033 { | |
2034 /* Used to do Vpurify_flag = Qt here, but Qt isn't set up yet! */ | |
2035 pureptr = 0; | |
356 | 2036 #ifdef HAVE_SHM |
2037 pure_size = PURESIZE; | |
2038 #endif | |
300 | 2039 all_vectors = 0; |
2040 ignore_warnings = 1; | |
2041 init_strings (); | |
2042 init_cons (); | |
2043 init_symbol (); | |
2044 init_marker (); | |
2045 #ifdef LISP_FLOAT_TYPE | |
2046 init_float (); | |
2047 #endif /* LISP_FLOAT_TYPE */ | |
1300
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
2048 INIT_INTERVALS; |
b13b79e28eb5
* alloc.c: #include "intervals.h".
Joseph Arceneaux <jla@gnu.org>
parents:
1295
diff
changeset
|
2049 |
300 | 2050 ignore_warnings = 0; |
2051 gcprolist = 0; | |
2052 staticidx = 0; | |
2053 consing_since_gc = 0; | |
2054 gc_cons_threshold = 100000; | |
2055 #ifdef VIRT_ADDR_VARIES | |
2056 malloc_sbrk_unused = 1<<22; /* A large number */ | |
2057 malloc_sbrk_used = 100000; /* as reasonable as any number */ | |
2058 #endif /* VIRT_ADDR_VARIES */ | |
2059 } | |
2060 | |
2061 init_alloc () | |
2062 { | |
2063 gcprolist = 0; | |
2064 } | |
2065 | |
2066 void | |
2067 syms_of_alloc () | |
2068 { | |
2069 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold, | |
2070 "*Number of bytes of consing between garbage collections.\n\ | |
2071 Garbage collection can happen automatically once this many bytes have been\n\ | |
2072 allocated since the last garbage collection. All data types count.\n\n\ | |
2073 Garbage collection happens automatically only when `eval' is called.\n\n\ | |
2074 By binding this temporarily to a large number, you can effectively\n\ | |
2075 prevent garbage collection during a part of the program."); | |
2076 | |
2077 DEFVAR_INT ("pure-bytes-used", &pureptr, | |
2078 "Number of bytes of sharable Lisp data allocated so far."); | |
2079 | |
2080 #if 0 | |
2081 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used, | |
2082 "Number of bytes of unshared memory allocated in this session."); | |
2083 | |
2084 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused, | |
2085 "Number of bytes of unshared memory remaining available in this session."); | |
2086 #endif | |
2087 | |
2088 DEFVAR_LISP ("purify-flag", &Vpurify_flag, | |
2089 "Non-nil means loading Lisp code in order to dump an executable.\n\ | |
2090 This means that certain objects should be allocated in shared (pure) space."); | |
2091 | |
764 | 2092 DEFVAR_INT ("undo-limit", &undo_limit, |
300 | 2093 "Keep no more undo information once it exceeds this size.\n\ |
764 | 2094 This limit is applied when garbage collection happens.\n\ |
300 | 2095 The size is counted as the number of bytes occupied,\n\ |
2096 which includes both saved text and other data."); | |
764 | 2097 undo_limit = 20000; |
300 | 2098 |
764 | 2099 DEFVAR_INT ("undo-strong-limit", &undo_strong_limit, |
300 | 2100 "Don't keep more than this much size of undo information.\n\ |
2101 A command which pushes past this size is itself forgotten.\n\ | |
764 | 2102 This limit is applied when garbage collection happens.\n\ |
300 | 2103 The size is counted as the number of bytes occupied,\n\ |
2104 which includes both saved text and other data."); | |
764 | 2105 undo_strong_limit = 30000; |
300 | 2106 |
2107 defsubr (&Scons); | |
2108 defsubr (&Slist); | |
2109 defsubr (&Svector); | |
2110 defsubr (&Smake_byte_code); | |
2111 defsubr (&Smake_list); | |
2112 defsubr (&Smake_vector); | |
2113 defsubr (&Smake_string); | |
2114 defsubr (&Smake_rope); | |
2115 defsubr (&Srope_elt); | |
2116 defsubr (&Smake_symbol); | |
2117 defsubr (&Smake_marker); | |
2118 defsubr (&Spurecopy); | |
2119 defsubr (&Sgarbage_collect); | |
1327
ef16e7c0d402
* alloc.c (Fmemory_limit): New function.
Jim Blandy <jimb@redhat.com>
parents:
1318
diff
changeset
|
2120 defsubr (&Smemory_limit); |
300 | 2121 } |