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