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