300
|
1 /* Storage allocation and gc for GNU Emacs Lisp interpreter.
|
17348
|
2 Copyright (C) 1985, 86, 88, 93, 94, 95, 97 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
|
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
|
14186
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
300
|
20
|
13320
|
21 /* Note that this declares bzero on OSF/1. How dumb. */
|
3003
|
22 #include <signal.h>
|
300
|
23
|
4696
|
24 #include <config.h>
|
300
|
25 #include "lisp.h"
|
1300
|
26 #include "intervals.h"
|
356
|
27 #include "puresize.h"
|
300
|
28 #ifndef standalone
|
|
29 #include "buffer.h"
|
|
30 #include "window.h"
|
764
|
31 #include "frame.h"
|
2439
|
32 #include "blockinput.h"
|
11341
|
33 #include "keyboard.h"
|
300
|
34 #endif
|
|
35
|
638
|
36 #include "syssignal.h"
|
|
37
|
12096
|
38 extern char *sbrk ();
|
|
39
|
17345
|
40 #ifdef DOUG_LEA_MALLOC
|
|
41 #include <malloc.h>
|
|
42 #define __malloc_size_t int
|
|
43 #else
|
10673
|
44 /* The following come from gmalloc.c. */
|
|
45
|
|
46 #if defined (__STDC__) && __STDC__
|
|
47 #include <stddef.h>
|
|
48 #define __malloc_size_t size_t
|
|
49 #else
|
|
50 #define __malloc_size_t unsigned int
|
|
51 #endif
|
|
52 extern __malloc_size_t _bytes_used;
|
|
53 extern int __malloc_extra_blocks;
|
17345
|
54 #endif /* !defined(DOUG_LEA_MALLOC) */
|
10673
|
55
|
16538
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
56 extern Lisp_Object Vhistory_length;
|
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
57
|
300
|
58 #define max(A,B) ((A) > (B) ? (A) : (B))
|
11727
|
59 #define min(A,B) ((A) < (B) ? (A) : (B))
|
300
|
60
|
|
61 /* Macro to verify that storage intended for Lisp objects is not
|
|
62 out of range to fit in the space for a pointer.
|
|
63 ADDRESS is the start of the block, and SIZE
|
|
64 is the amount of space within which objects can start. */
|
|
65 #define VALIDATE_LISP_STORAGE(address, size) \
|
|
66 do \
|
|
67 { \
|
|
68 Lisp_Object val; \
|
9261
|
69 XSETCONS (val, (char *) address + size); \
|
300
|
70 if ((char *) XCONS (val) != (char *) address + size) \
|
|
71 { \
|
2439
|
72 xfree (address); \
|
300
|
73 memory_full (); \
|
|
74 } \
|
|
75 } while (0)
|
|
76
|
10673
|
77 /* Value of _bytes_used, when spare_memory was freed. */
|
|
78 static __malloc_size_t bytes_used_when_full;
|
|
79
|
300
|
80 /* Number of bytes of consing done since the last gc */
|
|
81 int consing_since_gc;
|
|
82
|
12748
|
83 /* Count the amount of consing of various sorts of space. */
|
|
84 int cons_cells_consed;
|
|
85 int floats_consed;
|
|
86 int vector_cells_consed;
|
|
87 int symbols_consed;
|
|
88 int string_chars_consed;
|
|
89 int misc_objects_consed;
|
|
90 int intervals_consed;
|
|
91
|
300
|
92 /* Number of bytes of consing since gc before another gc should be done. */
|
11727
|
93 int gc_cons_threshold;
|
300
|
94
|
|
95 /* Nonzero during gc */
|
|
96 int gc_in_progress;
|
|
97
|
14959
|
98 /* Nonzero means display messages at beginning and end of GC. */
|
|
99 int garbage_collection_messages;
|
|
100
|
300
|
101 #ifndef VIRT_ADDR_VARIES
|
|
102 extern
|
|
103 #endif /* VIRT_ADDR_VARIES */
|
|
104 int malloc_sbrk_used;
|
|
105
|
|
106 #ifndef VIRT_ADDR_VARIES
|
|
107 extern
|
|
108 #endif /* VIRT_ADDR_VARIES */
|
|
109 int malloc_sbrk_unused;
|
|
110
|
764
|
111 /* Two limits controlling how much undo information to keep. */
|
|
112 int undo_limit;
|
|
113 int undo_strong_limit;
|
300
|
114
|
19332
|
115 int total_conses, total_markers, total_symbols, total_string_size, total_vector_size;
|
|
116 int total_free_conses, total_free_markers, total_free_symbols;
|
|
117 #ifdef LISP_FLOAT_TYPE
|
|
118 int total_free_floats, total_floats;
|
|
119 #endif /* LISP_FLOAT_TYPE */
|
|
120
|
10673
|
121 /* Points to memory space allocated as "spare",
|
|
122 to be freed if we run out of memory. */
|
|
123 static char *spare_memory;
|
|
124
|
|
125 /* Amount of spare memory to keep in reserve. */
|
|
126 #define SPARE_MEMORY (1 << 14)
|
|
127
|
|
128 /* Number of extra blocks malloc should get when it needs more core. */
|
|
129 static int malloc_hysteresis;
|
|
130
|
12529
|
131 /* Nonzero when malloc is called for allocating Lisp object space. */
|
|
132 int allocating_for_lisp;
|
|
133
|
300
|
134 /* Non-nil means defun should do purecopy on the function definition */
|
|
135 Lisp_Object Vpurify_flag;
|
|
136
|
|
137 #ifndef HAVE_SHM
|
8817
|
138 EMACS_INT pure[PURESIZE / sizeof (EMACS_INT)] = {0,}; /* Force it into data space! */
|
300
|
139 #define PUREBEG (char *) pure
|
|
140 #else
|
|
141 #define pure PURE_SEG_BITS /* Use shared memory segment */
|
|
142 #define PUREBEG (char *)PURE_SEG_BITS
|
356
|
143
|
|
144 /* This variable is used only by the XPNTR macro when HAVE_SHM is
|
|
145 defined. If we used the PURESIZE macro directly there, that would
|
|
146 make most of emacs dependent on puresize.h, which we don't want -
|
|
147 you should be able to change that without too much recompilation.
|
|
148 So map_in_data initializes pure_size, and the dependencies work
|
|
149 out. */
|
8817
|
150 EMACS_INT pure_size;
|
300
|
151 #endif /* not HAVE_SHM */
|
|
152
|
|
153 /* Index in pure at which next pure object will be allocated. */
|
|
154 int pureptr;
|
|
155
|
|
156 /* If nonzero, this is a warning delivered by malloc and not yet displayed. */
|
|
157 char *pending_malloc_warning;
|
|
158
|
6116
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
159 /* Pre-computed signal argument for use when memory is exhausted. */
|
6133
|
160 Lisp_Object memory_signal_data;
|
6116
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
161
|
300
|
162 /* Maximum amount of C stack to save when a GC happens. */
|
|
163
|
|
164 #ifndef MAX_SAVE_STACK
|
|
165 #define MAX_SAVE_STACK 16000
|
|
166 #endif
|
|
167
|
10413
|
168 /* Define DONT_COPY_FLAG to be some bit which will always be zero in a
|
|
169 pointer to a Lisp_Object, when that pointer is viewed as an integer.
|
|
170 (On most machines, pointers are even, so we can use the low bit.
|
14036
|
171 Word-addressable architectures may need to override this in the m-file.)
|
10413
|
172 When linking references to small strings through the size field, we
|
|
173 use this slot to hold the bit that would otherwise be interpreted as
|
|
174 the GC mark bit. */
|
10389
|
175 #ifndef DONT_COPY_FLAG
|
10413
|
176 #define DONT_COPY_FLAG 1
|
10389
|
177 #endif /* no DONT_COPY_FLAG */
|
|
178
|
300
|
179 /* Buffer in which we save a copy of the C stack at each GC. */
|
|
180
|
|
181 char *stack_copy;
|
|
182 int stack_copy_size;
|
|
183
|
|
184 /* Non-zero means ignore malloc warnings. Set during initialization. */
|
|
185 int ignore_warnings;
|
1318
|
186
|
13219
|
187 Lisp_Object Qgc_cons_threshold, Qchar_table_extra_slots;
|
11374
|
188
|
11018
|
189 static void mark_object (), mark_buffer (), mark_kboards ();
|
1318
|
190 static void clear_marks (), gc_sweep ();
|
|
191 static void compact_strings ();
|
300
|
192
|
1908
|
193 /* Versions of malloc and realloc that print warnings as memory gets full. */
|
|
194
|
300
|
195 Lisp_Object
|
|
196 malloc_warning_1 (str)
|
|
197 Lisp_Object str;
|
|
198 {
|
|
199 Fprinc (str, Vstandard_output);
|
|
200 write_string ("\nKilling some buffers may delay running out of memory.\n", -1);
|
|
201 write_string ("However, certainly by the time you receive the 95% warning,\n", -1);
|
|
202 write_string ("you should clean up, kill this Emacs, and start a new one.", -1);
|
|
203 return Qnil;
|
|
204 }
|
|
205
|
|
206 /* malloc calls this if it finds we are near exhausting storage */
|
|
207 malloc_warning (str)
|
|
208 char *str;
|
|
209 {
|
|
210 pending_malloc_warning = str;
|
|
211 }
|
|
212
|
|
213 display_malloc_warning ()
|
|
214 {
|
|
215 register Lisp_Object val;
|
|
216
|
|
217 val = build_string (pending_malloc_warning);
|
|
218 pending_malloc_warning = 0;
|
|
219 internal_with_output_to_temp_buffer (" *Danger*", malloc_warning_1, val);
|
|
220 }
|
|
221
|
17345
|
222 #ifdef DOUG_LEA_MALLOC
|
17831
|
223 # define BYTES_USED (mallinfo ().arena)
|
17345
|
224 #else
|
17831
|
225 # define BYTES_USED _bytes_used
|
17345
|
226 #endif
|
|
227
|
300
|
228 /* Called if malloc returns zero */
|
10673
|
229
|
300
|
230 memory_full ()
|
|
231 {
|
10673
|
232 #ifndef SYSTEM_MALLOC
|
17345
|
233 bytes_used_when_full = BYTES_USED;
|
10673
|
234 #endif
|
|
235
|
|
236 /* The first time we get here, free the spare memory. */
|
|
237 if (spare_memory)
|
|
238 {
|
|
239 free (spare_memory);
|
|
240 spare_memory = 0;
|
|
241 }
|
|
242
|
|
243 /* This used to call error, but if we've run out of memory, we could get
|
|
244 infinite recursion trying to build the string. */
|
|
245 while (1)
|
18621
|
246 Fsignal (Qnil, memory_signal_data);
|
10673
|
247 }
|
|
248
|
|
249 /* Called if we can't allocate relocatable space for a buffer. */
|
|
250
|
|
251 void
|
|
252 buffer_memory_full ()
|
|
253 {
|
|
254 /* If buffers use the relocating allocator,
|
|
255 no need to free spare_memory, because we may have plenty of malloc
|
|
256 space left that we could get, and if we don't, the malloc that fails
|
|
257 will itself cause spare_memory to be freed.
|
|
258 If buffers don't use the relocating allocator,
|
|
259 treat this like any other failing malloc. */
|
|
260
|
|
261 #ifndef REL_ALLOC
|
|
262 memory_full ();
|
|
263 #endif
|
|
264
|
6116
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
265 /* This used to call error, but if we've run out of memory, we could get
|
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
266 infinite recursion trying to build the string. */
|
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
267 while (1)
|
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
268 Fsignal (Qerror, memory_signal_data);
|
300
|
269 }
|
|
270
|
2439
|
271 /* like malloc routines but check for no memory and block interrupt input. */
|
300
|
272
|
|
273 long *
|
|
274 xmalloc (size)
|
|
275 int size;
|
|
276 {
|
|
277 register long *val;
|
|
278
|
2439
|
279 BLOCK_INPUT;
|
300
|
280 val = (long *) malloc (size);
|
2439
|
281 UNBLOCK_INPUT;
|
300
|
282
|
|
283 if (!val && size) memory_full ();
|
|
284 return val;
|
|
285 }
|
|
286
|
|
287 long *
|
|
288 xrealloc (block, size)
|
|
289 long *block;
|
|
290 int size;
|
|
291 {
|
|
292 register long *val;
|
|
293
|
2439
|
294 BLOCK_INPUT;
|
590
|
295 /* We must call malloc explicitly when BLOCK is 0, since some
|
|
296 reallocs don't do this. */
|
|
297 if (! block)
|
|
298 val = (long *) malloc (size);
|
600
|
299 else
|
590
|
300 val = (long *) realloc (block, size);
|
2439
|
301 UNBLOCK_INPUT;
|
300
|
302
|
|
303 if (!val && size) memory_full ();
|
|
304 return val;
|
|
305 }
|
2439
|
306
|
|
307 void
|
|
308 xfree (block)
|
|
309 long *block;
|
|
310 {
|
|
311 BLOCK_INPUT;
|
|
312 free (block);
|
|
313 UNBLOCK_INPUT;
|
|
314 }
|
|
315
|
|
316
|
|
317 /* Arranging to disable input signals while we're in malloc.
|
|
318
|
|
319 This only works with GNU malloc. To help out systems which can't
|
|
320 use GNU malloc, all the calls to malloc, realloc, and free
|
|
321 elsewhere in the code should be inside a BLOCK_INPUT/UNBLOCK_INPUT
|
|
322 pairs; unfortunately, we have no idea what C library functions
|
|
323 might call malloc, so we can't really protect them unless you're
|
|
324 using GNU malloc. Fortunately, most of the major operating can use
|
|
325 GNU malloc. */
|
|
326
|
|
327 #ifndef SYSTEM_MALLOC
|
2507
|
328 extern void * (*__malloc_hook) ();
|
|
329 static void * (*old_malloc_hook) ();
|
|
330 extern void * (*__realloc_hook) ();
|
|
331 static void * (*old_realloc_hook) ();
|
|
332 extern void (*__free_hook) ();
|
|
333 static void (*old_free_hook) ();
|
2439
|
334
|
10673
|
335 /* This function is used as the hook for free to call. */
|
|
336
|
2439
|
337 static void
|
|
338 emacs_blocked_free (ptr)
|
|
339 void *ptr;
|
|
340 {
|
|
341 BLOCK_INPUT;
|
|
342 __free_hook = old_free_hook;
|
|
343 free (ptr);
|
10673
|
344 /* If we released our reserve (due to running out of memory),
|
|
345 and we have a fair amount free once again,
|
|
346 try to set aside another reserve in case we run out once more. */
|
|
347 if (spare_memory == 0
|
|
348 /* Verify there is enough space that even with the malloc
|
|
349 hysteresis this call won't run out again.
|
|
350 The code here is correct as long as SPARE_MEMORY
|
|
351 is substantially larger than the block size malloc uses. */
|
|
352 && (bytes_used_when_full
|
17345
|
353 > BYTES_USED + max (malloc_hysteresis, 4) * SPARE_MEMORY))
|
10673
|
354 spare_memory = (char *) malloc (SPARE_MEMORY);
|
|
355
|
2507
|
356 __free_hook = emacs_blocked_free;
|
2439
|
357 UNBLOCK_INPUT;
|
|
358 }
|
|
359
|
10673
|
360 /* If we released our reserve (due to running out of memory),
|
|
361 and we have a fair amount free once again,
|
|
362 try to set aside another reserve in case we run out once more.
|
|
363
|
|
364 This is called when a relocatable block is freed in ralloc.c. */
|
|
365
|
|
366 void
|
|
367 refill_memory_reserve ()
|
|
368 {
|
|
369 if (spare_memory == 0)
|
|
370 spare_memory = (char *) malloc (SPARE_MEMORY);
|
|
371 }
|
|
372
|
|
373 /* This function is the malloc hook that Emacs uses. */
|
|
374
|
2439
|
375 static void *
|
|
376 emacs_blocked_malloc (size)
|
|
377 unsigned size;
|
|
378 {
|
|
379 void *value;
|
|
380
|
|
381 BLOCK_INPUT;
|
|
382 __malloc_hook = old_malloc_hook;
|
17831
|
383 #ifdef DOUG_LEA_MALLOC
|
17345
|
384 mallopt (M_TOP_PAD, malloc_hysteresis * 4096);
|
17831
|
385 #else
|
17345
|
386 __malloc_extra_blocks = malloc_hysteresis;
|
17831
|
387 #endif
|
3581
|
388 value = (void *) malloc (size);
|
2507
|
389 __malloc_hook = emacs_blocked_malloc;
|
2439
|
390 UNBLOCK_INPUT;
|
|
391
|
|
392 return value;
|
|
393 }
|
|
394
|
|
395 static void *
|
|
396 emacs_blocked_realloc (ptr, size)
|
|
397 void *ptr;
|
|
398 unsigned size;
|
|
399 {
|
|
400 void *value;
|
|
401
|
|
402 BLOCK_INPUT;
|
|
403 __realloc_hook = old_realloc_hook;
|
3581
|
404 value = (void *) realloc (ptr, size);
|
2507
|
405 __realloc_hook = emacs_blocked_realloc;
|
2439
|
406 UNBLOCK_INPUT;
|
|
407
|
|
408 return value;
|
|
409 }
|
|
410
|
|
411 void
|
|
412 uninterrupt_malloc ()
|
|
413 {
|
|
414 old_free_hook = __free_hook;
|
2507
|
415 __free_hook = emacs_blocked_free;
|
2439
|
416
|
|
417 old_malloc_hook = __malloc_hook;
|
2507
|
418 __malloc_hook = emacs_blocked_malloc;
|
2439
|
419
|
|
420 old_realloc_hook = __realloc_hook;
|
2507
|
421 __realloc_hook = emacs_blocked_realloc;
|
2439
|
422 }
|
|
423 #endif
|
300
|
424
|
1908
|
425 /* Interval allocation. */
|
|
426
|
1300
|
427 #ifdef USE_TEXT_PROPERTIES
|
|
428 #define INTERVAL_BLOCK_SIZE \
|
|
429 ((1020 - sizeof (struct interval_block *)) / sizeof (struct interval))
|
|
430
|
|
431 struct interval_block
|
|
432 {
|
|
433 struct interval_block *next;
|
|
434 struct interval intervals[INTERVAL_BLOCK_SIZE];
|
|
435 };
|
|
436
|
|
437 struct interval_block *interval_block;
|
|
438 static int interval_block_index;
|
|
439
|
|
440 INTERVAL interval_free_list;
|
|
441
|
|
442 static void
|
|
443 init_intervals ()
|
|
444 {
|
12529
|
445 allocating_for_lisp = 1;
|
1300
|
446 interval_block
|
|
447 = (struct interval_block *) malloc (sizeof (struct interval_block));
|
12529
|
448 allocating_for_lisp = 0;
|
1300
|
449 interval_block->next = 0;
|
13320
|
450 bzero ((char *) interval_block->intervals, sizeof interval_block->intervals);
|
1300
|
451 interval_block_index = 0;
|
|
452 interval_free_list = 0;
|
|
453 }
|
|
454
|
|
455 #define INIT_INTERVALS init_intervals ()
|
|
456
|
|
457 INTERVAL
|
|
458 make_interval ()
|
|
459 {
|
|
460 INTERVAL val;
|
|
461
|
|
462 if (interval_free_list)
|
|
463 {
|
|
464 val = interval_free_list;
|
|
465 interval_free_list = interval_free_list->parent;
|
|
466 }
|
|
467 else
|
|
468 {
|
|
469 if (interval_block_index == INTERVAL_BLOCK_SIZE)
|
|
470 {
|
12529
|
471 register struct interval_block *newi;
|
1300
|
472
|
12529
|
473 allocating_for_lisp = 1;
|
|
474 newi = (struct interval_block *) xmalloc (sizeof (struct interval_block));
|
|
475
|
|
476 allocating_for_lisp = 0;
|
1300
|
477 VALIDATE_LISP_STORAGE (newi, sizeof *newi);
|
|
478 newi->next = interval_block;
|
|
479 interval_block = newi;
|
|
480 interval_block_index = 0;
|
|
481 }
|
|
482 val = &interval_block->intervals[interval_block_index++];
|
|
483 }
|
|
484 consing_since_gc += sizeof (struct interval);
|
12748
|
485 intervals_consed++;
|
1300
|
486 RESET_INTERVAL (val);
|
|
487 return val;
|
|
488 }
|
|
489
|
|
490 static int total_free_intervals, total_intervals;
|
|
491
|
|
492 /* Mark the pointers of one interval. */
|
|
493
|
|
494 static void
|
1957
|
495 mark_interval (i, dummy)
|
1300
|
496 register INTERVAL i;
|
1957
|
497 Lisp_Object dummy;
|
1300
|
498 {
|
|
499 if (XMARKBIT (i->plist))
|
|
500 abort ();
|
|
501 mark_object (&i->plist);
|
|
502 XMARK (i->plist);
|
|
503 }
|
|
504
|
|
505 static void
|
|
506 mark_interval_tree (tree)
|
|
507 register INTERVAL tree;
|
|
508 {
|
4139
|
509 /* No need to test if this tree has been marked already; this
|
|
510 function is always called through the MARK_INTERVAL_TREE macro,
|
|
511 which takes care of that. */
|
|
512
|
|
513 /* XMARK expands to an assignment; the LHS of an assignment can't be
|
|
514 a cast. */
|
|
515 XMARK (* (Lisp_Object *) &tree->parent);
|
1300
|
516
|
1957
|
517 traverse_intervals (tree, 1, 0, mark_interval, Qnil);
|
1300
|
518 }
|
|
519
|
4139
|
520 #define MARK_INTERVAL_TREE(i) \
|
|
521 do { \
|
|
522 if (!NULL_INTERVAL_P (i) \
|
18621
|
523 && ! XMARKBIT (*(Lisp_Object *) &i->parent)) \
|
4139
|
524 mark_interval_tree (i); \
|
|
525 } while (0)
|
1300
|
526
|
1908
|
527 /* The oddity in the call to XUNMARK is necessary because XUNMARK
|
3591
|
528 expands to an assignment to its argument, and most C compilers don't
|
1908
|
529 support casts on the left operand of `='. */
|
|
530 #define UNMARK_BALANCE_INTERVALS(i) \
|
|
531 { \
|
|
532 if (! NULL_INTERVAL_P (i)) \
|
|
533 { \
|
|
534 XUNMARK (* (Lisp_Object *) (&(i)->parent)); \
|
|
535 (i) = balance_intervals (i); \
|
|
536 } \
|
1300
|
537 }
|
|
538
|
|
539 #else /* no interval use */
|
|
540
|
|
541 #define INIT_INTERVALS
|
|
542
|
|
543 #define UNMARK_BALANCE_INTERVALS(i)
|
|
544 #define MARK_INTERVAL_TREE(i)
|
|
545
|
|
546 #endif /* no interval use */
|
|
547
|
1908
|
548 /* Floating point allocation. */
|
|
549
|
300
|
550 #ifdef LISP_FLOAT_TYPE
|
|
551 /* Allocation of float cells, just like conses */
|
|
552 /* We store float cells inside of float_blocks, allocating a new
|
|
553 float_block with malloc whenever necessary. Float cells reclaimed by
|
|
554 GC are put on a free list to be reallocated before allocating
|
|
555 any new float cells from the latest float_block.
|
|
556
|
|
557 Each float_block is just under 1020 bytes long,
|
|
558 since malloc really allocates in units of powers of two
|
|
559 and uses 4 bytes for its own overhead. */
|
|
560
|
|
561 #define FLOAT_BLOCK_SIZE \
|
|
562 ((1020 - sizeof (struct float_block *)) / sizeof (struct Lisp_Float))
|
|
563
|
|
564 struct float_block
|
|
565 {
|
|
566 struct float_block *next;
|
|
567 struct Lisp_Float floats[FLOAT_BLOCK_SIZE];
|
|
568 };
|
|
569
|
|
570 struct float_block *float_block;
|
|
571 int float_block_index;
|
|
572
|
|
573 struct Lisp_Float *float_free_list;
|
|
574
|
|
575 void
|
|
576 init_float ()
|
|
577 {
|
12529
|
578 allocating_for_lisp = 1;
|
300
|
579 float_block = (struct float_block *) malloc (sizeof (struct float_block));
|
12529
|
580 allocating_for_lisp = 0;
|
300
|
581 float_block->next = 0;
|
13320
|
582 bzero ((char *) float_block->floats, sizeof float_block->floats);
|
300
|
583 float_block_index = 0;
|
|
584 float_free_list = 0;
|
|
585 }
|
|
586
|
|
587 /* Explicitly free a float cell. */
|
|
588 free_float (ptr)
|
|
589 struct Lisp_Float *ptr;
|
|
590 {
|
9942
|
591 *(struct Lisp_Float **)&ptr->type = float_free_list;
|
300
|
592 float_free_list = ptr;
|
|
593 }
|
|
594
|
|
595 Lisp_Object
|
|
596 make_float (float_value)
|
|
597 double float_value;
|
|
598 {
|
|
599 register Lisp_Object val;
|
|
600
|
|
601 if (float_free_list)
|
|
602 {
|
9261
|
603 XSETFLOAT (val, float_free_list);
|
9942
|
604 float_free_list = *(struct Lisp_Float **)&float_free_list->type;
|
300
|
605 }
|
|
606 else
|
|
607 {
|
|
608 if (float_block_index == FLOAT_BLOCK_SIZE)
|
|
609 {
|
12529
|
610 register struct float_block *new;
|
|
611
|
|
612 allocating_for_lisp = 1;
|
|
613 new = (struct float_block *) xmalloc (sizeof (struct float_block));
|
|
614 allocating_for_lisp = 0;
|
300
|
615 VALIDATE_LISP_STORAGE (new, sizeof *new);
|
|
616 new->next = float_block;
|
|
617 float_block = new;
|
|
618 float_block_index = 0;
|
|
619 }
|
9261
|
620 XSETFLOAT (val, &float_block->floats[float_block_index++]);
|
300
|
621 }
|
|
622 XFLOAT (val)->data = float_value;
|
9295
|
623 XSETFASTINT (XFLOAT (val)->type, 0); /* bug chasing -wsr */
|
300
|
624 consing_since_gc += sizeof (struct Lisp_Float);
|
12748
|
625 floats_consed++;
|
300
|
626 return val;
|
|
627 }
|
|
628
|
|
629 #endif /* LISP_FLOAT_TYPE */
|
|
630
|
|
631 /* Allocation of cons cells */
|
|
632 /* We store cons cells inside of cons_blocks, allocating a new
|
|
633 cons_block with malloc whenever necessary. Cons cells reclaimed by
|
|
634 GC are put on a free list to be reallocated before allocating
|
|
635 any new cons cells from the latest cons_block.
|
|
636
|
|
637 Each cons_block is just under 1020 bytes long,
|
|
638 since malloc really allocates in units of powers of two
|
|
639 and uses 4 bytes for its own overhead. */
|
|
640
|
|
641 #define CONS_BLOCK_SIZE \
|
|
642 ((1020 - sizeof (struct cons_block *)) / sizeof (struct Lisp_Cons))
|
|
643
|
|
644 struct cons_block
|
|
645 {
|
|
646 struct cons_block *next;
|
|
647 struct Lisp_Cons conses[CONS_BLOCK_SIZE];
|
|
648 };
|
|
649
|
|
650 struct cons_block *cons_block;
|
|
651 int cons_block_index;
|
|
652
|
|
653 struct Lisp_Cons *cons_free_list;
|
|
654
|
|
655 void
|
|
656 init_cons ()
|
|
657 {
|
12529
|
658 allocating_for_lisp = 1;
|
300
|
659 cons_block = (struct cons_block *) malloc (sizeof (struct cons_block));
|
12529
|
660 allocating_for_lisp = 0;
|
300
|
661 cons_block->next = 0;
|
13320
|
662 bzero ((char *) cons_block->conses, sizeof cons_block->conses);
|
300
|
663 cons_block_index = 0;
|
|
664 cons_free_list = 0;
|
|
665 }
|
|
666
|
|
667 /* Explicitly free a cons cell. */
|
|
668 free_cons (ptr)
|
|
669 struct Lisp_Cons *ptr;
|
|
670 {
|
9942
|
671 *(struct Lisp_Cons **)&ptr->car = cons_free_list;
|
300
|
672 cons_free_list = ptr;
|
|
673 }
|
|
674
|
|
675 DEFUN ("cons", Fcons, Scons, 2, 2, 0,
|
|
676 "Create a new cons, give it CAR and CDR as components, and return it.")
|
|
677 (car, cdr)
|
|
678 Lisp_Object car, cdr;
|
|
679 {
|
|
680 register Lisp_Object val;
|
|
681
|
|
682 if (cons_free_list)
|
|
683 {
|
9261
|
684 XSETCONS (val, cons_free_list);
|
9942
|
685 cons_free_list = *(struct Lisp_Cons **)&cons_free_list->car;
|
300
|
686 }
|
|
687 else
|
|
688 {
|
|
689 if (cons_block_index == CONS_BLOCK_SIZE)
|
|
690 {
|
12529
|
691 register struct cons_block *new;
|
|
692 allocating_for_lisp = 1;
|
|
693 new = (struct cons_block *) xmalloc (sizeof (struct cons_block));
|
|
694 allocating_for_lisp = 0;
|
300
|
695 VALIDATE_LISP_STORAGE (new, sizeof *new);
|
|
696 new->next = cons_block;
|
|
697 cons_block = new;
|
|
698 cons_block_index = 0;
|
|
699 }
|
9261
|
700 XSETCONS (val, &cons_block->conses[cons_block_index++]);
|
300
|
701 }
|
|
702 XCONS (val)->car = car;
|
|
703 XCONS (val)->cdr = cdr;
|
|
704 consing_since_gc += sizeof (struct Lisp_Cons);
|
12748
|
705 cons_cells_consed++;
|
300
|
706 return val;
|
|
707 }
|
|
708
|
|
709 DEFUN ("list", Flist, Slist, 0, MANY, 0,
|
|
710 "Return a newly created list with specified arguments as elements.\n\
|
|
711 Any number of arguments, even zero arguments, are allowed.")
|
|
712 (nargs, args)
|
|
713 int nargs;
|
|
714 register Lisp_Object *args;
|
|
715 {
|
13610
|
716 register Lisp_Object val;
|
|
717 val = Qnil;
|
300
|
718
|
13610
|
719 while (nargs > 0)
|
|
720 {
|
|
721 nargs--;
|
|
722 val = Fcons (args[nargs], val);
|
|
723 }
|
300
|
724 return val;
|
|
725 }
|
|
726
|
|
727 DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0,
|
|
728 "Return a newly created list of length LENGTH, with each element being INIT.")
|
|
729 (length, init)
|
|
730 register Lisp_Object length, init;
|
|
731 {
|
|
732 register Lisp_Object val;
|
|
733 register int size;
|
|
734
|
9953
e0672d4cf470
(Fmake_list, Fmake_vector, Fmake_string): Use CHECK_NATNUM instead of its
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
735 CHECK_NATNUM (length, 0);
|
e0672d4cf470
(Fmake_list, Fmake_vector, Fmake_string): Use CHECK_NATNUM instead of its
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
736 size = XFASTINT (length);
|
300
|
737
|
|
738 val = Qnil;
|
|
739 while (size-- > 0)
|
|
740 val = Fcons (init, val);
|
|
741 return val;
|
|
742 }
|
|
743
|
|
744 /* Allocation of vectors */
|
|
745
|
|
746 struct Lisp_Vector *all_vectors;
|
|
747
|
9968
|
748 struct Lisp_Vector *
|
|
749 allocate_vectorlike (len)
|
|
750 EMACS_INT len;
|
|
751 {
|
|
752 struct Lisp_Vector *p;
|
|
753
|
12529
|
754 allocating_for_lisp = 1;
|
17345
|
755 #ifdef DOUG_LEA_MALLOC
|
|
756 /* Prevent mmap'ing the chunk (which is potentially very large). */
|
|
757 mallopt (M_MMAP_MAX, 0);
|
|
758 #endif
|
9968
|
759 p = (struct Lisp_Vector *)xmalloc (sizeof (struct Lisp_Vector)
|
|
760 + (len - 1) * sizeof (Lisp_Object));
|
17345
|
761 #ifdef DOUG_LEA_MALLOC
|
|
762 /* Back to a reasonable maximum of mmap'ed areas. */
|
|
763 mallopt (M_MMAP_MAX, 64);
|
|
764 #endif
|
12529
|
765 allocating_for_lisp = 0;
|
9968
|
766 VALIDATE_LISP_STORAGE (p, 0);
|
|
767 consing_since_gc += (sizeof (struct Lisp_Vector)
|
|
768 + (len - 1) * sizeof (Lisp_Object));
|
12748
|
769 vector_cells_consed += len;
|
9968
|
770
|
|
771 p->next = all_vectors;
|
|
772 all_vectors = p;
|
|
773 return p;
|
|
774 }
|
|
775
|
300
|
776 DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0,
|
|
777 "Return a newly created vector of length LENGTH, with each element being INIT.\n\
|
|
778 See also the function `vector'.")
|
|
779 (length, init)
|
|
780 register Lisp_Object length, init;
|
|
781 {
|
9968
|
782 Lisp_Object vector;
|
|
783 register EMACS_INT sizei;
|
|
784 register int index;
|
300
|
785 register struct Lisp_Vector *p;
|
|
786
|
9953
e0672d4cf470
(Fmake_list, Fmake_vector, Fmake_string): Use CHECK_NATNUM instead of its
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
787 CHECK_NATNUM (length, 0);
|
e0672d4cf470
(Fmake_list, Fmake_vector, Fmake_string): Use CHECK_NATNUM instead of its
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
788 sizei = XFASTINT (length);
|
300
|
789
|
9968
|
790 p = allocate_vectorlike (sizei);
|
300
|
791 p->size = sizei;
|
|
792 for (index = 0; index < sizei; index++)
|
|
793 p->contents[index] = init;
|
|
794
|
9968
|
795 XSETVECTOR (vector, p);
|
300
|
796 return vector;
|
|
797 }
|
|
798
|
13219
|
799 DEFUN ("make-char-table", Fmake_char_table, Smake_char_table, 1, 2, 0,
|
13322
|
800 "Return a newly created char-table, with purpose PURPOSE.\n\
|
13141
|
801 Each element is initialized to INIT, which defaults to nil.\n\
|
16479
|
802 PURPOSE should be a symbol which has a `char-table-extra-slots' property.\n\
|
13219
|
803 The property's value should be an integer between 0 and 10.")
|
|
804 (purpose, init)
|
|
805 register Lisp_Object purpose, init;
|
13141
|
806 {
|
|
807 Lisp_Object vector;
|
13219
|
808 Lisp_Object n;
|
|
809 CHECK_SYMBOL (purpose, 1);
|
17328
|
810 n = Fget (purpose, Qchar_table_extra_slots);
|
13219
|
811 CHECK_NUMBER (n, 0);
|
13141
|
812 if (XINT (n) < 0 || XINT (n) > 10)
|
|
813 args_out_of_range (n, Qnil);
|
|
814 /* Add 2 to the size for the defalt and parent slots. */
|
|
815 vector = Fmake_vector (make_number (CHAR_TABLE_STANDARD_SLOTS + XINT (n)),
|
|
816 init);
|
17328
|
817 XCHAR_TABLE (vector)->top = Qt;
|
13150
|
818 XCHAR_TABLE (vector)->parent = Qnil;
|
13219
|
819 XCHAR_TABLE (vector)->purpose = purpose;
|
13141
|
820 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector));
|
|
821 return vector;
|
|
822 }
|
|
823
|
17328
|
824 /* Return a newly created sub char table with default value DEFALT.
|
|
825 Since a sub char table does not appear as a top level Emacs Lisp
|
|
826 object, we don't need a Lisp interface to make it. */
|
|
827
|
|
828 Lisp_Object
|
|
829 make_sub_char_table (defalt)
|
|
830 Lisp_Object defalt;
|
|
831 {
|
|
832 Lisp_Object vector
|
|
833 = Fmake_vector (make_number (SUB_CHAR_TABLE_STANDARD_SLOTS), Qnil);
|
|
834 XCHAR_TABLE (vector)->top = Qnil;
|
|
835 XCHAR_TABLE (vector)->defalt = defalt;
|
|
836 XSETCHAR_TABLE (vector, XCHAR_TABLE (vector));
|
|
837 return vector;
|
|
838 }
|
|
839
|
300
|
840 DEFUN ("vector", Fvector, Svector, 0, MANY, 0,
|
|
841 "Return a newly created vector with specified arguments as elements.\n\
|
|
842 Any number of arguments, even zero arguments, are allowed.")
|
|
843 (nargs, args)
|
|
844 register int nargs;
|
|
845 Lisp_Object *args;
|
|
846 {
|
|
847 register Lisp_Object len, val;
|
|
848 register int index;
|
|
849 register struct Lisp_Vector *p;
|
|
850
|
9295
|
851 XSETFASTINT (len, nargs);
|
300
|
852 val = Fmake_vector (len, Qnil);
|
|
853 p = XVECTOR (val);
|
|
854 for (index = 0; index < nargs; index++)
|
|
855 p->contents[index] = args[index];
|
|
856 return val;
|
|
857 }
|
|
858
|
|
859 DEFUN ("make-byte-code", Fmake_byte_code, Smake_byte_code, 4, MANY, 0,
|
|
860 "Create a byte-code object with specified arguments as elements.\n\
|
|
861 The arguments should be the arglist, bytecode-string, constant vector,\n\
|
|
862 stack size, (optional) doc string, and (optional) interactive spec.\n\
|
|
863 The first four arguments are required; at most six have any\n\
|
|
864 significance.")
|
|
865 (nargs, args)
|
|
866 register int nargs;
|
|
867 Lisp_Object *args;
|
|
868 {
|
|
869 register Lisp_Object len, val;
|
|
870 register int index;
|
|
871 register struct Lisp_Vector *p;
|
|
872
|
9295
|
873 XSETFASTINT (len, nargs);
|
485
|
874 if (!NILP (Vpurify_flag))
|
16101
|
875 val = make_pure_vector ((EMACS_INT) nargs);
|
300
|
876 else
|
|
877 val = Fmake_vector (len, Qnil);
|
|
878 p = XVECTOR (val);
|
|
879 for (index = 0; index < nargs; index++)
|
|
880 {
|
485
|
881 if (!NILP (Vpurify_flag))
|
300
|
882 args[index] = Fpurecopy (args[index]);
|
|
883 p->contents[index] = args[index];
|
|
884 }
|
18104
|
885 XSETCOMPILED (val, p);
|
300
|
886 return val;
|
|
887 }
|
|
888
|
|
889 /* Allocation of symbols.
|
|
890 Just like allocation of conses!
|
|
891
|
|
892 Each symbol_block is just under 1020 bytes long,
|
|
893 since malloc really allocates in units of powers of two
|
|
894 and uses 4 bytes for its own overhead. */
|
|
895
|
|
896 #define SYMBOL_BLOCK_SIZE \
|
|
897 ((1020 - sizeof (struct symbol_block *)) / sizeof (struct Lisp_Symbol))
|
|
898
|
|
899 struct symbol_block
|
|
900 {
|
|
901 struct symbol_block *next;
|
|
902 struct Lisp_Symbol symbols[SYMBOL_BLOCK_SIZE];
|
|
903 };
|
|
904
|
|
905 struct symbol_block *symbol_block;
|
|
906 int symbol_block_index;
|
|
907
|
|
908 struct Lisp_Symbol *symbol_free_list;
|
|
909
|
|
910 void
|
|
911 init_symbol ()
|
|
912 {
|
12529
|
913 allocating_for_lisp = 1;
|
300
|
914 symbol_block = (struct symbol_block *) malloc (sizeof (struct symbol_block));
|
12529
|
915 allocating_for_lisp = 0;
|
300
|
916 symbol_block->next = 0;
|
13320
|
917 bzero ((char *) symbol_block->symbols, sizeof symbol_block->symbols);
|
300
|
918 symbol_block_index = 0;
|
|
919 symbol_free_list = 0;
|
|
920 }
|
|
921
|
|
922 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0,
|
|
923 "Return a newly allocated uninterned symbol whose name is NAME.\n\
|
|
924 Its value and function definition are void, and its property list is nil.")
|
14093
|
925 (name)
|
|
926 Lisp_Object name;
|
300
|
927 {
|
|
928 register Lisp_Object val;
|
|
929 register struct Lisp_Symbol *p;
|
|
930
|
14093
|
931 CHECK_STRING (name, 0);
|
300
|
932
|
|
933 if (symbol_free_list)
|
|
934 {
|
9261
|
935 XSETSYMBOL (val, symbol_free_list);
|
9942
|
936 symbol_free_list = *(struct Lisp_Symbol **)&symbol_free_list->value;
|
300
|
937 }
|
|
938 else
|
|
939 {
|
|
940 if (symbol_block_index == SYMBOL_BLOCK_SIZE)
|
|
941 {
|
12529
|
942 struct symbol_block *new;
|
|
943 allocating_for_lisp = 1;
|
|
944 new = (struct symbol_block *) xmalloc (sizeof (struct symbol_block));
|
|
945 allocating_for_lisp = 0;
|
300
|
946 VALIDATE_LISP_STORAGE (new, sizeof *new);
|
|
947 new->next = symbol_block;
|
|
948 symbol_block = new;
|
|
949 symbol_block_index = 0;
|
|
950 }
|
9261
|
951 XSETSYMBOL (val, &symbol_block->symbols[symbol_block_index++]);
|
300
|
952 }
|
|
953 p = XSYMBOL (val);
|
14095
|
954 p->name = XSTRING (name);
|
16223
|
955 p->obarray = Qnil;
|
300
|
956 p->plist = Qnil;
|
|
957 p->value = Qunbound;
|
|
958 p->function = Qunbound;
|
|
959 p->next = 0;
|
|
960 consing_since_gc += sizeof (struct Lisp_Symbol);
|
12748
|
961 symbols_consed++;
|
300
|
962 return val;
|
|
963 }
|
|
964
|
9437
|
965 /* Allocation of markers and other objects that share that structure.
|
300
|
966 Works like allocation of conses. */
|
|
967
|
|
968 #define MARKER_BLOCK_SIZE \
|
9437
|
969 ((1020 - sizeof (struct marker_block *)) / sizeof (union Lisp_Misc))
|
300
|
970
|
|
971 struct marker_block
|
|
972 {
|
|
973 struct marker_block *next;
|
9437
|
974 union Lisp_Misc markers[MARKER_BLOCK_SIZE];
|
300
|
975 };
|
|
976
|
|
977 struct marker_block *marker_block;
|
|
978 int marker_block_index;
|
|
979
|
9437
|
980 union Lisp_Misc *marker_free_list;
|
300
|
981
|
|
982 void
|
|
983 init_marker ()
|
|
984 {
|
12529
|
985 allocating_for_lisp = 1;
|
300
|
986 marker_block = (struct marker_block *) malloc (sizeof (struct marker_block));
|
12529
|
987 allocating_for_lisp = 0;
|
300
|
988 marker_block->next = 0;
|
13320
|
989 bzero ((char *) marker_block->markers, sizeof marker_block->markers);
|
300
|
990 marker_block_index = 0;
|
|
991 marker_free_list = 0;
|
|
992 }
|
|
993
|
9437
|
994 /* Return a newly allocated Lisp_Misc object, with no substructure. */
|
|
995 Lisp_Object
|
|
996 allocate_misc ()
|
|
997 {
|
|
998 Lisp_Object val;
|
|
999
|
|
1000 if (marker_free_list)
|
|
1001 {
|
|
1002 XSETMISC (val, marker_free_list);
|
|
1003 marker_free_list = marker_free_list->u_free.chain;
|
|
1004 }
|
|
1005 else
|
|
1006 {
|
|
1007 if (marker_block_index == MARKER_BLOCK_SIZE)
|
|
1008 {
|
12529
|
1009 struct marker_block *new;
|
|
1010 allocating_for_lisp = 1;
|
|
1011 new = (struct marker_block *) xmalloc (sizeof (struct marker_block));
|
|
1012 allocating_for_lisp = 0;
|
9437
|
1013 VALIDATE_LISP_STORAGE (new, sizeof *new);
|
|
1014 new->next = marker_block;
|
|
1015 marker_block = new;
|
|
1016 marker_block_index = 0;
|
|
1017 }
|
|
1018 XSETMISC (val, &marker_block->markers[marker_block_index++]);
|
|
1019 }
|
|
1020 consing_since_gc += sizeof (union Lisp_Misc);
|
12748
|
1021 misc_objects_consed++;
|
9437
|
1022 return val;
|
|
1023 }
|
|
1024
|
300
|
1025 DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0,
|
|
1026 "Return a newly allocated marker which does not point at any place.")
|
|
1027 ()
|
|
1028 {
|
|
1029 register Lisp_Object val;
|
|
1030 register struct Lisp_Marker *p;
|
638
|
1031
|
9437
|
1032 val = allocate_misc ();
|
11243
|
1033 XMISCTYPE (val) = Lisp_Misc_Marker;
|
300
|
1034 p = XMARKER (val);
|
|
1035 p->buffer = 0;
|
|
1036 p->bufpos = 0;
|
|
1037 p->chain = Qnil;
|
13008
|
1038 p->insertion_type = 0;
|
300
|
1039 return val;
|
|
1040 }
|
19332
|
1041
|
|
1042 /* Put MARKER back on the free list after using it temporarily. */
|
|
1043
|
|
1044 free_marker (marker)
|
|
1045 Lisp_Object marker;
|
|
1046 {
|
|
1047 XMISC (marker)->u_marker.type = Lisp_Misc_Free;
|
|
1048 XMISC (marker)->u_free.chain = marker_free_list;
|
|
1049 marker_free_list = XMISC (marker);
|
|
1050
|
|
1051 total_free_markers++;
|
|
1052 }
|
300
|
1053
|
|
1054 /* Allocation of strings */
|
|
1055
|
|
1056 /* Strings reside inside of string_blocks. The entire data of the string,
|
|
1057 both the size and the contents, live in part of the `chars' component of a string_block.
|
|
1058 The `pos' component is the index within `chars' of the first free byte.
|
|
1059
|
|
1060 first_string_block points to the first string_block ever allocated.
|
|
1061 Each block points to the next one with its `next' field.
|
|
1062 The `prev' fields chain in reverse order.
|
|
1063 The last one allocated is the one currently being filled.
|
|
1064 current_string_block points to it.
|
|
1065
|
|
1066 The string_blocks that hold individual large strings
|
|
1067 go in a separate chain, started by large_string_blocks. */
|
|
1068
|
|
1069
|
|
1070 /* String blocks contain this many useful bytes.
|
|
1071 8188 is power of 2, minus 4 for malloc overhead. */
|
|
1072 #define STRING_BLOCK_SIZE (8188 - sizeof (struct string_block_head))
|
|
1073
|
|
1074 /* A string bigger than this gets its own specially-made string block
|
|
1075 if it doesn't fit in the current one. */
|
|
1076 #define STRING_BLOCK_OUTSIZE 1024
|
|
1077
|
|
1078 struct string_block_head
|
|
1079 {
|
|
1080 struct string_block *next, *prev;
|
14764
|
1081 EMACS_INT pos;
|
300
|
1082 };
|
|
1083
|
|
1084 struct string_block
|
|
1085 {
|
|
1086 struct string_block *next, *prev;
|
8817
|
1087 EMACS_INT pos;
|
300
|
1088 char chars[STRING_BLOCK_SIZE];
|
|
1089 };
|
|
1090
|
|
1091 /* This points to the string block we are now allocating strings. */
|
|
1092
|
|
1093 struct string_block *current_string_block;
|
|
1094
|
|
1095 /* This points to the oldest string block, the one that starts the chain. */
|
|
1096
|
|
1097 struct string_block *first_string_block;
|
|
1098
|
|
1099 /* Last string block in chain of those made for individual large strings. */
|
|
1100
|
|
1101 struct string_block *large_string_blocks;
|
|
1102
|
|
1103 /* If SIZE is the length of a string, this returns how many bytes
|
|
1104 the string occupies in a string_block (including padding). */
|
|
1105
|
|
1106 #define STRING_FULLSIZE(size) (((size) + sizeof (struct Lisp_String) + PAD) \
|
|
1107 & ~(PAD - 1))
|
8817
|
1108 #define PAD (sizeof (EMACS_INT))
|
300
|
1109
|
|
1110 #if 0
|
|
1111 #define STRING_FULLSIZE(SIZE) \
|
8817
|
1112 (((SIZE) + 2 * sizeof (EMACS_INT)) & ~(sizeof (EMACS_INT) - 1))
|
300
|
1113 #endif
|
|
1114
|
|
1115 void
|
|
1116 init_strings ()
|
|
1117 {
|
12529
|
1118 allocating_for_lisp = 1;
|
300
|
1119 current_string_block = (struct string_block *) malloc (sizeof (struct string_block));
|
12529
|
1120 allocating_for_lisp = 0;
|
300
|
1121 first_string_block = current_string_block;
|
|
1122 consing_since_gc += sizeof (struct string_block);
|
|
1123 current_string_block->next = 0;
|
|
1124 current_string_block->prev = 0;
|
|
1125 current_string_block->pos = 0;
|
|
1126 large_string_blocks = 0;
|
|
1127 }
|
|
1128
|
|
1129 DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0,
|
|
1130 "Return a newly created string of length LENGTH, with each element being INIT.\n\
|
|
1131 Both LENGTH and INIT must be numbers.")
|
|
1132 (length, init)
|
|
1133 Lisp_Object length, init;
|
|
1134 {
|
|
1135 register Lisp_Object val;
|
|
1136 register unsigned char *p, *end, c;
|
|
1137
|
9953
e0672d4cf470
(Fmake_list, Fmake_vector, Fmake_string): Use CHECK_NATNUM instead of its
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1138 CHECK_NATNUM (length, 0);
|
300
|
1139 CHECK_NUMBER (init, 1);
|
9953
e0672d4cf470
(Fmake_list, Fmake_vector, Fmake_string): Use CHECK_NATNUM instead of its
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1140 val = make_uninit_string (XFASTINT (length));
|
300
|
1141 c = XINT (init);
|
|
1142 p = XSTRING (val)->data;
|
|
1143 end = p + XSTRING (val)->size;
|
|
1144 while (p != end)
|
|
1145 *p++ = c;
|
|
1146 *p = 0;
|
|
1147 return val;
|
|
1148 }
|
|
1149
|
13141
|
1150 DEFUN ("make-bool-vector", Fmake_bool_vector, Smake_bool_vector, 2, 2, 0,
|
18010
|
1151 "Return a new bool-vector of length LENGTH, using INIT for as each element.\n\
|
|
1152 LENGTH must be a number. INIT matters only in whether it is t or nil.")
|
13141
|
1153 (length, init)
|
|
1154 Lisp_Object length, init;
|
|
1155 {
|
|
1156 register Lisp_Object val;
|
|
1157 struct Lisp_Bool_Vector *p;
|
|
1158 int real_init, i;
|
|
1159 int length_in_chars, length_in_elts, bits_per_value;
|
|
1160
|
|
1161 CHECK_NATNUM (length, 0);
|
|
1162
|
13363
|
1163 bits_per_value = sizeof (EMACS_INT) * BITS_PER_CHAR;
|
13141
|
1164
|
|
1165 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value;
|
|
1166 length_in_chars = length_in_elts * sizeof (EMACS_INT);
|
|
1167
|
17021
|
1168 /* We must allocate one more elements than LENGTH_IN_ELTS for the
|
|
1169 slot `size' of the struct Lisp_Bool_Vector. */
|
|
1170 val = Fmake_vector (make_number (length_in_elts + 1), Qnil);
|
13141
|
1171 p = XBOOL_VECTOR (val);
|
|
1172 /* Get rid of any bits that would cause confusion. */
|
|
1173 p->vector_size = 0;
|
|
1174 XSETBOOL_VECTOR (val, p);
|
|
1175 p->size = XFASTINT (length);
|
|
1176
|
|
1177 real_init = (NILP (init) ? 0 : -1);
|
|
1178 for (i = 0; i < length_in_chars ; i++)
|
|
1179 p->data[i] = real_init;
|
|
1180
|
|
1181 return val;
|
|
1182 }
|
|
1183
|
300
|
1184 Lisp_Object
|
|
1185 make_string (contents, length)
|
|
1186 char *contents;
|
|
1187 int length;
|
|
1188 {
|
|
1189 register Lisp_Object val;
|
|
1190 val = make_uninit_string (length);
|
|
1191 bcopy (contents, XSTRING (val)->data, length);
|
|
1192 return val;
|
|
1193 }
|
|
1194
|
|
1195 Lisp_Object
|
|
1196 build_string (str)
|
|
1197 char *str;
|
|
1198 {
|
|
1199 return make_string (str, strlen (str));
|
|
1200 }
|
|
1201
|
|
1202 Lisp_Object
|
|
1203 make_uninit_string (length)
|
|
1204 int length;
|
|
1205 {
|
|
1206 register Lisp_Object val;
|
|
1207 register int fullsize = STRING_FULLSIZE (length);
|
|
1208
|
|
1209 if (length < 0) abort ();
|
|
1210
|
|
1211 if (fullsize <= STRING_BLOCK_SIZE - current_string_block->pos)
|
|
1212 /* This string can fit in the current string block */
|
|
1213 {
|
9261
|
1214 XSETSTRING (val,
|
|
1215 ((struct Lisp_String *)
|
|
1216 (current_string_block->chars + current_string_block->pos)));
|
300
|
1217 current_string_block->pos += fullsize;
|
|
1218 }
|
|
1219 else if (fullsize > STRING_BLOCK_OUTSIZE)
|
|
1220 /* This string gets its own string block */
|
|
1221 {
|
12529
|
1222 register struct string_block *new;
|
|
1223 allocating_for_lisp = 1;
|
17345
|
1224 #ifdef DOUG_LEA_MALLOC
|
|
1225 /* Prevent mmap'ing the chunk (which is potentially very large). */
|
|
1226 mallopt (M_MMAP_MAX, 0);
|
|
1227 #endif
|
12529
|
1228 new = (struct string_block *) xmalloc (sizeof (struct string_block_head) + fullsize);
|
17345
|
1229 #ifdef DOUG_LEA_MALLOC
|
|
1230 /* Back to a reasonable maximum of mmap'ed areas. */
|
|
1231 mallopt (M_MMAP_MAX, 64);
|
|
1232 #endif
|
12529
|
1233 allocating_for_lisp = 0;
|
300
|
1234 VALIDATE_LISP_STORAGE (new, 0);
|
|
1235 consing_since_gc += sizeof (struct string_block_head) + fullsize;
|
|
1236 new->pos = fullsize;
|
|
1237 new->next = large_string_blocks;
|
|
1238 large_string_blocks = new;
|
9261
|
1239 XSETSTRING (val,
|
|
1240 ((struct Lisp_String *)
|
|
1241 ((struct string_block_head *)new + 1)));
|
300
|
1242 }
|
|
1243 else
|
|
1244 /* Make a new current string block and start it off with this string */
|
|
1245 {
|
12529
|
1246 register struct string_block *new;
|
|
1247 allocating_for_lisp = 1;
|
|
1248 new = (struct string_block *) xmalloc (sizeof (struct string_block));
|
|
1249 allocating_for_lisp = 0;
|
300
|
1250 VALIDATE_LISP_STORAGE (new, sizeof *new);
|
|
1251 consing_since_gc += sizeof (struct string_block);
|
|
1252 current_string_block->next = new;
|
|
1253 new->prev = current_string_block;
|
|
1254 new->next = 0;
|
|
1255 current_string_block = new;
|
|
1256 new->pos = fullsize;
|
9261
|
1257 XSETSTRING (val,
|
|
1258 (struct Lisp_String *) current_string_block->chars);
|
300
|
1259 }
|
|
1260
|
12748
|
1261 string_chars_consed += fullsize;
|
300
|
1262 XSTRING (val)->size = length;
|
|
1263 XSTRING (val)->data[length] = 0;
|
1300
|
1264 INITIALIZE_INTERVAL (XSTRING (val), NULL_INTERVAL);
|
300
|
1265
|
|
1266 return val;
|
|
1267 }
|
|
1268
|
|
1269 /* Return a newly created vector or string with specified arguments as
|
2013
|
1270 elements. If all the arguments are characters that can fit
|
|
1271 in a string of events, make a string; otherwise, make a vector.
|
|
1272
|
|
1273 Any number of arguments, even zero arguments, are allowed. */
|
300
|
1274
|
|
1275 Lisp_Object
|
2013
|
1276 make_event_array (nargs, args)
|
300
|
1277 register int nargs;
|
|
1278 Lisp_Object *args;
|
|
1279 {
|
|
1280 int i;
|
|
1281
|
|
1282 for (i = 0; i < nargs; i++)
|
2013
|
1283 /* The things that fit in a string
|
3536
|
1284 are characters that are in 0...127,
|
|
1285 after discarding the meta bit and all the bits above it. */
|
9144
0e29f6a4fe7c
(Fmake_list, Fmake_vector, Fmake_string, make_event_array): Use type test
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1286 if (!INTEGERP (args[i])
|
3536
|
1287 || (XUINT (args[i]) & ~(-CHAR_META)) >= 0200)
|
300
|
1288 return Fvector (nargs, args);
|
|
1289
|
|
1290 /* Since the loop exited, we know that all the things in it are
|
|
1291 characters, so we can make a string. */
|
|
1292 {
|
6492
|
1293 Lisp_Object result;
|
300
|
1294
|
18104
|
1295 result = Fmake_string (make_number (nargs), make_number (0));
|
300
|
1296 for (i = 0; i < nargs; i++)
|
2013
|
1297 {
|
|
1298 XSTRING (result)->data[i] = XINT (args[i]);
|
|
1299 /* Move the meta bit to the right place for a string char. */
|
|
1300 if (XINT (args[i]) & CHAR_META)
|
|
1301 XSTRING (result)->data[i] |= 0x80;
|
|
1302 }
|
300
|
1303
|
|
1304 return result;
|
|
1305 }
|
|
1306 }
|
|
1307
|
1908
|
1308 /* Pure storage management. */
|
|
1309
|
300
|
1310 /* Must get an error if pure storage is full,
|
|
1311 since if it cannot hold a large string
|
|
1312 it may be able to hold conses that point to that string;
|
|
1313 then the string is not protected from gc. */
|
|
1314
|
|
1315 Lisp_Object
|
|
1316 make_pure_string (data, length)
|
|
1317 char *data;
|
|
1318 int length;
|
|
1319 {
|
|
1320 register Lisp_Object new;
|
8817
|
1321 register int size = sizeof (EMACS_INT) + INTERVAL_PTR_SIZE + length + 1;
|
300
|
1322
|
|
1323 if (pureptr + size > PURESIZE)
|
|
1324 error ("Pure Lisp storage exhausted");
|
9261
|
1325 XSETSTRING (new, PUREBEG + pureptr);
|
300
|
1326 XSTRING (new)->size = length;
|
|
1327 bcopy (data, XSTRING (new)->data, length);
|
|
1328 XSTRING (new)->data[length] = 0;
|
4956
|
1329
|
|
1330 /* We must give strings in pure storage some kind of interval. So we
|
|
1331 give them a null one. */
|
|
1332 #if defined (USE_TEXT_PROPERTIES)
|
|
1333 XSTRING (new)->intervals = NULL_INTERVAL;
|
|
1334 #endif
|
8817
|
1335 pureptr += (size + sizeof (EMACS_INT) - 1)
|
|
1336 / sizeof (EMACS_INT) * sizeof (EMACS_INT);
|
300
|
1337 return new;
|
|
1338 }
|
|
1339
|
|
1340 Lisp_Object
|
|
1341 pure_cons (car, cdr)
|
|
1342 Lisp_Object car, cdr;
|
|
1343 {
|
|
1344 register Lisp_Object new;
|
|
1345
|
|
1346 if (pureptr + sizeof (struct Lisp_Cons) > PURESIZE)
|
|
1347 error ("Pure Lisp storage exhausted");
|
9261
|
1348 XSETCONS (new, PUREBEG + pureptr);
|
300
|
1349 pureptr += sizeof (struct Lisp_Cons);
|
|
1350 XCONS (new)->car = Fpurecopy (car);
|
|
1351 XCONS (new)->cdr = Fpurecopy (cdr);
|
|
1352 return new;
|
|
1353 }
|
|
1354
|
|
1355 #ifdef LISP_FLOAT_TYPE
|
|
1356
|
|
1357 Lisp_Object
|
|
1358 make_pure_float (num)
|
|
1359 double num;
|
|
1360 {
|
|
1361 register Lisp_Object new;
|
|
1362
|
1939
|
1363 /* Make sure that PUREBEG + pureptr is aligned on at least a sizeof
|
|
1364 (double) boundary. Some architectures (like the sparc) require
|
|
1365 this, and I suspect that floats are rare enough that it's no
|
|
1366 tragedy for those that do. */
|
|
1367 {
|
|
1368 int alignment;
|
|
1369 char *p = PUREBEG + pureptr;
|
|
1370
|
1936
|
1371 #ifdef __GNUC__
|
|
1372 #if __GNUC__ >= 2
|
1939
|
1373 alignment = __alignof (struct Lisp_Float);
|
1936
|
1374 #else
|
1939
|
1375 alignment = sizeof (struct Lisp_Float);
|
1936
|
1376 #endif
|
|
1377 #else
|
1939
|
1378 alignment = sizeof (struct Lisp_Float);
|
1936
|
1379 #endif
|
1939
|
1380 p = (char *) (((unsigned long) p + alignment - 1) & - alignment);
|
|
1381 pureptr = p - PUREBEG;
|
|
1382 }
|
1908
|
1383
|
300
|
1384 if (pureptr + sizeof (struct Lisp_Float) > PURESIZE)
|
|
1385 error ("Pure Lisp storage exhausted");
|
9261
|
1386 XSETFLOAT (new, PUREBEG + pureptr);
|
300
|
1387 pureptr += sizeof (struct Lisp_Float);
|
|
1388 XFLOAT (new)->data = num;
|
9295
|
1389 XSETFASTINT (XFLOAT (new)->type, 0); /* bug chasing -wsr */
|
300
|
1390 return new;
|
|
1391 }
|
|
1392
|
|
1393 #endif /* LISP_FLOAT_TYPE */
|
|
1394
|
|
1395 Lisp_Object
|
|
1396 make_pure_vector (len)
|
8817
|
1397 EMACS_INT len;
|
300
|
1398 {
|
|
1399 register Lisp_Object new;
|
8817
|
1400 register EMACS_INT size = sizeof (struct Lisp_Vector) + (len - 1) * sizeof (Lisp_Object);
|
300
|
1401
|
|
1402 if (pureptr + size > PURESIZE)
|
|
1403 error ("Pure Lisp storage exhausted");
|
|
1404
|
9261
|
1405 XSETVECTOR (new, PUREBEG + pureptr);
|
300
|
1406 pureptr += size;
|
|
1407 XVECTOR (new)->size = len;
|
|
1408 return new;
|
|
1409 }
|
|
1410
|
|
1411 DEFUN ("purecopy", Fpurecopy, Spurecopy, 1, 1, 0,
|
|
1412 "Make a copy of OBJECT in pure storage.\n\
|
|
1413 Recursively copies contents of vectors and cons cells.\n\
|
|
1414 Does not copy symbols.")
|
|
1415 (obj)
|
|
1416 register Lisp_Object obj;
|
|
1417 {
|
485
|
1418 if (NILP (Vpurify_flag))
|
300
|
1419 return obj;
|
|
1420
|
|
1421 if ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) ((char *) pure + PURESIZE)
|
|
1422 && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure)
|
|
1423 return obj;
|
|
1424
|
10004
|
1425 if (CONSP (obj))
|
|
1426 return pure_cons (XCONS (obj)->car, XCONS (obj)->cdr);
|
300
|
1427 #ifdef LISP_FLOAT_TYPE
|
10004
|
1428 else if (FLOATP (obj))
|
|
1429 return make_pure_float (XFLOAT (obj)->data);
|
300
|
1430 #endif /* LISP_FLOAT_TYPE */
|
10004
|
1431 else if (STRINGP (obj))
|
|
1432 return make_pure_string (XSTRING (obj)->data, XSTRING (obj)->size);
|
|
1433 else if (COMPILEDP (obj) || VECTORP (obj))
|
|
1434 {
|
|
1435 register struct Lisp_Vector *vec;
|
|
1436 register int i, size;
|
300
|
1437
|
10004
|
1438 size = XVECTOR (obj)->size;
|
10427
|
1439 if (size & PSEUDOVECTOR_FLAG)
|
|
1440 size &= PSEUDOVECTOR_SIZE_MASK;
|
16100
|
1441 vec = XVECTOR (make_pure_vector ((EMACS_INT) size));
|
10004
|
1442 for (i = 0; i < size; i++)
|
|
1443 vec->contents[i] = Fpurecopy (XVECTOR (obj)->contents[i]);
|
|
1444 if (COMPILEDP (obj))
|
|
1445 XSETCOMPILED (obj, vec);
|
|
1446 else
|
|
1447 XSETVECTOR (obj, vec);
|
300
|
1448 return obj;
|
|
1449 }
|
10004
|
1450 else if (MARKERP (obj))
|
|
1451 error ("Attempt to copy a marker to pure storage");
|
|
1452 else
|
|
1453 return obj;
|
300
|
1454 }
|
|
1455
|
|
1456 /* Recording what needs to be marked for gc. */
|
|
1457
|
|
1458 struct gcpro *gcprolist;
|
|
1459
|
10855
|
1460 #define NSTATICS 768
|
300
|
1461
|
|
1462 Lisp_Object *staticvec[NSTATICS] = {0};
|
|
1463
|
|
1464 int staticidx = 0;
|
|
1465
|
|
1466 /* Put an entry in staticvec, pointing at the variable whose address is given */
|
|
1467
|
|
1468 void
|
|
1469 staticpro (varaddress)
|
|
1470 Lisp_Object *varaddress;
|
|
1471 {
|
|
1472 staticvec[staticidx++] = varaddress;
|
|
1473 if (staticidx >= NSTATICS)
|
|
1474 abort ();
|
|
1475 }
|
|
1476
|
|
1477 struct catchtag
|
|
1478 {
|
|
1479 Lisp_Object tag;
|
|
1480 Lisp_Object val;
|
|
1481 struct catchtag *next;
|
|
1482 /* jmp_buf jmp; /* We don't need this for GC purposes */
|
|
1483 };
|
|
1484
|
|
1485 struct backtrace
|
|
1486 {
|
|
1487 struct backtrace *next;
|
|
1488 Lisp_Object *function;
|
|
1489 Lisp_Object *args; /* Points to vector of args. */
|
|
1490 int nargs; /* length of vector */
|
|
1491 /* if nargs is UNEVALLED, args points to slot holding list of unevalled args */
|
|
1492 char evalargs;
|
|
1493 };
|
|
1494
|
1908
|
1495 /* Garbage collection! */
|
|
1496
|
11374
|
1497 /* Temporarily prevent garbage collection. */
|
|
1498
|
|
1499 int
|
|
1500 inhibit_garbage_collection ()
|
|
1501 {
|
|
1502 int count = specpdl_ptr - specpdl;
|
11679
|
1503 Lisp_Object number;
|
13363
|
1504 int nbits = min (VALBITS, BITS_PER_INT);
|
11374
|
1505
|
11727
|
1506 XSETINT (number, ((EMACS_INT) 1 << (nbits - 1)) - 1);
|
11679
|
1507
|
|
1508 specbind (Qgc_cons_threshold, number);
|
11374
|
1509
|
|
1510 return count;
|
|
1511 }
|
|
1512
|
300
|
1513 DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "",
|
|
1514 "Reclaim storage for Lisp objects no longer needed.\n\
|
|
1515 Returns info on amount of space in use:\n\
|
|
1516 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)\n\
|
|
1517 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS\n\
|
16001
|
1518 (USED-FLOATS . FREE-FLOATS) (USED-INTERVALS . FREE-INTERVALS))\n\
|
300
|
1519 Garbage collection happens automatically if you cons more than\n\
|
|
1520 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.")
|
|
1521 ()
|
|
1522 {
|
|
1523 register struct gcpro *tail;
|
|
1524 register struct specbinding *bind;
|
|
1525 struct catchtag *catch;
|
|
1526 struct handler *handler;
|
|
1527 register struct backtrace *backlist;
|
|
1528 register Lisp_Object tem;
|
|
1529 char *omessage = echo_area_glyphs;
|
5874
|
1530 int omessage_length = echo_area_glyphs_length;
|
300
|
1531 char stack_top_variable;
|
|
1532 register int i;
|
|
1533
|
11892
|
1534 /* In case user calls debug_print during GC,
|
|
1535 don't let that cause a recursive GC. */
|
|
1536 consing_since_gc = 0;
|
|
1537
|
300
|
1538 /* Save a copy of the contents of the stack, for debugging. */
|
|
1539 #if MAX_SAVE_STACK > 0
|
485
|
1540 if (NILP (Vpurify_flag))
|
300
|
1541 {
|
|
1542 i = &stack_top_variable - stack_bottom;
|
|
1543 if (i < 0) i = -i;
|
|
1544 if (i < MAX_SAVE_STACK)
|
|
1545 {
|
|
1546 if (stack_copy == 0)
|
2439
|
1547 stack_copy = (char *) xmalloc (stack_copy_size = i);
|
300
|
1548 else if (stack_copy_size < i)
|
2439
|
1549 stack_copy = (char *) xrealloc (stack_copy, (stack_copy_size = i));
|
300
|
1550 if (stack_copy)
|
|
1551 {
|
8817
|
1552 if ((EMACS_INT) (&stack_top_variable - stack_bottom) > 0)
|
300
|
1553 bcopy (stack_bottom, stack_copy, i);
|
|
1554 else
|
|
1555 bcopy (&stack_top_variable, stack_copy, i);
|
|
1556 }
|
|
1557 }
|
|
1558 }
|
|
1559 #endif /* MAX_SAVE_STACK > 0 */
|
|
1560
|
14959
|
1561 if (garbage_collection_messages)
|
10395
|
1562 message1_nolog ("Garbage collecting...");
|
300
|
1563
|
16538
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1564 /* Don't keep command history around forever. */
|
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1565 if (NUMBERP (Vhistory_length) && XINT (Vhistory_length) > 0)
|
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1566 {
|
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1567 tem = Fnthcdr (Vhistory_length, Vcommand_history);
|
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1568 if (CONSP (tem))
|
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1569 XCONS (tem)->cdr = Qnil;
|
1e1026e6cd9d
(Fgarbage_collect): Use Vhistory_length for truncating Vcommand_history.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1570 }
|
648
|
1571
|
300
|
1572 /* Likewise for undo information. */
|
|
1573 {
|
|
1574 register struct buffer *nextb = all_buffers;
|
|
1575
|
|
1576 while (nextb)
|
|
1577 {
|
648
|
1578 /* If a buffer's undo list is Qt, that means that undo is
|
|
1579 turned off in that buffer. Calling truncate_undo_list on
|
|
1580 Qt tends to return NULL, which effectively turns undo back on.
|
|
1581 So don't call truncate_undo_list if undo_list is Qt. */
|
|
1582 if (! EQ (nextb->undo_list, Qt))
|
|
1583 nextb->undo_list
|
764
|
1584 = truncate_undo_list (nextb->undo_list, undo_limit,
|
|
1585 undo_strong_limit);
|
300
|
1586 nextb = nextb->next;
|
|
1587 }
|
|
1588 }
|
|
1589
|
|
1590 gc_in_progress = 1;
|
|
1591
|
16231
|
1592 /* clear_marks (); */
|
300
|
1593
|
|
1594 /* In each "large string", set the MARKBIT of the size field.
|
|
1595 That enables mark_object to recognize them. */
|
|
1596 {
|
|
1597 register struct string_block *b;
|
|
1598 for (b = large_string_blocks; b; b = b->next)
|
|
1599 ((struct Lisp_String *)(&b->chars[0]))->size |= MARKBIT;
|
|
1600 }
|
|
1601
|
|
1602 /* Mark all the special slots that serve as the roots of accessibility.
|
|
1603
|
|
1604 Usually the special slots to mark are contained in particular structures.
|
|
1605 Then we know no slot is marked twice because the structures don't overlap.
|
|
1606 In some cases, the structures point to the slots to be marked.
|
|
1607 For these, we use MARKBIT to avoid double marking of the slot. */
|
|
1608
|
|
1609 for (i = 0; i < staticidx; i++)
|
|
1610 mark_object (staticvec[i]);
|
|
1611 for (tail = gcprolist; tail; tail = tail->next)
|
|
1612 for (i = 0; i < tail->nvars; i++)
|
|
1613 if (!XMARKBIT (tail->var[i]))
|
|
1614 {
|
|
1615 mark_object (&tail->var[i]);
|
|
1616 XMARK (tail->var[i]);
|
|
1617 }
|
|
1618 for (bind = specpdl; bind != specpdl_ptr; bind++)
|
|
1619 {
|
|
1620 mark_object (&bind->symbol);
|
|
1621 mark_object (&bind->old_value);
|
|
1622 }
|
|
1623 for (catch = catchlist; catch; catch = catch->next)
|
|
1624 {
|
|
1625 mark_object (&catch->tag);
|
|
1626 mark_object (&catch->val);
|
|
1627 }
|
|
1628 for (handler = handlerlist; handler; handler = handler->next)
|
|
1629 {
|
|
1630 mark_object (&handler->handler);
|
|
1631 mark_object (&handler->var);
|
|
1632 }
|
|
1633 for (backlist = backtrace_list; backlist; backlist = backlist->next)
|
|
1634 {
|
|
1635 if (!XMARKBIT (*backlist->function))
|
|
1636 {
|
|
1637 mark_object (backlist->function);
|
|
1638 XMARK (*backlist->function);
|
|
1639 }
|
|
1640 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
|
|
1641 i = 0;
|
|
1642 else
|
|
1643 i = backlist->nargs - 1;
|
|
1644 for (; i >= 0; i--)
|
|
1645 if (!XMARKBIT (backlist->args[i]))
|
|
1646 {
|
|
1647 mark_object (&backlist->args[i]);
|
|
1648 XMARK (backlist->args[i]);
|
|
1649 }
|
|
1650 }
|
11018
|
1651 mark_kboards ();
|
300
|
1652
|
|
1653 gc_sweep ();
|
|
1654
|
|
1655 /* Clear the mark bits that we set in certain root slots. */
|
|
1656
|
|
1657 for (tail = gcprolist; tail; tail = tail->next)
|
|
1658 for (i = 0; i < tail->nvars; i++)
|
|
1659 XUNMARK (tail->var[i]);
|
|
1660 for (backlist = backtrace_list; backlist; backlist = backlist->next)
|
|
1661 {
|
|
1662 XUNMARK (*backlist->function);
|
|
1663 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
|
|
1664 i = 0;
|
|
1665 else
|
|
1666 i = backlist->nargs - 1;
|
|
1667 for (; i >= 0; i--)
|
|
1668 XUNMARK (backlist->args[i]);
|
|
1669 }
|
|
1670 XUNMARK (buffer_defaults.name);
|
|
1671 XUNMARK (buffer_local_symbols.name);
|
|
1672
|
16231
|
1673 /* clear_marks (); */
|
300
|
1674 gc_in_progress = 0;
|
|
1675
|
|
1676 consing_since_gc = 0;
|
|
1677 if (gc_cons_threshold < 10000)
|
|
1678 gc_cons_threshold = 10000;
|
|
1679
|
14959
|
1680 if (garbage_collection_messages)
|
|
1681 {
|
|
1682 if (omessage || minibuf_level > 0)
|
|
1683 message2_nolog (omessage, omessage_length);
|
|
1684 else
|
|
1685 message1_nolog ("Garbage collecting...done");
|
|
1686 }
|
300
|
1687
|
|
1688 return Fcons (Fcons (make_number (total_conses),
|
|
1689 make_number (total_free_conses)),
|
|
1690 Fcons (Fcons (make_number (total_symbols),
|
|
1691 make_number (total_free_symbols)),
|
|
1692 Fcons (Fcons (make_number (total_markers),
|
|
1693 make_number (total_free_markers)),
|
|
1694 Fcons (make_number (total_string_size),
|
|
1695 Fcons (make_number (total_vector_size),
|
16001
|
1696 Fcons (Fcons
|
300
|
1697 #ifdef LISP_FLOAT_TYPE
|
16001
|
1698 (make_number (total_floats),
|
|
1699 make_number (total_free_floats)),
|
300
|
1700 #else /* not LISP_FLOAT_TYPE */
|
16001
|
1701 (make_number (0), make_number (0)),
|
300
|
1702 #endif /* not LISP_FLOAT_TYPE */
|
16001
|
1703 Fcons (Fcons
|
|
1704 #ifdef USE_TEXT_PROPERTIES
|
|
1705 (make_number (total_intervals),
|
|
1706 make_number (total_free_intervals)),
|
|
1707 #else /* not USE_TEXT_PROPERTIES */
|
|
1708 (make_number (0), make_number (0)),
|
|
1709 #endif /* not USE_TEXT_PROPERTIES */
|
|
1710 Qnil)))))));
|
300
|
1711 }
|
|
1712
|
|
1713 #if 0
|
|
1714 static void
|
|
1715 clear_marks ()
|
|
1716 {
|
|
1717 /* Clear marks on all conses */
|
|
1718 {
|
|
1719 register struct cons_block *cblk;
|
|
1720 register int lim = cons_block_index;
|
|
1721
|
|
1722 for (cblk = cons_block; cblk; cblk = cblk->next)
|
|
1723 {
|
|
1724 register int i;
|
|
1725 for (i = 0; i < lim; i++)
|
|
1726 XUNMARK (cblk->conses[i].car);
|
|
1727 lim = CONS_BLOCK_SIZE;
|
|
1728 }
|
|
1729 }
|
|
1730 /* Clear marks on all symbols */
|
|
1731 {
|
|
1732 register struct symbol_block *sblk;
|
|
1733 register int lim = symbol_block_index;
|
|
1734
|
|
1735 for (sblk = symbol_block; sblk; sblk = sblk->next)
|
|
1736 {
|
|
1737 register int i;
|
|
1738 for (i = 0; i < lim; i++)
|
|
1739 {
|
|
1740 XUNMARK (sblk->symbols[i].plist);
|
|
1741 }
|
|
1742 lim = SYMBOL_BLOCK_SIZE;
|
|
1743 }
|
|
1744 }
|
|
1745 /* Clear marks on all markers */
|
|
1746 {
|
|
1747 register struct marker_block *sblk;
|
|
1748 register int lim = marker_block_index;
|
|
1749
|
|
1750 for (sblk = marker_block; sblk; sblk = sblk->next)
|
|
1751 {
|
|
1752 register int i;
|
|
1753 for (i = 0; i < lim; i++)
|
11243
|
1754 if (sblk->markers[i].u_marker.type == Lisp_Misc_Marker)
|
9437
|
1755 XUNMARK (sblk->markers[i].u_marker.chain);
|
300
|
1756 lim = MARKER_BLOCK_SIZE;
|
|
1757 }
|
|
1758 }
|
|
1759 /* Clear mark bits on all buffers */
|
|
1760 {
|
|
1761 register struct buffer *nextb = all_buffers;
|
|
1762
|
|
1763 while (nextb)
|
|
1764 {
|
|
1765 XUNMARK (nextb->name);
|
|
1766 nextb = nextb->next;
|
|
1767 }
|
|
1768 }
|
|
1769 }
|
|
1770 #endif
|
|
1771
|
1908
|
1772 /* Mark reference to a Lisp_Object.
|
|
1773 If the object referred to has not been seen yet, recursively mark
|
|
1774 all the references contained in it.
|
300
|
1775
|
3591
|
1776 If the object referenced is a short string, the referencing slot
|
300
|
1777 is threaded into a chain of such slots, pointed to from
|
|
1778 the `size' field of the string. The actual string size
|
|
1779 lives in the last slot in the chain. We recognize the end
|
|
1780 because it is < (unsigned) STRING_BLOCK_SIZE. */
|
|
1781
|
1168
|
1782 #define LAST_MARKED_SIZE 500
|
|
1783 Lisp_Object *last_marked[LAST_MARKED_SIZE];
|
|
1784 int last_marked_index;
|
|
1785
|
300
|
1786 static void
|
13553
|
1787 mark_object (argptr)
|
|
1788 Lisp_Object *argptr;
|
300
|
1789 {
|
13553
|
1790 Lisp_Object *objptr = argptr;
|
300
|
1791 register Lisp_Object obj;
|
|
1792
|
5868
|
1793 loop:
|
300
|
1794 obj = *objptr;
|
5868
|
1795 loop2:
|
300
|
1796 XUNMARK (obj);
|
|
1797
|
|
1798 if ((PNTR_COMPARISON_TYPE) XPNTR (obj) < (PNTR_COMPARISON_TYPE) ((char *) pure + PURESIZE)
|
|
1799 && (PNTR_COMPARISON_TYPE) XPNTR (obj) >= (PNTR_COMPARISON_TYPE) pure)
|
|
1800 return;
|
|
1801
|
1168
|
1802 last_marked[last_marked_index++] = objptr;
|
|
1803 if (last_marked_index == LAST_MARKED_SIZE)
|
|
1804 last_marked_index = 0;
|
|
1805
|
10457
2ab3bd0288a9
Change all occurences of SWITCH_ENUM_BUG to use SWITCH_ENUM_CAST instead.
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
1806 switch (SWITCH_ENUM_CAST (XGCTYPE (obj)))
|
300
|
1807 {
|
|
1808 case Lisp_String:
|
|
1809 {
|
|
1810 register struct Lisp_String *ptr = XSTRING (obj);
|
|
1811
|
1300
|
1812 MARK_INTERVAL_TREE (ptr->intervals);
|
300
|
1813 if (ptr->size & MARKBIT)
|
|
1814 /* A large string. Just set ARRAY_MARK_FLAG. */
|
|
1815 ptr->size |= ARRAY_MARK_FLAG;
|
|
1816 else
|
|
1817 {
|
|
1818 /* A small string. Put this reference
|
|
1819 into the chain of references to it.
|
10413
|
1820 If the address includes MARKBIT, put that bit elsewhere
|
300
|
1821 when we store OBJPTR into the size field. */
|
|
1822
|
|
1823 if (XMARKBIT (*objptr))
|
|
1824 {
|
9295
|
1825 XSETFASTINT (*objptr, ptr->size);
|
300
|
1826 XMARK (*objptr);
|
|
1827 }
|
|
1828 else
|
9295
|
1829 XSETFASTINT (*objptr, ptr->size);
|
10389
|
1830
|
|
1831 if ((EMACS_INT) objptr & DONT_COPY_FLAG)
|
|
1832 abort ();
|
10413
|
1833 ptr->size = (EMACS_INT) objptr;
|
|
1834 if (ptr->size & MARKBIT)
|
|
1835 ptr->size ^= MARKBIT | DONT_COPY_FLAG;
|
300
|
1836 }
|
|
1837 }
|
|
1838 break;
|
|
1839
|
10009
|
1840 case Lisp_Vectorlike:
|
10307
|
1841 if (GC_BUFFERP (obj))
|
10340
|
1842 {
|
|
1843 if (!XMARKBIT (XBUFFER (obj)->name))
|
|
1844 mark_buffer (obj);
|
|
1845 }
|
10307
|
1846 else if (GC_SUBRP (obj))
|
10291
|
1847 break;
|
|
1848 else if (GC_COMPILEDP (obj))
|
|
1849 /* We could treat this just like a vector, but it is better
|
|
1850 to save the COMPILED_CONSTANTS element for last and avoid recursion
|
|
1851 there. */
|
|
1852 {
|
|
1853 register struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
1854 register EMACS_INT size = ptr->size;
|
|
1855 /* See comment above under Lisp_Vector. */
|
|
1856 struct Lisp_Vector *volatile ptr1 = ptr;
|
|
1857 register int i;
|
300
|
1858
|
10291
|
1859 if (size & ARRAY_MARK_FLAG)
|
|
1860 break; /* Already marked */
|
|
1861 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */
|
10009
|
1862 size &= PSEUDOVECTOR_SIZE_MASK;
|
10291
|
1863 for (i = 0; i < size; i++) /* and then mark its elements */
|
|
1864 {
|
|
1865 if (i != COMPILED_CONSTANTS)
|
|
1866 mark_object (&ptr1->contents[i]);
|
|
1867 }
|
|
1868 /* This cast should be unnecessary, but some Mips compiler complains
|
|
1869 (MIPS-ABI + SysVR4, DC/OSx, etc). */
|
|
1870 objptr = (Lisp_Object *) &ptr1->contents[COMPILED_CONSTANTS];
|
|
1871 goto loop;
|
|
1872 }
|
|
1873 else if (GC_FRAMEP (obj))
|
|
1874 {
|
|
1875 /* See comment above under Lisp_Vector for why this is volatile. */
|
|
1876 register struct frame *volatile ptr = XFRAME (obj);
|
|
1877 register EMACS_INT size = ptr->size;
|
1295
|
1878
|
10291
|
1879 if (size & ARRAY_MARK_FLAG) break; /* Already marked */
|
|
1880 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */
|
1295
|
1881
|
10291
|
1882 mark_object (&ptr->name);
|
12273
|
1883 mark_object (&ptr->icon_name);
|
14216
|
1884 mark_object (&ptr->title);
|
10291
|
1885 mark_object (&ptr->focus_frame);
|
|
1886 mark_object (&ptr->selected_window);
|
|
1887 mark_object (&ptr->minibuffer_window);
|
|
1888 mark_object (&ptr->param_alist);
|
|
1889 mark_object (&ptr->scroll_bars);
|
|
1890 mark_object (&ptr->condemned_scroll_bars);
|
|
1891 mark_object (&ptr->menu_bar_items);
|
|
1892 mark_object (&ptr->face_alist);
|
|
1893 mark_object (&ptr->menu_bar_vector);
|
|
1894 mark_object (&ptr->buffer_predicate);
|
17217
|
1895 mark_object (&ptr->buffer_list);
|
10291
|
1896 }
|
13141
|
1897 else if (GC_BOOL_VECTOR_P (obj))
|
15379
|
1898 {
|
|
1899 register struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
1900
|
|
1901 if (ptr->size & ARRAY_MARK_FLAG)
|
|
1902 break; /* Already marked */
|
|
1903 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */
|
|
1904 }
|
10291
|
1905 else
|
|
1906 {
|
|
1907 register struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
1908 register EMACS_INT size = ptr->size;
|
|
1909 /* The reason we use ptr1 is to avoid an apparent hardware bug
|
|
1910 that happens occasionally on the FSF's HP 300s.
|
|
1911 The bug is that a2 gets clobbered by recursive calls to mark_object.
|
|
1912 The clobberage seems to happen during function entry,
|
|
1913 perhaps in the moveml instruction.
|
|
1914 Yes, this is a crock, but we have to do it. */
|
|
1915 struct Lisp_Vector *volatile ptr1 = ptr;
|
|
1916 register int i;
|
300
|
1917
|
10291
|
1918 if (size & ARRAY_MARK_FLAG) break; /* Already marked */
|
|
1919 ptr->size |= ARRAY_MARK_FLAG; /* Else mark it */
|
|
1920 if (size & PSEUDOVECTOR_FLAG)
|
|
1921 size &= PSEUDOVECTOR_SIZE_MASK;
|
|
1922 for (i = 0; i < size; i++) /* and then mark its elements */
|
|
1923 mark_object (&ptr1->contents[i]);
|
|
1924 }
|
300
|
1925 break;
|
|
1926
|
|
1927 case Lisp_Symbol:
|
|
1928 {
|
4494
|
1929 /* See comment above under Lisp_Vector for why this is volatile. */
|
|
1930 register struct Lisp_Symbol *volatile ptr = XSYMBOL (obj);
|
300
|
1931 struct Lisp_Symbol *ptrx;
|
|
1932
|
|
1933 if (XMARKBIT (ptr->plist)) break;
|
|
1934 XMARK (ptr->plist);
|
|
1935 mark_object ((Lisp_Object *) &ptr->value);
|
|
1936 mark_object (&ptr->function);
|
|
1937 mark_object (&ptr->plist);
|
1114
|
1938 XSETTYPE (*(Lisp_Object *) &ptr->name, Lisp_String);
|
|
1939 mark_object (&ptr->name);
|
300
|
1940 ptr = ptr->next;
|
|
1941 if (ptr)
|
|
1942 {
|
5868
|
1943 /* For the benefit of the last_marked log. */
|
|
1944 objptr = (Lisp_Object *)&XSYMBOL (obj)->next;
|
2507
|
1945 ptrx = ptr; /* Use of ptrx avoids compiler bug on Sun */
|
300
|
1946 XSETSYMBOL (obj, ptrx);
|
5868
|
1947 /* We can't goto loop here because *objptr doesn't contain an
|
|
1948 actual Lisp_Object with valid datatype field. */
|
|
1949 goto loop2;
|
300
|
1950 }
|
|
1951 }
|
|
1952 break;
|
|
1953
|
9437
|
1954 case Lisp_Misc:
|
11243
|
1955 switch (XMISCTYPE (obj))
|
9437
|
1956 {
|
|
1957 case Lisp_Misc_Marker:
|
|
1958 XMARK (XMARKER (obj)->chain);
|
|
1959 /* DO NOT mark thru the marker's chain.
|
|
1960 The buffer's markers chain does not preserve markers from gc;
|
|
1961 instead, markers are removed from the chain when freed by gc. */
|
|
1962 break;
|
|
1963
|
9893
|
1964 case Lisp_Misc_Buffer_Local_Value:
|
|
1965 case Lisp_Misc_Some_Buffer_Local_Value:
|
|
1966 {
|
|
1967 register struct Lisp_Buffer_Local_Value *ptr
|
|
1968 = XBUFFER_LOCAL_VALUE (obj);
|
|
1969 if (XMARKBIT (ptr->car)) break;
|
|
1970 XMARK (ptr->car);
|
|
1971 /* If the cdr is nil, avoid recursion for the car. */
|
|
1972 if (EQ (ptr->cdr, Qnil))
|
|
1973 {
|
|
1974 objptr = &ptr->car;
|
|
1975 goto loop;
|
|
1976 }
|
|
1977 mark_object (&ptr->car);
|
|
1978 /* See comment above under Lisp_Vector for why not use ptr here. */
|
|
1979 objptr = &XBUFFER_LOCAL_VALUE (obj)->cdr;
|
|
1980 goto loop;
|
|
1981 }
|
|
1982
|
9463
|
1983 case Lisp_Misc_Intfwd:
|
|
1984 case Lisp_Misc_Boolfwd:
|
|
1985 case Lisp_Misc_Objfwd:
|
|
1986 case Lisp_Misc_Buffer_Objfwd:
|
11018
|
1987 case Lisp_Misc_Kboard_Objfwd:
|
9463
|
1988 /* Don't bother with Lisp_Buffer_Objfwd,
|
|
1989 since all markable slots in current buffer marked anyway. */
|
|
1990 /* Don't need to do Lisp_Objfwd, since the places they point
|
|
1991 are protected with staticpro. */
|
|
1992 break;
|
|
1993
|
9926
|
1994 case Lisp_Misc_Overlay:
|
|
1995 {
|
|
1996 struct Lisp_Overlay *ptr = XOVERLAY (obj);
|
|
1997 if (!XMARKBIT (ptr->plist))
|
|
1998 {
|
|
1999 XMARK (ptr->plist);
|
|
2000 mark_object (&ptr->start);
|
|
2001 mark_object (&ptr->end);
|
|
2002 objptr = &ptr->plist;
|
|
2003 goto loop;
|
|
2004 }
|
|
2005 }
|
|
2006 break;
|
|
2007
|
9437
|
2008 default:
|
|
2009 abort ();
|
|
2010 }
|
300
|
2011 break;
|
|
2012
|
|
2013 case Lisp_Cons:
|
|
2014 {
|
|
2015 register struct Lisp_Cons *ptr = XCONS (obj);
|
|
2016 if (XMARKBIT (ptr->car)) break;
|
|
2017 XMARK (ptr->car);
|
1295
|
2018 /* If the cdr is nil, avoid recursion for the car. */
|
|
2019 if (EQ (ptr->cdr, Qnil))
|
|
2020 {
|
|
2021 objptr = &ptr->car;
|
|
2022 goto loop;
|
|
2023 }
|
300
|
2024 mark_object (&ptr->car);
|
4494
|
2025 /* See comment above under Lisp_Vector for why not use ptr here. */
|
|
2026 objptr = &XCONS (obj)->cdr;
|
300
|
2027 goto loop;
|
|
2028 }
|
|
2029
|
|
2030 #ifdef LISP_FLOAT_TYPE
|
|
2031 case Lisp_Float:
|
|
2032 XMARK (XFLOAT (obj)->type);
|
|
2033 break;
|
|
2034 #endif /* LISP_FLOAT_TYPE */
|
|
2035
|
|
2036 case Lisp_Int:
|
|
2037 break;
|
|
2038
|
|
2039 default:
|
|
2040 abort ();
|
|
2041 }
|
|
2042 }
|
|
2043
|
|
2044 /* Mark the pointers in a buffer structure. */
|
|
2045
|
|
2046 static void
|
|
2047 mark_buffer (buf)
|
|
2048 Lisp_Object buf;
|
|
2049 {
|
|
2050 register struct buffer *buffer = XBUFFER (buf);
|
|
2051 register Lisp_Object *ptr;
|
10307
|
2052 Lisp_Object base_buffer;
|
300
|
2053
|
|
2054 /* This is the buffer's markbit */
|
|
2055 mark_object (&buffer->name);
|
|
2056 XMARK (buffer->name);
|
|
2057
|
10307
|
2058 MARK_INTERVAL_TREE (BUF_INTERVALS (buffer));
|
1300
|
2059
|
300
|
2060 #if 0
|
|
2061 mark_object (buffer->syntax_table);
|
|
2062
|
|
2063 /* Mark the various string-pointers in the buffer object.
|
|
2064 Since the strings may be relocated, we must mark them
|
|
2065 in their actual slots. So gc_sweep must convert each slot
|
|
2066 back to an ordinary C pointer. */
|
9261
|
2067 XSETSTRING (*(Lisp_Object *)&buffer->upcase_table, buffer->upcase_table);
|
300
|
2068 mark_object ((Lisp_Object *)&buffer->upcase_table);
|
9261
|
2069 XSETSTRING (*(Lisp_Object *)&buffer->downcase_table, buffer->downcase_table);
|
300
|
2070 mark_object ((Lisp_Object *)&buffer->downcase_table);
|
|
2071
|
9261
|
2072 XSETSTRING (*(Lisp_Object *)&buffer->sort_table, buffer->sort_table);
|
300
|
2073 mark_object ((Lisp_Object *)&buffer->sort_table);
|
9261
|
2074 XSETSTRING (*(Lisp_Object *)&buffer->folding_sort_table, buffer->folding_sort_table);
|
300
|
2075 mark_object ((Lisp_Object *)&buffer->folding_sort_table);
|
|
2076 #endif
|
|
2077
|
|
2078 for (ptr = &buffer->name + 1;
|
|
2079 (char *)ptr < (char *)buffer + sizeof (struct buffer);
|
|
2080 ptr++)
|
|
2081 mark_object (ptr);
|
10307
|
2082
|
|
2083 /* If this is an indirect buffer, mark its base buffer. */
|
10340
|
2084 if (buffer->base_buffer && !XMARKBIT (buffer->base_buffer->name))
|
10307
|
2085 {
|
|
2086 XSETBUFFER (base_buffer, buffer->base_buffer);
|
|
2087 mark_buffer (base_buffer);
|
|
2088 }
|
300
|
2089 }
|
10649
|
2090
|
|
2091
|
11018
|
2092 /* Mark the pointers in the kboard objects. */
|
10649
|
2093
|
|
2094 static void
|
11018
|
2095 mark_kboards ()
|
10649
|
2096 {
|
11018
|
2097 KBOARD *kb;
|
11593
|
2098 Lisp_Object *p;
|
11018
|
2099 for (kb = all_kboards; kb; kb = kb->next_kboard)
|
10649
|
2100 {
|
11593
|
2101 if (kb->kbd_macro_buffer)
|
|
2102 for (p = kb->kbd_macro_buffer; p < kb->kbd_macro_ptr; p++)
|
|
2103 mark_object (p);
|
12120
|
2104 mark_object (&kb->Vprefix_arg);
|
11018
|
2105 mark_object (&kb->kbd_queue);
|
|
2106 mark_object (&kb->Vlast_kbd_macro);
|
11593
|
2107 mark_object (&kb->Vsystem_key_alist);
|
12175
|
2108 mark_object (&kb->system_key_syms);
|
10649
|
2109 }
|
|
2110 }
|
300
|
2111
|
1908
|
2112 /* Sweep: find all structures not marked, and free them. */
|
300
|
2113
|
|
2114 static void
|
|
2115 gc_sweep ()
|
|
2116 {
|
|
2117 total_string_size = 0;
|
|
2118 compact_strings ();
|
|
2119
|
|
2120 /* Put all unmarked conses on free list */
|
|
2121 {
|
|
2122 register struct cons_block *cblk;
|
|
2123 register int lim = cons_block_index;
|
|
2124 register int num_free = 0, num_used = 0;
|
|
2125
|
|
2126 cons_free_list = 0;
|
|
2127
|
|
2128 for (cblk = cons_block; cblk; cblk = cblk->next)
|
|
2129 {
|
|
2130 register int i;
|
|
2131 for (i = 0; i < lim; i++)
|
|
2132 if (!XMARKBIT (cblk->conses[i].car))
|
|
2133 {
|
|
2134 num_free++;
|
9942
|
2135 *(struct Lisp_Cons **)&cblk->conses[i].car = cons_free_list;
|
300
|
2136 cons_free_list = &cblk->conses[i];
|
|
2137 }
|
|
2138 else
|
|
2139 {
|
|
2140 num_used++;
|
|
2141 XUNMARK (cblk->conses[i].car);
|
|
2142 }
|
|
2143 lim = CONS_BLOCK_SIZE;
|
|
2144 }
|
|
2145 total_conses = num_used;
|
|
2146 total_free_conses = num_free;
|
|
2147 }
|
|
2148
|
|
2149 #ifdef LISP_FLOAT_TYPE
|
|
2150 /* Put all unmarked floats on free list */
|
|
2151 {
|
|
2152 register struct float_block *fblk;
|
|
2153 register int lim = float_block_index;
|
|
2154 register int num_free = 0, num_used = 0;
|
|
2155
|
|
2156 float_free_list = 0;
|
|
2157
|
|
2158 for (fblk = float_block; fblk; fblk = fblk->next)
|
|
2159 {
|
|
2160 register int i;
|
|
2161 for (i = 0; i < lim; i++)
|
|
2162 if (!XMARKBIT (fblk->floats[i].type))
|
|
2163 {
|
|
2164 num_free++;
|
9942
|
2165 *(struct Lisp_Float **)&fblk->floats[i].type = float_free_list;
|
300
|
2166 float_free_list = &fblk->floats[i];
|
|
2167 }
|
|
2168 else
|
|
2169 {
|
|
2170 num_used++;
|
|
2171 XUNMARK (fblk->floats[i].type);
|
|
2172 }
|
|
2173 lim = FLOAT_BLOCK_SIZE;
|
|
2174 }
|
|
2175 total_floats = num_used;
|
|
2176 total_free_floats = num_free;
|
|
2177 }
|
|
2178 #endif /* LISP_FLOAT_TYPE */
|
|
2179
|
1300
|
2180 #ifdef USE_TEXT_PROPERTIES
|
|
2181 /* Put all unmarked intervals on free list */
|
|
2182 {
|
|
2183 register struct interval_block *iblk;
|
|
2184 register int lim = interval_block_index;
|
|
2185 register int num_free = 0, num_used = 0;
|
|
2186
|
|
2187 interval_free_list = 0;
|
|
2188
|
|
2189 for (iblk = interval_block; iblk; iblk = iblk->next)
|
|
2190 {
|
|
2191 register int i;
|
|
2192
|
|
2193 for (i = 0; i < lim; i++)
|
|
2194 {
|
|
2195 if (! XMARKBIT (iblk->intervals[i].plist))
|
|
2196 {
|
|
2197 iblk->intervals[i].parent = interval_free_list;
|
|
2198 interval_free_list = &iblk->intervals[i];
|
|
2199 num_free++;
|
|
2200 }
|
|
2201 else
|
|
2202 {
|
|
2203 num_used++;
|
|
2204 XUNMARK (iblk->intervals[i].plist);
|
|
2205 }
|
|
2206 }
|
|
2207 lim = INTERVAL_BLOCK_SIZE;
|
|
2208 }
|
|
2209 total_intervals = num_used;
|
|
2210 total_free_intervals = num_free;
|
|
2211 }
|
|
2212 #endif /* USE_TEXT_PROPERTIES */
|
|
2213
|
300
|
2214 /* Put all unmarked symbols on free list */
|
|
2215 {
|
|
2216 register struct symbol_block *sblk;
|
|
2217 register int lim = symbol_block_index;
|
|
2218 register int num_free = 0, num_used = 0;
|
|
2219
|
|
2220 symbol_free_list = 0;
|
|
2221
|
|
2222 for (sblk = symbol_block; sblk; sblk = sblk->next)
|
|
2223 {
|
|
2224 register int i;
|
|
2225 for (i = 0; i < lim; i++)
|
|
2226 if (!XMARKBIT (sblk->symbols[i].plist))
|
|
2227 {
|
9942
|
2228 *(struct Lisp_Symbol **)&sblk->symbols[i].value = symbol_free_list;
|
300
|
2229 symbol_free_list = &sblk->symbols[i];
|
|
2230 num_free++;
|
|
2231 }
|
|
2232 else
|
|
2233 {
|
|
2234 num_used++;
|
|
2235 sblk->symbols[i].name
|
|
2236 = XSTRING (*(Lisp_Object *) &sblk->symbols[i].name);
|
|
2237 XUNMARK (sblk->symbols[i].plist);
|
|
2238 }
|
|
2239 lim = SYMBOL_BLOCK_SIZE;
|
|
2240 }
|
|
2241 total_symbols = num_used;
|
|
2242 total_free_symbols = num_free;
|
|
2243 }
|
|
2244
|
|
2245 #ifndef standalone
|
|
2246 /* Put all unmarked markers on free list.
|
14036
|
2247 Unchain each one first from the buffer it points into,
|
9893
|
2248 but only if it's a real marker. */
|
300
|
2249 {
|
|
2250 register struct marker_block *mblk;
|
|
2251 register int lim = marker_block_index;
|
|
2252 register int num_free = 0, num_used = 0;
|
|
2253
|
|
2254 marker_free_list = 0;
|
|
2255
|
|
2256 for (mblk = marker_block; mblk; mblk = mblk->next)
|
|
2257 {
|
|
2258 register int i;
|
11679
|
2259 EMACS_INT already_free = -1;
|
11403
|
2260
|
300
|
2261 for (i = 0; i < lim; i++)
|
9893
|
2262 {
|
|
2263 Lisp_Object *markword;
|
11243
|
2264 switch (mblk->markers[i].u_marker.type)
|
9893
|
2265 {
|
|
2266 case Lisp_Misc_Marker:
|
|
2267 markword = &mblk->markers[i].u_marker.chain;
|
|
2268 break;
|
|
2269 case Lisp_Misc_Buffer_Local_Value:
|
|
2270 case Lisp_Misc_Some_Buffer_Local_Value:
|
|
2271 markword = &mblk->markers[i].u_buffer_local_value.car;
|
|
2272 break;
|
9926
|
2273 case Lisp_Misc_Overlay:
|
|
2274 markword = &mblk->markers[i].u_overlay.plist;
|
|
2275 break;
|
11403
|
2276 case Lisp_Misc_Free:
|
|
2277 /* If the object was already free, keep it
|
|
2278 on the free list. */
|
18621
|
2279 markword = (Lisp_Object *) &already_free;
|
11403
|
2280 break;
|
9893
|
2281 default:
|
|
2282 markword = 0;
|
9926
|
2283 break;
|
9893
|
2284 }
|
|
2285 if (markword && !XMARKBIT (*markword))
|
|
2286 {
|
|
2287 Lisp_Object tem;
|
11243
|
2288 if (mblk->markers[i].u_marker.type == Lisp_Misc_Marker)
|
9893
|
2289 {
|
|
2290 /* tem1 avoids Sun compiler bug */
|
|
2291 struct Lisp_Marker *tem1 = &mblk->markers[i].u_marker;
|
|
2292 XSETMARKER (tem, tem1);
|
|
2293 unchain_marker (tem);
|
|
2294 }
|
11403
|
2295 /* Set the type of the freed object to Lisp_Misc_Free.
|
|
2296 We could leave the type alone, since nobody checks it,
|
9893
|
2297 but this might catch bugs faster. */
|
11243
|
2298 mblk->markers[i].u_marker.type = Lisp_Misc_Free;
|
9893
|
2299 mblk->markers[i].u_free.chain = marker_free_list;
|
|
2300 marker_free_list = &mblk->markers[i];
|
|
2301 num_free++;
|
|
2302 }
|
|
2303 else
|
|
2304 {
|
|
2305 num_used++;
|
|
2306 if (markword)
|
|
2307 XUNMARK (*markword);
|
|
2308 }
|
|
2309 }
|
300
|
2310 lim = MARKER_BLOCK_SIZE;
|
|
2311 }
|
|
2312
|
|
2313 total_markers = num_used;
|
|
2314 total_free_markers = num_free;
|
|
2315 }
|
|
2316
|
|
2317 /* Free all unmarked buffers */
|
|
2318 {
|
|
2319 register struct buffer *buffer = all_buffers, *prev = 0, *next;
|
|
2320
|
|
2321 while (buffer)
|
|
2322 if (!XMARKBIT (buffer->name))
|
|
2323 {
|
|
2324 if (prev)
|
|
2325 prev->next = buffer->next;
|
|
2326 else
|
|
2327 all_buffers = buffer->next;
|
|
2328 next = buffer->next;
|
2439
|
2329 xfree (buffer);
|
300
|
2330 buffer = next;
|
|
2331 }
|
|
2332 else
|
|
2333 {
|
|
2334 XUNMARK (buffer->name);
|
10307
|
2335 UNMARK_BALANCE_INTERVALS (BUF_INTERVALS (buffer));
|
300
|
2336
|
|
2337 #if 0
|
|
2338 /* Each `struct Lisp_String *' was turned into a Lisp_Object
|
|
2339 for purposes of marking and relocation.
|
|
2340 Turn them back into C pointers now. */
|
|
2341 buffer->upcase_table
|
|
2342 = XSTRING (*(Lisp_Object *)&buffer->upcase_table);
|
|
2343 buffer->downcase_table
|
|
2344 = XSTRING (*(Lisp_Object *)&buffer->downcase_table);
|
|
2345 buffer->sort_table
|
|
2346 = XSTRING (*(Lisp_Object *)&buffer->sort_table);
|
|
2347 buffer->folding_sort_table
|
|
2348 = XSTRING (*(Lisp_Object *)&buffer->folding_sort_table);
|
|
2349 #endif
|
|
2350
|
|
2351 prev = buffer, buffer = buffer->next;
|
|
2352 }
|
|
2353 }
|
|
2354
|
|
2355 #endif /* standalone */
|
|
2356
|
|
2357 /* Free all unmarked vectors */
|
|
2358 {
|
|
2359 register struct Lisp_Vector *vector = all_vectors, *prev = 0, *next;
|
|
2360 total_vector_size = 0;
|
|
2361
|
|
2362 while (vector)
|
|
2363 if (!(vector->size & ARRAY_MARK_FLAG))
|
|
2364 {
|
|
2365 if (prev)
|
|
2366 prev->next = vector->next;
|
|
2367 else
|
|
2368 all_vectors = vector->next;
|
|
2369 next = vector->next;
|
2439
|
2370 xfree (vector);
|
300
|
2371 vector = next;
|
|
2372 }
|
|
2373 else
|
|
2374 {
|
|
2375 vector->size &= ~ARRAY_MARK_FLAG;
|
11403
|
2376 if (vector->size & PSEUDOVECTOR_FLAG)
|
|
2377 total_vector_size += (PSEUDOVECTOR_SIZE_MASK & vector->size);
|
|
2378 else
|
|
2379 total_vector_size += vector->size;
|
300
|
2380 prev = vector, vector = vector->next;
|
|
2381 }
|
|
2382 }
|
|
2383
|
|
2384 /* Free all "large strings" not marked with ARRAY_MARK_FLAG. */
|
|
2385 {
|
|
2386 register struct string_block *sb = large_string_blocks, *prev = 0, *next;
|
4139
|
2387 struct Lisp_String *s;
|
300
|
2388
|
|
2389 while (sb)
|
4139
|
2390 {
|
|
2391 s = (struct Lisp_String *) &sb->chars[0];
|
|
2392 if (s->size & ARRAY_MARK_FLAG)
|
|
2393 {
|
|
2394 ((struct Lisp_String *)(&sb->chars[0]))->size
|
10413
|
2395 &= ~ARRAY_MARK_FLAG & ~MARKBIT;
|
4139
|
2396 UNMARK_BALANCE_INTERVALS (s->intervals);
|
|
2397 total_string_size += ((struct Lisp_String *)(&sb->chars[0]))->size;
|
|
2398 prev = sb, sb = sb->next;
|
|
2399 }
|
|
2400 else
|
|
2401 {
|
|
2402 if (prev)
|
|
2403 prev->next = sb->next;
|
|
2404 else
|
|
2405 large_string_blocks = sb->next;
|
|
2406 next = sb->next;
|
|
2407 xfree (sb);
|
|
2408 sb = next;
|
|
2409 }
|
|
2410 }
|
300
|
2411 }
|
|
2412 }
|
|
2413
|
1908
|
2414 /* Compactify strings, relocate references, and free empty string blocks. */
|
300
|
2415
|
|
2416 static void
|
|
2417 compact_strings ()
|
|
2418 {
|
|
2419 /* String block of old strings we are scanning. */
|
|
2420 register struct string_block *from_sb;
|
|
2421 /* A preceding string block (or maybe the same one)
|
|
2422 where we are copying the still-live strings to. */
|
|
2423 register struct string_block *to_sb;
|
|
2424 int pos;
|
|
2425 int to_pos;
|
|
2426
|
|
2427 to_sb = first_string_block;
|
|
2428 to_pos = 0;
|
|
2429
|
|
2430 /* Scan each existing string block sequentially, string by string. */
|
|
2431 for (from_sb = first_string_block; from_sb; from_sb = from_sb->next)
|
|
2432 {
|
|
2433 pos = 0;
|
|
2434 /* POS is the index of the next string in the block. */
|
|
2435 while (pos < from_sb->pos)
|
|
2436 {
|
|
2437 register struct Lisp_String *nextstr
|
|
2438 = (struct Lisp_String *) &from_sb->chars[pos];
|
|
2439
|
|
2440 register struct Lisp_String *newaddr;
|
8817
|
2441 register EMACS_INT size = nextstr->size;
|
300
|
2442
|
|
2443 /* NEXTSTR is the old address of the next string.
|
|
2444 Just skip it if it isn't marked. */
|
10389
|
2445 if (((EMACS_UINT) size & ~DONT_COPY_FLAG) > STRING_BLOCK_SIZE)
|
300
|
2446 {
|
|
2447 /* It is marked, so its size field is really a chain of refs.
|
|
2448 Find the end of the chain, where the actual size lives. */
|
10389
|
2449 while (((EMACS_UINT) size & ~DONT_COPY_FLAG) > STRING_BLOCK_SIZE)
|
300
|
2450 {
|
10389
|
2451 if (size & DONT_COPY_FLAG)
|
|
2452 size ^= MARKBIT | DONT_COPY_FLAG;
|
8817
|
2453 size = *(EMACS_INT *)size & ~MARKBIT;
|
300
|
2454 }
|
|
2455
|
|
2456 total_string_size += size;
|
|
2457
|
|
2458 /* If it won't fit in TO_SB, close it out,
|
|
2459 and move to the next sb. Keep doing so until
|
|
2460 TO_SB reaches a large enough, empty enough string block.
|
|
2461 We know that TO_SB cannot advance past FROM_SB here
|
|
2462 since FROM_SB is large enough to contain this string.
|
|
2463 Any string blocks skipped here
|
|
2464 will be patched out and freed later. */
|
|
2465 while (to_pos + STRING_FULLSIZE (size)
|
|
2466 > max (to_sb->pos, STRING_BLOCK_SIZE))
|
|
2467 {
|
|
2468 to_sb->pos = to_pos;
|
|
2469 to_sb = to_sb->next;
|
|
2470 to_pos = 0;
|
|
2471 }
|
|
2472 /* Compute new address of this string
|
|
2473 and update TO_POS for the space being used. */
|
|
2474 newaddr = (struct Lisp_String *) &to_sb->chars[to_pos];
|
|
2475 to_pos += STRING_FULLSIZE (size);
|
|
2476
|
|
2477 /* Copy the string itself to the new place. */
|
|
2478 if (nextstr != newaddr)
|
8817
|
2479 bcopy (nextstr, newaddr, size + 1 + sizeof (EMACS_INT)
|
1300
|
2480 + INTERVAL_PTR_SIZE);
|
300
|
2481
|
|
2482 /* Go through NEXTSTR's chain of references
|
|
2483 and make each slot in the chain point to
|
|
2484 the new address of this string. */
|
|
2485 size = newaddr->size;
|
10389
|
2486 while (((EMACS_UINT) size & ~DONT_COPY_FLAG) > STRING_BLOCK_SIZE)
|
300
|
2487 {
|
|
2488 register Lisp_Object *objptr;
|
10389
|
2489 if (size & DONT_COPY_FLAG)
|
|
2490 size ^= MARKBIT | DONT_COPY_FLAG;
|
300
|
2491 objptr = (Lisp_Object *)size;
|
|
2492
|
|
2493 size = XFASTINT (*objptr) & ~MARKBIT;
|
|
2494 if (XMARKBIT (*objptr))
|
|
2495 {
|
9261
|
2496 XSETSTRING (*objptr, newaddr);
|
300
|
2497 XMARK (*objptr);
|
|
2498 }
|
|
2499 else
|
9261
|
2500 XSETSTRING (*objptr, newaddr);
|
300
|
2501 }
|
|
2502 /* Store the actual size in the size field. */
|
|
2503 newaddr->size = size;
|
4139
|
2504
|
4212
|
2505 #ifdef USE_TEXT_PROPERTIES
|
4139
|
2506 /* Now that the string has been relocated, rebalance its
|
|
2507 interval tree, and update the tree's parent pointer. */
|
|
2508 if (! NULL_INTERVAL_P (newaddr->intervals))
|
|
2509 {
|
|
2510 UNMARK_BALANCE_INTERVALS (newaddr->intervals);
|
9261
|
2511 XSETSTRING (* (Lisp_Object *) &newaddr->intervals->parent,
|
|
2512 newaddr);
|
4139
|
2513 }
|
4212
|
2514 #endif /* USE_TEXT_PROPERTIES */
|
300
|
2515 }
|
|
2516 pos += STRING_FULLSIZE (size);
|
|
2517 }
|
|
2518 }
|
|
2519
|
|
2520 /* Close out the last string block still used and free any that follow. */
|
|
2521 to_sb->pos = to_pos;
|
|
2522 current_string_block = to_sb;
|
|
2523
|
|
2524 from_sb = to_sb->next;
|
|
2525 to_sb->next = 0;
|
|
2526 while (from_sb)
|
|
2527 {
|
|
2528 to_sb = from_sb->next;
|
2439
|
2529 xfree (from_sb);
|
300
|
2530 from_sb = to_sb;
|
|
2531 }
|
|
2532
|
|
2533 /* Free any empty string blocks further back in the chain.
|
|
2534 This loop will never free first_string_block, but it is very
|
|
2535 unlikely that that one will become empty, so why bother checking? */
|
|
2536
|
|
2537 from_sb = first_string_block;
|
|
2538 while (to_sb = from_sb->next)
|
|
2539 {
|
|
2540 if (to_sb->pos == 0)
|
|
2541 {
|
|
2542 if (from_sb->next = to_sb->next)
|
|
2543 from_sb->next->prev = from_sb;
|
2439
|
2544 xfree (to_sb);
|
300
|
2545 }
|
|
2546 else
|
|
2547 from_sb = to_sb;
|
|
2548 }
|
|
2549 }
|
|
2550
|
1327
|
2551 /* Debugging aids. */
|
|
2552
|
5353
|
2553 DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, 0,
|
1327
|
2554 "Return the address of the last byte Emacs has allocated, divided by 1024.\n\
|
|
2555 This may be helpful in debugging Emacs's memory usage.\n\
|
1893
|
2556 We divide the value by 1024 to make sure it fits in a Lisp integer.")
|
1327
|
2557 ()
|
|
2558 {
|
|
2559 Lisp_Object end;
|
|
2560
|
9261
|
2561 XSETINT (end, (EMACS_INT) sbrk (0) / 1024);
|
1327
|
2562
|
|
2563 return end;
|
|
2564 }
|
|
2565
|
12748
|
2566 DEFUN ("memory-use-counts", Fmemory_use_counts, Smemory_use_counts, 0, 0, 0,
|
|
2567 "Return a list of counters that measure how much consing there has been.\n\
|
|
2568 Each of these counters increments for a certain kind of object.\n\
|
|
2569 The counters wrap around from the largest positive integer to zero.\n\
|
|
2570 Garbage collection does not decrease them.\n\
|
|
2571 The elements of the value are as follows:\n\
|
|
2572 (CONSES FLOATS VECTOR-CELLS SYMBOLS STRING-CHARS MISCS INTERVALS)\n\
|
|
2573 All are in units of 1 = one object consed\n\
|
|
2574 except for VECTOR-CELLS and STRING-CHARS, which count the total length of\n\
|
|
2575 objects consed.\n\
|
|
2576 MISCS include overlays, markers, and some internal types.\n\
|
|
2577 Frames, windows, buffers, and subprocesses count as vectors\n\
|
|
2578 (but the contents of a buffer's text do not count here).")
|
|
2579 ()
|
|
2580 {
|
|
2581 Lisp_Object lisp_cons_cells_consed;
|
|
2582 Lisp_Object lisp_floats_consed;
|
|
2583 Lisp_Object lisp_vector_cells_consed;
|
|
2584 Lisp_Object lisp_symbols_consed;
|
|
2585 Lisp_Object lisp_string_chars_consed;
|
|
2586 Lisp_Object lisp_misc_objects_consed;
|
|
2587 Lisp_Object lisp_intervals_consed;
|
|
2588
|
|
2589 XSETINT (lisp_cons_cells_consed,
|
13320
|
2590 cons_cells_consed & ~(((EMACS_INT) 1) << (VALBITS - 1)));
|
12748
|
2591 XSETINT (lisp_floats_consed,
|
13320
|
2592 floats_consed & ~(((EMACS_INT) 1) << (VALBITS - 1)));
|
12748
|
2593 XSETINT (lisp_vector_cells_consed,
|
13320
|
2594 vector_cells_consed & ~(((EMACS_INT) 1) << (VALBITS - 1)));
|
12748
|
2595 XSETINT (lisp_symbols_consed,
|
13320
|
2596 symbols_consed & ~(((EMACS_INT) 1) << (VALBITS - 1)));
|
12748
|
2597 XSETINT (lisp_string_chars_consed,
|
13320
|
2598 string_chars_consed & ~(((EMACS_INT) 1) << (VALBITS - 1)));
|
12748
|
2599 XSETINT (lisp_misc_objects_consed,
|
13320
|
2600 misc_objects_consed & ~(((EMACS_INT) 1) << (VALBITS - 1)));
|
12748
|
2601 XSETINT (lisp_intervals_consed,
|
13320
|
2602 intervals_consed & ~(((EMACS_INT) 1) << (VALBITS - 1)));
|
12748
|
2603
|
|
2604 return Fcons (lisp_cons_cells_consed,
|
|
2605 Fcons (lisp_floats_consed,
|
|
2606 Fcons (lisp_vector_cells_consed,
|
|
2607 Fcons (lisp_symbols_consed,
|
|
2608 Fcons (lisp_string_chars_consed,
|
|
2609 Fcons (lisp_misc_objects_consed,
|
|
2610 Fcons (lisp_intervals_consed,
|
|
2611 Qnil)))))));
|
|
2612 }
|
1327
|
2613
|
300
|
2614 /* Initialization */
|
|
2615
|
|
2616 init_alloc_once ()
|
|
2617 {
|
|
2618 /* Used to do Vpurify_flag = Qt here, but Qt isn't set up yet! */
|
|
2619 pureptr = 0;
|
356
|
2620 #ifdef HAVE_SHM
|
|
2621 pure_size = PURESIZE;
|
|
2622 #endif
|
300
|
2623 all_vectors = 0;
|
|
2624 ignore_warnings = 1;
|
17345
|
2625 #ifdef DOUG_LEA_MALLOC
|
|
2626 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
|
|
2627 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */
|
|
2628 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */
|
|
2629 #endif
|
300
|
2630 init_strings ();
|
|
2631 init_cons ();
|
|
2632 init_symbol ();
|
|
2633 init_marker ();
|
|
2634 #ifdef LISP_FLOAT_TYPE
|
|
2635 init_float ();
|
|
2636 #endif /* LISP_FLOAT_TYPE */
|
1300
|
2637 INIT_INTERVALS;
|
|
2638
|
10673
|
2639 #ifdef REL_ALLOC
|
|
2640 malloc_hysteresis = 32;
|
|
2641 #else
|
|
2642 malloc_hysteresis = 0;
|
|
2643 #endif
|
|
2644
|
|
2645 spare_memory = (char *) malloc (SPARE_MEMORY);
|
|
2646
|
300
|
2647 ignore_warnings = 0;
|
|
2648 gcprolist = 0;
|
|
2649 staticidx = 0;
|
|
2650 consing_since_gc = 0;
|
12605
|
2651 gc_cons_threshold = 100000 * sizeof (Lisp_Object);
|
300
|
2652 #ifdef VIRT_ADDR_VARIES
|
|
2653 malloc_sbrk_unused = 1<<22; /* A large number */
|
|
2654 malloc_sbrk_used = 100000; /* as reasonable as any number */
|
|
2655 #endif /* VIRT_ADDR_VARIES */
|
|
2656 }
|
|
2657
|
|
2658 init_alloc ()
|
|
2659 {
|
|
2660 gcprolist = 0;
|
|
2661 }
|
|
2662
|
|
2663 void
|
|
2664 syms_of_alloc ()
|
|
2665 {
|
|
2666 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold,
|
|
2667 "*Number of bytes of consing between garbage collections.\n\
|
|
2668 Garbage collection can happen automatically once this many bytes have been\n\
|
|
2669 allocated since the last garbage collection. All data types count.\n\n\
|
|
2670 Garbage collection happens automatically only when `eval' is called.\n\n\
|
|
2671 By binding this temporarily to a large number, you can effectively\n\
|
|
2672 prevent garbage collection during a part of the program.");
|
|
2673
|
|
2674 DEFVAR_INT ("pure-bytes-used", &pureptr,
|
|
2675 "Number of bytes of sharable Lisp data allocated so far.");
|
|
2676
|
15960
|
2677 DEFVAR_INT ("cons-cells-consed", &cons_cells_consed,
|
|
2678 "Number of cons cells that have been consed so far.");
|
|
2679
|
|
2680 DEFVAR_INT ("floats-consed", &floats_consed,
|
|
2681 "Number of floats that have been consed so far.");
|
|
2682
|
|
2683 DEFVAR_INT ("vector-cells-consed", &vector_cells_consed,
|
|
2684 "Number of vector cells that have been consed so far.");
|
|
2685
|
|
2686 DEFVAR_INT ("symbols-consed", &symbols_consed,
|
|
2687 "Number of symbols that have been consed so far.");
|
|
2688
|
|
2689 DEFVAR_INT ("string-chars-consed", &string_chars_consed,
|
|
2690 "Number of string characters that have been consed so far.");
|
|
2691
|
|
2692 DEFVAR_INT ("misc-objects-consed", &misc_objects_consed,
|
|
2693 "Number of miscellaneous objects that have been consed so far.");
|
|
2694
|
|
2695 DEFVAR_INT ("intervals-consed", &intervals_consed,
|
|
2696 "Number of intervals that have been consed so far.");
|
|
2697
|
300
|
2698 #if 0
|
|
2699 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used,
|
|
2700 "Number of bytes of unshared memory allocated in this session.");
|
|
2701
|
|
2702 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused,
|
|
2703 "Number of bytes of unshared memory remaining available in this session.");
|
|
2704 #endif
|
|
2705
|
|
2706 DEFVAR_LISP ("purify-flag", &Vpurify_flag,
|
|
2707 "Non-nil means loading Lisp code in order to dump an executable.\n\
|
|
2708 This means that certain objects should be allocated in shared (pure) space.");
|
|
2709
|
764
|
2710 DEFVAR_INT ("undo-limit", &undo_limit,
|
300
|
2711 "Keep no more undo information once it exceeds this size.\n\
|
764
|
2712 This limit is applied when garbage collection happens.\n\
|
300
|
2713 The size is counted as the number of bytes occupied,\n\
|
|
2714 which includes both saved text and other data.");
|
764
|
2715 undo_limit = 20000;
|
300
|
2716
|
764
|
2717 DEFVAR_INT ("undo-strong-limit", &undo_strong_limit,
|
300
|
2718 "Don't keep more than this much size of undo information.\n\
|
|
2719 A command which pushes past this size is itself forgotten.\n\
|
764
|
2720 This limit is applied when garbage collection happens.\n\
|
300
|
2721 The size is counted as the number of bytes occupied,\n\
|
|
2722 which includes both saved text and other data.");
|
764
|
2723 undo_strong_limit = 30000;
|
300
|
2724
|
14959
|
2725 DEFVAR_BOOL ("garbage-collection-messages", &garbage_collection_messages,
|
|
2726 "Non-nil means display messages at start and end of garbage collection.");
|
|
2727 garbage_collection_messages = 0;
|
|
2728
|
6116
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2729 /* We build this in advance because if we wait until we need it, we might
|
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2730 not be able to allocate the memory to hold it. */
|
6133
|
2731 memory_signal_data
|
10673
|
2732 = Fcons (Qerror, Fcons (build_string ("Memory exhausted--use M-x save-some-buffers RET"), Qnil));
|
6116
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2733 staticpro (&memory_signal_data);
|
64417bbbb128
(memory_full): Use new variable memory_signal_data with precomputed value
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2734
|
11374
|
2735 staticpro (&Qgc_cons_threshold);
|
|
2736 Qgc_cons_threshold = intern ("gc-cons-threshold");
|
|
2737
|
13219
|
2738 staticpro (&Qchar_table_extra_slots);
|
|
2739 Qchar_table_extra_slots = intern ("char-table-extra-slots");
|
|
2740
|
300
|
2741 defsubr (&Scons);
|
|
2742 defsubr (&Slist);
|
|
2743 defsubr (&Svector);
|
|
2744 defsubr (&Smake_byte_code);
|
|
2745 defsubr (&Smake_list);
|
|
2746 defsubr (&Smake_vector);
|
13141
|
2747 defsubr (&Smake_char_table);
|
300
|
2748 defsubr (&Smake_string);
|
13141
|
2749 defsubr (&Smake_bool_vector);
|
300
|
2750 defsubr (&Smake_symbol);
|
|
2751 defsubr (&Smake_marker);
|
|
2752 defsubr (&Spurecopy);
|
|
2753 defsubr (&Sgarbage_collect);
|
1327
|
2754 defsubr (&Smemory_limit);
|
12748
|
2755 defsubr (&Smemory_use_counts);
|
300
|
2756 }
|