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