0
|
1 /* Storage allocation and gc for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994
|
|
3 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5 Copyright (C) 1995, 1996 Ben Wing.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: FSF 19.28, Mule 2.0. Substantially different from
|
|
25 FSF. */
|
|
26
|
|
27 /* Authorship:
|
|
28
|
|
29 FSF: Original version; a long time ago.
|
|
30 Mly: Significantly rewritten to use new 3-bit tags and
|
|
31 nicely abstracted object definitions, for 19.8.
|
|
32 JWZ: Improved code to keep track of purespace usage and
|
|
33 issue nice purespace and GC stats.
|
|
34 Ben Wing: Cleaned up frob-block lrecord code, added error-checking
|
|
35 and various changes for Mule, for 19.12.
|
|
36 Added bit vectors for 19.13.
|
|
37 Added lcrecord lists for 19.14.
|
|
38 */
|
|
39
|
|
40 #include <config.h>
|
|
41 #include "lisp.h"
|
|
42
|
|
43 #ifndef standalone
|
|
44 #include "backtrace.h"
|
|
45 #include "buffer.h"
|
|
46 #include "bytecode.h"
|
|
47 #include "device.h"
|
|
48 #include "elhash.h"
|
|
49 #include "events.h"
|
|
50 #include "extents.h"
|
|
51 #include "frame.h"
|
|
52 #include "glyphs.h"
|
|
53 #include "redisplay.h"
|
|
54 #include "specifier.h"
|
|
55 #include "window.h"
|
|
56 #endif
|
|
57
|
|
58 /* #define GDB_SUCKS */
|
|
59
|
|
60 /* #define VERIFY_STRING_CHARS_INTEGRITY */
|
|
61
|
|
62 /* Define this to see where all that space is going... */
|
|
63 #define PURESTAT
|
|
64
|
|
65 /* Define this to use malloc/free with no freelist for all datatypes,
|
|
66 the hope being that some debugging tools may help detect
|
|
67 freed memory references */
|
|
68 /* #define ALLOC_NO_POOLS */
|
|
69
|
|
70 #include "puresize.h"
|
|
71
|
|
72 #ifdef DEBUG_XEMACS
|
|
73 int debug_allocation;
|
|
74
|
|
75 int debug_allocation_backtrace_length;
|
|
76 #endif
|
|
77
|
|
78 /* Number of bytes of consing done since the last gc */
|
|
79 EMACS_INT consing_since_gc;
|
|
80 #ifdef EMACS_BTL
|
|
81 extern void cadillac_record_backtrace ();
|
|
82 #define INCREMENT_CONS_COUNTER_1(size) \
|
|
83 do { \
|
|
84 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
|
|
85 consing_since_gc += __sz__; \
|
|
86 cadillac_record_backtrace (2, __sz__); \
|
|
87 } while (0)
|
|
88 #else
|
|
89 #define INCREMENT_CONS_COUNTER_1(size) (consing_since_gc += (size))
|
|
90 #endif
|
|
91
|
|
92 #define debug_allocation_backtrace() \
|
|
93 do { \
|
|
94 if (debug_allocation_backtrace_length > 0) \
|
|
95 debug_short_backtrace (debug_allocation_backtrace_length); \
|
|
96 } while (0)
|
|
97
|
|
98 #ifdef DEBUG_XEMACS
|
|
99 #define INCREMENT_CONS_COUNTER(foosize, type) \
|
|
100 do { \
|
|
101 if (debug_allocation) \
|
|
102 { \
|
|
103 stderr_out ("allocating %s (size %ld)\n", type, (long)foosize); \
|
|
104 debug_allocation_backtrace (); \
|
|
105 } \
|
|
106 INCREMENT_CONS_COUNTER_1 (foosize); \
|
|
107 } while (0)
|
|
108 #define NOSEEUM_INCREMENT_CONS_COUNTER(foosize, type) \
|
|
109 do { \
|
|
110 if (debug_allocation > 1) \
|
|
111 { \
|
|
112 stderr_out ("allocating noseeum %s (size %ld)\n", type, (long)foosize); \
|
|
113 debug_allocation_backtrace (); \
|
|
114 } \
|
|
115 INCREMENT_CONS_COUNTER_1 (foosize); \
|
|
116 } while (0)
|
|
117 #else
|
|
118 #define INCREMENT_CONS_COUNTER(size, type) INCREMENT_CONS_COUNTER_1 (size)
|
|
119 #define NOSEEUM_INCREMENT_CONS_COUNTER(size, type) \
|
|
120 INCREMENT_CONS_COUNTER_1 (size)
|
|
121 #endif
|
|
122
|
|
123 #define DECREMENT_CONS_COUNTER(size) \
|
|
124 do { \
|
|
125 EMACS_INT __sz__ = ((EMACS_INT) (size)); \
|
|
126 if (consing_since_gc >= __sz__) \
|
|
127 consing_since_gc -= __sz__; \
|
|
128 else \
|
|
129 consing_since_gc = 0; \
|
|
130 } while (0)
|
|
131
|
|
132 /* Number of bytes of consing since gc before another gc should be done. */
|
|
133 EMACS_INT gc_cons_threshold;
|
|
134
|
|
135 /* Nonzero during gc */
|
|
136 int gc_in_progress;
|
|
137
|
|
138 /* Number of times GC has happened at this level or below.
|
|
139 * Level 0 is most volatile, contrary to usual convention.
|
|
140 * (Of course, there's only one level at present) */
|
|
141 EMACS_INT gc_generation_number[1];
|
|
142
|
|
143 /* This is just for use by the printer, to allow things to print uniquely */
|
|
144 static int lrecord_uid_counter;
|
|
145
|
|
146 /* Nonzero when calling certain hooks or doing other things where
|
|
147 a GC would be bad */
|
|
148 int gc_currently_forbidden;
|
|
149
|
|
150 /* Hooks. */
|
|
151 Lisp_Object Vpre_gc_hook, Qpre_gc_hook;
|
|
152 Lisp_Object Vpost_gc_hook, Qpost_gc_hook;
|
|
153
|
|
154 /* "Garbage collecting" */
|
|
155 Lisp_Object Vgc_message;
|
|
156 Lisp_Object Vgc_pointer_glyph;
|
|
157 static CONST char gc_default_message[] = "Garbage collecting";
|
|
158 Lisp_Object Qgarbage_collecting;
|
|
159
|
|
160 #ifndef VIRT_ADDR_VARIES
|
|
161 extern
|
|
162 #endif /* VIRT_ADDR_VARIES */
|
|
163 EMACS_INT malloc_sbrk_used;
|
|
164
|
|
165 #ifndef VIRT_ADDR_VARIES
|
|
166 extern
|
|
167 #endif /* VIRT_ADDR_VARIES */
|
|
168 EMACS_INT malloc_sbrk_unused;
|
|
169
|
|
170 /* Non-zero means defun should do purecopy on the function definition */
|
|
171 int purify_flag;
|
|
172
|
|
173 extern Lisp_Object pure[];/* moved to pure.c to speed incremental linking */
|
|
174
|
|
175 #define PUREBEG ((unsigned char *) pure)
|
|
176
|
|
177 /* Index in pure at which next pure object will be allocated. */
|
|
178 static long pureptr;
|
|
179
|
|
180 #define PURIFIED(ptr) \
|
|
181 ((PNTR_COMPARISON_TYPE) (ptr) < \
|
|
182 (PNTR_COMPARISON_TYPE) (PUREBEG + PURESIZE) && \
|
|
183 (PNTR_COMPARISON_TYPE) (ptr) >= \
|
|
184 (PNTR_COMPARISON_TYPE) PUREBEG)
|
|
185
|
|
186 /* Non-zero if pureptr > PURESIZE; accounts for excess purespace needs. */
|
|
187 static long pure_lossage;
|
|
188
|
|
189 #ifdef ERROR_CHECK_TYPECHECK
|
|
190
|
|
191 Error_behavior ERROR_ME, ERROR_ME_NOT, ERROR_ME_WARN;
|
|
192
|
|
193 #endif
|
|
194
|
|
195 int
|
|
196 purified (Lisp_Object obj)
|
|
197 {
|
|
198 if (!POINTER_TYPE_P (XGCTYPE (obj)))
|
|
199 return (0);
|
|
200 return (PURIFIED (XPNTR (obj)));
|
|
201 }
|
|
202
|
|
203 int
|
|
204 purespace_usage (void)
|
|
205 {
|
|
206 return (int) pureptr;
|
|
207 }
|
|
208
|
|
209 static int
|
|
210 check_purespace (EMACS_INT size)
|
|
211 {
|
|
212 if (pure_lossage)
|
|
213 {
|
|
214 pure_lossage += size;
|
|
215 return (0);
|
|
216 }
|
|
217 else if (pureptr + size > PURESIZE)
|
|
218 {
|
|
219 message ("\nERROR: Pure Lisp storage exhausted!\n");
|
|
220 pure_lossage = size;
|
|
221 return (0);
|
|
222 }
|
|
223 else
|
|
224 return (1);
|
|
225 }
|
|
226
|
|
227
|
|
228
|
|
229 #ifndef PURESTAT
|
|
230
|
|
231 #define bump_purestat(p,b) do {} while (0) /* Do nothing */
|
|
232
|
|
233 #else /* PURESTAT */
|
|
234
|
|
235 static int purecopying_for_bytecode;
|
|
236
|
|
237 static int pure_sizeof (Lisp_Object /*, int recurse */);
|
|
238
|
|
239 /* Keep statistics on how much of what is in purespace */
|
|
240 struct purestat
|
|
241 {
|
|
242 int nobjects;
|
|
243 int nbytes;
|
|
244 CONST char *name;
|
|
245 };
|
|
246
|
|
247 #define FMH(s,n) static struct purestat s = { 0, 0, n }
|
|
248 FMH (purestat_cons, "cons cells:");
|
|
249 FMH (purestat_float, "float objects:");
|
|
250 FMH (purestat_string_pname, "symbol-name strings:");
|
|
251 FMH (purestat_bytecode, "compiled-function objects:");
|
|
252 FMH (purestat_string_bytecodes, "byte-code strings:");
|
|
253 FMH (purestat_vector_bytecode_constants, "byte-constant vectors:");
|
|
254 FMH (purestat_string_interactive, "interactive strings:");
|
|
255 #ifdef I18N3
|
|
256 FMH (purestat_string_domain, "domain strings:");
|
|
257 #endif
|
|
258 FMH (purestat_string_documentation, "documentation strings:");
|
|
259 FMH (purestat_string_other_function, "other function strings:");
|
|
260 FMH (purestat_vector_other, "other vectors:");
|
|
261 FMH (purestat_string_other, "other strings:");
|
|
262 FMH (purestat_string_all, "all strings:");
|
|
263 FMH (purestat_vector_all, "all vectors:");
|
|
264
|
|
265 static struct purestat *purestats[] =
|
|
266 {
|
|
267 &purestat_cons,
|
|
268 &purestat_float,
|
|
269 &purestat_string_pname,
|
|
270 &purestat_bytecode,
|
|
271 &purestat_string_bytecodes,
|
|
272 &purestat_vector_bytecode_constants,
|
|
273 &purestat_string_interactive,
|
|
274 #ifdef I18N3
|
|
275 &purestat_string_domain,
|
|
276 #endif
|
|
277 &purestat_string_documentation,
|
|
278 &purestat_string_other_function,
|
|
279 &purestat_vector_other,
|
|
280 &purestat_string_other,
|
|
281 0,
|
|
282 &purestat_string_all,
|
|
283 &purestat_vector_all
|
|
284 };
|
|
285 #undef FMH
|
|
286
|
|
287 static void
|
|
288 bump_purestat (struct purestat *purestat, int nbytes)
|
|
289 {
|
|
290 if (pure_lossage) return;
|
|
291 purestat->nobjects += 1;
|
|
292 purestat->nbytes += nbytes;
|
|
293 }
|
|
294 #endif /* PURESTAT */
|
|
295
|
|
296
|
|
297 /* Maximum amount of C stack to save when a GC happens. */
|
|
298
|
|
299 #ifndef MAX_SAVE_STACK
|
|
300 #define MAX_SAVE_STACK 16000
|
|
301 #endif
|
|
302
|
|
303 /* Buffer in which we save a copy of the C stack at each GC. */
|
|
304
|
|
305 static char *stack_copy;
|
|
306 static int stack_copy_size;
|
|
307
|
|
308 /* Non-zero means ignore malloc warnings. Set during initialization. */
|
|
309 int ignore_malloc_warnings;
|
|
310
|
|
311
|
|
312 static void *breathing_space;
|
|
313
|
|
314 void
|
|
315 release_breathing_space (void)
|
|
316 {
|
|
317 if (breathing_space)
|
|
318 {
|
|
319 void *tmp = breathing_space;
|
|
320 breathing_space = 0;
|
|
321 xfree (tmp);
|
|
322 }
|
|
323 }
|
|
324
|
|
325 /* malloc calls this if it finds we are near exhausting storage */
|
|
326 void
|
|
327 malloc_warning (CONST char *str)
|
|
328 {
|
|
329 if (ignore_malloc_warnings)
|
|
330 return;
|
|
331
|
|
332 warn_when_safe
|
|
333 (Qmemory, Qcritical,
|
|
334 "%s\n"
|
|
335 "Killing some buffers may delay running out of memory.\n"
|
|
336 "However, certainly by the time you receive the 95%% warning,\n"
|
|
337 "you should clean up, kill this Emacs, and start a new one.",
|
|
338 str);
|
|
339 }
|
|
340
|
|
341 /* Called if malloc returns zero */
|
|
342 DOESNT_RETURN
|
|
343 memory_full (void)
|
|
344 {
|
|
345 /* Force a GC next time eval is called.
|
|
346 It's better to loop garbage-collecting (we might reclaim enough
|
|
347 to win) than to loop beeping and barfing "Memory exhausted"
|
|
348 */
|
|
349 consing_since_gc = gc_cons_threshold + 1;
|
|
350 release_breathing_space ();
|
|
351
|
|
352 #ifndef standalone
|
|
353 /* Flush some histories which might conceivably contain
|
|
354 * garbalogical inhibitors */
|
|
355 if (!NILP (Fboundp (Qvalues)))
|
|
356 Fset (Qvalues, Qnil);
|
|
357 Vcommand_history = Qnil;
|
|
358 #endif
|
|
359
|
|
360 error ("Memory exhausted");
|
|
361 }
|
|
362
|
|
363 /* like malloc and realloc but check for no memory left, and block input. */
|
|
364
|
|
365 void *
|
|
366 xmalloc (int size)
|
|
367 {
|
|
368 void *val;
|
|
369
|
|
370 val = (void *) malloc (size);
|
|
371
|
|
372 if (!val && (size != 0)) memory_full ();
|
|
373 return val;
|
|
374 }
|
|
375
|
|
376 void *
|
|
377 xmalloc_and_zero (int size)
|
|
378 {
|
|
379 void *val = xmalloc (size);
|
|
380 memset (val, 0, size);
|
|
381 return val;
|
|
382 }
|
|
383
|
|
384 void *
|
|
385 xrealloc (void *block, int size)
|
|
386 {
|
|
387 void *val;
|
|
388
|
|
389 /* We must call malloc explicitly when BLOCK is 0, since some
|
|
390 reallocs don't do this. */
|
|
391 if (! block)
|
|
392 val = (void *) malloc (size);
|
|
393 else
|
|
394 val = (void *) realloc (block, size);
|
|
395
|
|
396 if (!val && (size != 0)) memory_full ();
|
|
397 return val;
|
|
398 }
|
|
399
|
|
400 void
|
|
401 #ifdef ERROR_CHECK_MALLOC
|
|
402 xfree_1 (void *block)
|
|
403 #else
|
|
404 xfree (void *block)
|
|
405 #endif
|
|
406 {
|
|
407 #ifdef ERROR_CHECK_MALLOC
|
|
408 /* Unbelievably, calling free() on 0xDEADBEEF doesn't cause an
|
|
409 error until much later on for many system mallocs, such as
|
|
410 the one that comes with Solaris 2.3. FMH!! */
|
|
411 assert (block != (void *) 0xDEADBEEF);
|
|
412 assert (block);
|
|
413 #endif
|
|
414 free (block);
|
|
415 }
|
|
416
|
|
417 #if INTBITS == 32
|
|
418 # define FOUR_BYTE_TYPE unsigned int
|
|
419 #elif LONGBITS == 32
|
|
420 # define FOUR_BYTE_TYPE unsigned long
|
|
421 #elif SHORTBITS == 32
|
|
422 # define FOUR_BYTE_TYPE unsigned short
|
|
423 #else
|
|
424 What kind of strange-ass system are we running on?
|
|
425 #endif
|
|
426
|
|
427 #ifdef ERROR_CHECK_GC
|
|
428
|
|
429 #ifdef WORDS_BIGENDIAN
|
|
430 static unsigned char deadbeef_as_char[] = {0xDE, 0xAD, 0xBE, 0xEF};
|
|
431 #else
|
|
432 static unsigned char deadbeef_as_char[] = {0xEF, 0xBE, 0xAD, 0xDE};
|
|
433 #endif
|
|
434
|
|
435 static void
|
|
436 deadbeef_memory (void *ptr, unsigned long size)
|
|
437 {
|
|
438 unsigned long long_length = size / sizeof (FOUR_BYTE_TYPE);
|
|
439 unsigned long i;
|
|
440 unsigned long bytes_left_over = size - sizeof (FOUR_BYTE_TYPE) * long_length;
|
|
441
|
|
442 for (i = 0; i < long_length; i++)
|
|
443 ((FOUR_BYTE_TYPE *) ptr)[i] = 0xdeadbeef;
|
|
444 for (i = i; i < bytes_left_over; i++)
|
|
445 ((unsigned char *) ptr + long_length)[i] = deadbeef_as_char[i];
|
|
446 }
|
|
447
|
|
448 #else
|
|
449
|
|
450 #define deadbeef_memory(ptr, size)
|
|
451
|
|
452 #endif
|
|
453
|
|
454 char *
|
|
455 xstrdup (CONST char *str)
|
|
456 {
|
|
457 char *val;
|
|
458 int len = strlen (str) + 1; /* for stupid terminating 0 */
|
|
459
|
|
460 val = xmalloc (len);
|
|
461 if (val == 0) return 0;
|
|
462 memcpy (val, str, len);
|
|
463 return (val);
|
|
464 }
|
|
465
|
|
466 #ifdef NEED_STRDUP
|
|
467 char *
|
|
468 strdup (CONST char *s)
|
|
469 {
|
|
470 return xstrdup (s);
|
|
471 }
|
|
472 #endif /* NEED_STRDUP */
|
|
473
|
|
474
|
|
475 static void *
|
|
476 allocate_lisp_storage (int size)
|
|
477 {
|
|
478 void *p = xmalloc (size);
|
|
479 char *lim = ((char *) p) + size;
|
|
480 Lisp_Object val = Qnil;
|
|
481
|
|
482 XSETCONS (val, lim);
|
|
483 if ((char *) XCONS (val) != lim)
|
|
484 {
|
|
485 xfree (p);
|
|
486 memory_full ();
|
|
487 }
|
|
488 return (p);
|
|
489 }
|
|
490
|
|
491
|
|
492 #define MARKED_RECORD_HEADER_P(lheader) \
|
|
493 (((lheader)->implementation->finalizer) == this_marks_a_marked_record)
|
|
494 #define UNMARKABLE_RECORD_HEADER_P(lheader) \
|
|
495 (((lheader)->implementation->marker) == this_one_is_unmarkable)
|
|
496 #define MARK_RECORD_HEADER(lheader) \
|
|
497 do { (((lheader)->implementation)++); } while (0)
|
|
498 #define UNMARK_RECORD_HEADER(lheader) \
|
|
499 do { (((lheader)->implementation)--); } while (0)
|
|
500
|
|
501
|
|
502 /* lrecords are chained together through their "next.v" field.
|
|
503 * After doing the mark phase, the GC will walk this linked
|
|
504 * list and free any record which hasn't been marked
|
|
505 */
|
|
506 static struct lcrecord_header *all_lcrecords;
|
|
507
|
|
508 void *
|
|
509 alloc_lcrecord (int size, CONST struct lrecord_implementation *implementation)
|
|
510 {
|
|
511 struct lcrecord_header *lcheader;
|
|
512
|
|
513 if (size <= 0) abort ();
|
|
514 if (implementation->static_size == 0)
|
|
515 {
|
|
516 if (!implementation->size_in_bytes_method)
|
|
517 abort ();
|
|
518 }
|
|
519 else if (implementation->static_size != size)
|
|
520 abort ();
|
|
521
|
|
522 lcheader = allocate_lisp_storage (size);
|
|
523 lcheader->lheader.implementation = implementation;
|
|
524 lcheader->next = all_lcrecords;
|
|
525 #if 1 /* mly prefers to see small ID numbers */
|
|
526 lcheader->uid = lrecord_uid_counter++;
|
|
527 #else /* jwz prefers to see real addrs */
|
|
528 lcheader->uid = (int) &lcheader;
|
|
529 #endif
|
|
530 lcheader->free = 0;
|
|
531 all_lcrecords = lcheader;
|
|
532 INCREMENT_CONS_COUNTER (size, implementation->name);
|
|
533 return (lcheader);
|
|
534 }
|
|
535
|
|
536 #if 0 /* Presently unused */
|
|
537 /* Very, very poor man's EGC?
|
|
538 * This may be slow and thrash pages all over the place.
|
|
539 * Only call it if you really feel you must (and if the
|
|
540 * lrecord was fairly recently allocated).
|
|
541 * Otherwise, just let the GC do its job -- that's what it's there for
|
|
542 */
|
|
543 void
|
|
544 free_lcrecord (struct lcrecord_header *lcrecord)
|
|
545 {
|
|
546 if (all_lcrecords == lcrecord)
|
|
547 {
|
|
548 all_lcrecords = lcrecord->next;
|
|
549 }
|
|
550 else
|
|
551 {
|
|
552 struct lrecord_header *header = all_lcrecords;
|
|
553 for (;;)
|
|
554 {
|
|
555 struct lrecord_header *next = header->next;
|
|
556 if (next == lcrecord)
|
|
557 {
|
|
558 header->next = lrecord->next;
|
|
559 break;
|
|
560 }
|
|
561 else if (next == 0)
|
|
562 abort ();
|
|
563 else
|
|
564 header = next;
|
|
565 }
|
|
566 }
|
|
567 if (lrecord->implementation->finalizer)
|
|
568 ((lrecord->implementation->finalizer) (lrecord, 0));
|
|
569 xfree (lrecord);
|
|
570 return;
|
|
571 }
|
|
572 #endif /* Unused */
|
|
573
|
|
574
|
|
575 static void
|
|
576 disksave_object_finalization_1 (void)
|
|
577 {
|
|
578 struct lcrecord_header *header;
|
|
579
|
|
580 for (header = all_lcrecords; header; header = header->next)
|
|
581 {
|
|
582 if (header->lheader.implementation->finalizer && !header->free)
|
|
583 ((header->lheader.implementation->finalizer) (header, 1));
|
|
584 }
|
|
585 }
|
|
586
|
|
587
|
|
588 /* This must not be called -- it just serves as for EQ test
|
|
589 * If lheader->implementation->finalizer is this_marks_a_marked_record,
|
|
590 * then lrecord has been marked by the GC sweeper
|
|
591 * header->implementation is put back to its correct value by
|
|
592 * sweep_records */
|
|
593 void
|
|
594 this_marks_a_marked_record (void *dummy0, int dummy1)
|
|
595 {
|
|
596 abort ();
|
|
597 }
|
|
598
|
|
599 /* Semi-kludge -- lrecord_symbol_value_forward objects get stuck
|
|
600 in CONST space and you get SEGV's if you attempt to mark them.
|
|
601 This sits in lheader->implementation->marker. */
|
|
602
|
|
603 Lisp_Object
|
|
604 this_one_is_unmarkable (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
605 {
|
|
606 abort ();
|
|
607 return Qnil;
|
|
608 }
|
|
609
|
|
610 /* XGCTYPE for records */
|
|
611 int
|
|
612 gc_record_type_p (Lisp_Object frob, CONST struct lrecord_implementation *type)
|
|
613 {
|
|
614 return (XGCTYPE (frob) == Lisp_Record
|
|
615 && (XRECORD_LHEADER (frob)->implementation == type
|
|
616 || XRECORD_LHEADER (frob)->implementation == type + 1));
|
|
617 }
|
|
618
|
|
619
|
|
620 /**********************************************************************/
|
|
621 /* Fixed-size type macros */
|
|
622 /**********************************************************************/
|
|
623
|
|
624 /* For fixed-size types that are commonly used, we malloc() large blocks
|
|
625 of memory at a time and subdivide them into chunks of the correct
|
|
626 size for an object of that type. This is more efficient than
|
|
627 malloc()ing each object separately because we save on malloc() time
|
|
628 and overhead due to the fewer number of malloc()ed blocks, and
|
|
629 also because we don't need any extra pointers within each object
|
|
630 to keep them threaded together for GC purposes. For less common
|
|
631 (and frequently large-size) types, we use lcrecords, which are
|
|
632 malloc()ed individually and chained together through a pointer
|
|
633 in the lcrecord header. lcrecords do not need to be fixed-size
|
|
634 (i.e. two objects of the same type need not have the same size;
|
|
635 however, the size of a particular object cannot vary dynamically).
|
|
636 It is also much easier to create a new lcrecord type because no
|
|
637 additional code needs to be added to alloc.c. Finally, lcrecords
|
|
638 may be more efficient when there are only a small number of them.
|
|
639
|
|
640 The types that are stored in these large blocks (or "frob blocks")
|
|
641 are cons, float, compiled-function, symbol, marker, extent, event,
|
|
642 and string.
|
|
643
|
|
644 Note that strings are special in that they are actually stored in
|
|
645 two parts: a structure containing information about the string, and
|
|
646 the actual data associated with the string. The former structure
|
|
647 (a struct Lisp_String) is a fixed-size structure and is managed the
|
|
648 same way as all the other such types. This structure contains a
|
|
649 pointer to the actual string data, which is stored in structures of
|
|
650 type struct string_chars_block. Each string_chars_block consists
|
|
651 of a pointer to a struct Lisp_String, followed by the data for that
|
|
652 string, followed by another pointer to a struct Lisp_String,
|
|
653 followed by the data for that string, etc. At GC time, the data in
|
|
654 these blocks is compacted by searching sequentially through all the
|
|
655 blocks and compressing out any holes created by unmarked strings.
|
|
656 Strings that are more than a certain size (bigger than the size of
|
|
657 a string_chars_block, although something like half as big might
|
|
658 make more sense) are malloc()ed separately and not stored in
|
|
659 string_chars_blocks. Furthermore, no one string stretches across
|
|
660 two string_chars_blocks.
|
|
661
|
|
662 Vectors are each malloc()ed separately, similar to lcrecords.
|
|
663
|
|
664 In the following discussion, we use conses, but it applies equally
|
|
665 well to the other fixed-size types.
|
|
666
|
|
667 We store cons cells inside of cons_blocks, allocating a new
|
|
668 cons_block with malloc() whenever necessary. Cons cells reclaimed
|
|
669 by GC are put on a free list to be reallocated before allocating
|
|
670 any new cons cells from the latest cons_block. Each cons_block is
|
|
671 just under 2^n - MALLOC_OVERHEAD bytes long, since malloc (at least
|
|
672 the versions in malloc.c and gmalloc.c) really allocates in units
|
|
673 of powers of two and uses 4 bytes for its own overhead.
|
|
674
|
|
675 What GC actually does is to search through all the cons_blocks,
|
|
676 from the most recently allocated to the oldest, and put all
|
|
677 cons cells that are not marked (whether or not they're already
|
|
678 free) on a cons_free_list. The cons_free_list is a stack, and
|
|
679 so the cons cells in the oldest-allocated cons_block end up
|
|
680 at the head of the stack and are the first to be reallocated.
|
|
681 If any cons_block is entirely free, it is freed with free()
|
|
682 and its cons cells removed from the cons_free_list. Because
|
|
683 the cons_free_list ends up basically in memory order, we have
|
|
684 a high locality of reference (assuming a reasonable turnover
|
|
685 of allocating and freeing) and have a reasonable probability
|
|
686 of entirely freeing up cons_blocks that have been more recently
|
|
687 allocated. This stage is called the "sweep stage" of GC, and
|
|
688 is executed after the "mark stage", which involves starting
|
|
689 from all places that are known to point to in-use Lisp objects
|
|
690 (e.g. the obarray, where are all symbols are stored; the
|
|
691 current catches and condition-cases; the backtrace list of
|
|
692 currently executing functions; the gcpro list; etc.) and
|
|
693 recursively marking all objects that are accessible.
|
|
694
|
|
695 At the beginning of the sweep stage, the conses in the cons
|
|
696 blocks are in one of three states: in use and marked, in use
|
|
697 but not marked, and not in use (already freed). Any conses
|
|
698 that are marked have been marked in the mark stage just
|
|
699 executed, because as part of the sweep stage we unmark any
|
|
700 marked objects. The way we tell whether or not a cons cell
|
|
701 is in use is through the FREE_STRUCT_P macro. This basically
|
|
702 looks at the first 4 bytes (or however many bytes a pointer
|
|
703 fits in) to see if all the bits in those bytes are 1. The
|
|
704 resulting value (0xFFFFFFFF) is not a valid pointer and is
|
|
705 not a valid Lisp_Object. All current fixed-size types have
|
|
706 a pointer or Lisp_Object as their first element with the
|
|
707 exception of strings; they have a size value, which can
|
|
708 never be less than zero, and so 0xFFFFFFFF is invalid for
|
|
709 strings as well. Now assuming that a cons cell is in use,
|
|
710 the way we tell whether or not it is marked is to look at
|
|
711 the mark bit of its car (each Lisp_Object has one bit
|
|
712 reserved as a mark bit, in case it's needed). Note that
|
|
713 different types of objects use different fields to indicate
|
|
714 whether the object is marked, but the principle is the same.
|
|
715
|
|
716 Conses on the free_cons_list are threaded through a pointer
|
|
717 stored in the bytes directly after the bytes that are set
|
|
718 to 0xFFFFFFFF (we cannot overwrite these because the cons
|
|
719 is still in a cons_block and needs to remain marked as
|
|
720 not in use for the next time that GC happens). This
|
|
721 implies that all fixed-size types must be at least big
|
|
722 enough to store two pointers, which is indeed the case
|
|
723 for all current fixed-size types.
|
|
724
|
|
725 Some types of objects need additional "finalization" done
|
|
726 when an object is converted from in use to not in use;
|
|
727 this is the purpose of the ADDITIONAL_FREE_type macro.
|
|
728 For example, markers need to be removed from the chain
|
|
729 of markers that is kept in each buffer. This is because
|
|
730 markers in a buffer automatically disappear if the marker
|
|
731 is no longer referenced anywhere (the same does not
|
|
732 apply to extents, however).
|
|
733
|
|
734 WARNING: Things are in an extremely bizarre state when
|
|
735 the ADDITIONAL_FREE_type macros are called, so beware!
|
|
736
|
|
737 When ERROR_CHECK_GC is defined, we do things differently
|
|
738 so as to maximize our chances of catching places where
|
|
739 there is insufficient GCPROing. The thing we want to
|
|
740 avoid is having an object that we're using but didn't
|
|
741 GCPRO get freed by GC and then reallocated while we're
|
|
742 in the process of using it -- this will result in something
|
|
743 seemingly unrelated getting trashed, and is extremely
|
|
744 difficult to track down. If the object gets freed but
|
|
745 not reallocated, we can usually catch this because we
|
|
746 set all bytes of a freed object to 0xDEADBEEF. (The
|
|
747 first four bytes, however, are 0xFFFFFFFF, and the next
|
|
748 four are a pointer used to chain freed objects together;
|
|
749 we play some tricks with this pointer to make it more
|
|
750 bogus, so crashes are more likely to occur right away.)
|
|
751
|
|
752 We want freed objects to stay free as long as possible,
|
|
753 so instead of doing what we do above, we maintain the
|
|
754 free objects in a first-in first-out queue. We also
|
|
755 don't recompute the free list each GC, unlike above;
|
|
756 this ensures that the queue ordering is preserved.
|
|
757 [This means that we are likely to have worse locality
|
|
758 of reference, and that we can never free a frob block
|
|
759 once it's allocated. (Even if we know that all cells
|
|
760 in it are free, there's no easy way to remove all those
|
|
761 cells from the free list because the objects on the
|
|
762 free list are unlikely to be in memory order.)]
|
|
763 Furthermore, we never take objects off the free list
|
|
764 unless there's a large number (usually 1000, but
|
|
765 varies depending on type) of them already on the list.
|
|
766 This way, we ensure that an object that gets freed will
|
|
767 remain free for the next 1000 (or whatever) times that
|
|
768 an object of that type is allocated.
|
|
769 */
|
|
770
|
|
771 #ifndef MALLOC_OVERHEAD
|
|
772 #ifdef GNU_MALLOC
|
|
773 #define MALLOC_OVERHEAD 0
|
|
774 #elif defined (rcheck)
|
|
775 #define MALLOC_OVERHEAD 20
|
|
776 #else
|
|
777 #define MALLOC_OVERHEAD 8
|
|
778 #endif
|
|
779 #endif
|
|
780
|
|
781 #ifdef ALLOC_NO_POOLS
|
|
782 # define TYPE_ALLOC_SIZE(type, structtype) 1
|
|
783 #else
|
|
784 # define TYPE_ALLOC_SIZE(type, structtype) \
|
|
785 ((2048 - MALLOC_OVERHEAD - sizeof (struct type##_block *)) \
|
|
786 / sizeof (structtype))
|
|
787 #endif
|
|
788
|
|
789 #define DECLARE_FIXED_TYPE_ALLOC(type, structtype) \
|
|
790 \
|
|
791 struct type##_block \
|
|
792 { \
|
|
793 struct type##_block *prev; \
|
|
794 structtype block[TYPE_ALLOC_SIZE (type, structtype)]; \
|
|
795 }; \
|
|
796 \
|
|
797 static struct type##_block *current_##type##_block; \
|
|
798 static int current_##type##_block_index; \
|
|
799 \
|
|
800 static structtype *type##_free_list; \
|
|
801 static structtype *type##_free_list_tail; \
|
|
802 \
|
|
803 static void \
|
|
804 init_##type##_alloc (void) \
|
|
805 { \
|
|
806 current_##type##_block = 0; \
|
|
807 current_##type##_block_index = countof (current_##type##_block->block); \
|
|
808 type##_free_list = 0; \
|
|
809 type##_free_list_tail = 0; \
|
|
810 } \
|
|
811 \
|
|
812 static int gc_count_num_##type##_in_use, gc_count_num_##type##_freelist
|
|
813
|
|
814 #define ALLOCATE_FIXED_TYPE_FROM_BLOCK(type, result) \
|
|
815 do { \
|
|
816 if (current_##type##_block_index \
|
|
817 == countof (current_##type##_block->block)) \
|
|
818 { \
|
|
819 struct type##_block *__new__ \
|
|
820 = allocate_lisp_storage (sizeof (struct type##_block)); \
|
|
821 __new__->prev = current_##type##_block; \
|
|
822 current_##type##_block = __new__; \
|
|
823 current_##type##_block_index = 0; \
|
|
824 } \
|
|
825 (result) = \
|
|
826 &(current_##type##_block->block[current_##type##_block_index++]); \
|
|
827 } while (0)
|
|
828
|
|
829 /* Allocate an instance of a type that is stored in blocks.
|
|
830 TYPE is the "name" of the type, STRUCTTYPE is the corresponding
|
|
831 structure type. */
|
|
832
|
|
833 #ifdef ERROR_CHECK_GC
|
|
834
|
|
835 /* Note: if you get crashes in this function, suspect incorrect calls
|
|
836 to free_cons() and friends. This happened once because the cons
|
|
837 cell was not GC-protected and was getting collected before
|
|
838 free_cons() was called. */
|
|
839
|
|
840 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
|
|
841 do \
|
|
842 { \
|
|
843 if (gc_count_num_##type##_freelist > \
|
|
844 MINIMUM_ALLOWED_FIXED_TYPE_CELLS_##type) \
|
|
845 { \
|
|
846 result = type##_free_list; \
|
|
847 /* Before actually using the chain pointer, we complement all its \
|
|
848 bits; see FREE_FIXED_TYPE(). */ \
|
|
849 type##_free_list = \
|
|
850 (structtype *) ~(unsigned long) \
|
|
851 (* (structtype **) ((char *) result + sizeof (void *))); \
|
|
852 gc_count_num_##type##_freelist--; \
|
|
853 } \
|
|
854 else \
|
|
855 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
|
|
856 MARK_STRUCT_AS_NOT_FREE (result); \
|
|
857 } while (0)
|
|
858
|
|
859 #else
|
|
860
|
|
861 #define ALLOCATE_FIXED_TYPE_1(type, structtype, result) \
|
|
862 do \
|
|
863 { \
|
|
864 if (type##_free_list) \
|
|
865 { \
|
|
866 result = type##_free_list; \
|
|
867 type##_free_list = \
|
|
868 * (structtype **) ((char *) result + sizeof (void *)); \
|
|
869 } \
|
|
870 else \
|
|
871 ALLOCATE_FIXED_TYPE_FROM_BLOCK (type, result); \
|
|
872 MARK_STRUCT_AS_NOT_FREE (result); \
|
|
873 } while (0)
|
|
874
|
|
875 #endif
|
|
876
|
|
877 #define ALLOCATE_FIXED_TYPE(type, structtype, result) \
|
|
878 do \
|
|
879 { \
|
|
880 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
|
|
881 INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
|
|
882 } while (0)
|
|
883
|
|
884 #define NOSEEUM_ALLOCATE_FIXED_TYPE(type, structtype, result) \
|
|
885 do \
|
|
886 { \
|
|
887 ALLOCATE_FIXED_TYPE_1 (type, structtype, result); \
|
|
888 NOSEEUM_INCREMENT_CONS_COUNTER (sizeof (structtype), #type); \
|
|
889 } while (0)
|
|
890
|
|
891 /* INVALID_POINTER_VALUE should be a value that is invalid as a pointer
|
|
892 to a Lisp object and invalid as an actual Lisp_Object value. We have
|
|
893 to make sure that this value cannot be an integer in Lisp_Object form.
|
|
894 0xFFFFFFFF could be so on a 64-bit system, so we extend it to 64 bits.
|
|
895 On a 32-bit system, the type bits will be non-zero, making the value
|
|
896 be a pointer, and the pointer will be misaligned.
|
|
897
|
|
898 Even if Emacs is run on some weirdo system that allows and allocates
|
|
899 byte-aligned pointers, this pointer is at the very top of the address
|
|
900 space and so it's almost inconceivable that it could ever be valid. */
|
|
901
|
|
902 #if INTBITS == 32
|
|
903 # define INVALID_POINTER_VALUE 0xFFFFFFFF
|
|
904 #elif INTBITS == 48
|
|
905 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFF
|
|
906 #elif INTBITS == 64
|
|
907 # define INVALID_POINTER_VALUE 0xFFFFFFFFFFFFFFFF
|
|
908 #else
|
|
909 You have some weird system and need to supply a reasonable value here.
|
|
910 #endif
|
|
911
|
|
912 #define FREE_STRUCT_P(ptr) \
|
|
913 (* (void **) ptr == (void *) INVALID_POINTER_VALUE)
|
|
914 #define MARK_STRUCT_AS_FREE(ptr) \
|
|
915 (* (void **) ptr = (void *) INVALID_POINTER_VALUE)
|
|
916 #define MARK_STRUCT_AS_NOT_FREE(ptr) \
|
|
917 (* (void **) ptr = 0)
|
|
918
|
|
919 #ifdef ERROR_CHECK_GC
|
|
920
|
|
921 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
|
|
922 do { if (type##_free_list_tail) \
|
|
923 { \
|
|
924 /* When we store the chain pointer, we complement all \
|
|
925 its bits; this should significantly increase its \
|
|
926 bogosity in case someone tries to use the value, and \
|
|
927 should make us dump faster if someone stores something \
|
|
928 over the pointer because when it gets un-complemented in \
|
|
929 ALLOCATED_FIXED_TYPE(), the resulting pointer will be \
|
|
930 extremely bogus. */ \
|
|
931 * (structtype **) \
|
|
932 ((char *) type##_free_list_tail + sizeof (void *)) = \
|
|
933 (structtype *) ~(unsigned long) ptr; \
|
|
934 } \
|
|
935 else \
|
|
936 type##_free_list = ptr; \
|
|
937 type##_free_list_tail = ptr; \
|
|
938 } while (0)
|
|
939
|
|
940 #else
|
|
941
|
|
942 #define PUT_FIXED_TYPE_ON_FREE_LIST(type, structtype, ptr) \
|
|
943 do { * (structtype **) ((char *) ptr + sizeof (void *)) = \
|
|
944 type##_free_list; \
|
|
945 type##_free_list = ptr; \
|
|
946 } while (0)
|
|
947
|
|
948 #endif
|
|
949
|
|
950 /* TYPE and STRUCTTYPE are the same as in ALLOCATE_FIXED_TYPE(). */
|
|
951
|
|
952 #define FREE_FIXED_TYPE(type, structtype, ptr) \
|
|
953 do { structtype *_weird_ = (ptr); \
|
|
954 ADDITIONAL_FREE_##type (_weird_); \
|
|
955 deadbeef_memory (ptr, sizeof (structtype)); \
|
|
956 PUT_FIXED_TYPE_ON_FREE_LIST (type, structtype, ptr); \
|
|
957 MARK_STRUCT_AS_FREE (_weird_); \
|
|
958 } while (0)
|
|
959
|
|
960 /* Like FREE_FIXED_TYPE() but used when we are explicitly
|
|
961 freeing a structure through free_cons(), free_marker(), etc.
|
|
962 rather than through the normal process of sweeping.
|
|
963 We attempt to undo the changes made to the allocation counters
|
|
964 as a result of this structure being allocated. This is not
|
|
965 completely necessary but helps keep things saner: e.g. this way,
|
|
966 repeatedly allocating and freeing a cons will not result in
|
|
967 the consing-since-gc counter advancing, which would cause a GC
|
|
968 and somewhat defeat the purpose of explicitly freeing. */
|
|
969
|
|
970 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr) \
|
|
971 do { FREE_FIXED_TYPE (type, structtype, ptr); \
|
|
972 DECREMENT_CONS_COUNTER (sizeof (structtype)); \
|
|
973 gc_count_num_##type##_freelist++; \
|
|
974 } while (0)
|
|
975
|
|
976
|
|
977
|
|
978 /**********************************************************************/
|
|
979 /* Cons allocation */
|
|
980 /**********************************************************************/
|
|
981
|
|
982 DECLARE_FIXED_TYPE_ALLOC (cons, struct Lisp_Cons);
|
|
983 /* conses are used and freed so often that we set this really high */
|
|
984 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */
|
|
985 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000
|
|
986
|
|
987 DEFUN ("cons", Fcons, Scons, 2, 2, 0 /*
|
|
988 Create a new cons, give it CAR and CDR as components, and return it.
|
|
989 */ )
|
|
990 (car, cdr)
|
|
991 Lisp_Object car, cdr;
|
|
992 {
|
|
993 /* This cannot GC. */
|
|
994 Lisp_Object val = Qnil;
|
|
995 struct Lisp_Cons *c;
|
|
996
|
|
997 ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
|
|
998 XSETCONS (val, c);
|
|
999 XCAR (val) = car;
|
|
1000 XCDR (val) = cdr;
|
|
1001 return val;
|
|
1002 }
|
|
1003
|
|
1004 /* This is identical to Fcons() but it used for conses that we're
|
|
1005 going to free later, and is useful when trying to track down
|
|
1006 "real" consing. */
|
|
1007 Lisp_Object
|
|
1008 noseeum_cons (Lisp_Object car, Lisp_Object cdr)
|
|
1009 {
|
|
1010 Lisp_Object val = Qnil;
|
|
1011 struct Lisp_Cons *c;
|
|
1012
|
|
1013 NOSEEUM_ALLOCATE_FIXED_TYPE (cons, struct Lisp_Cons, c);
|
|
1014 XSETCONS (val, c);
|
|
1015 XCAR (val) = car;
|
|
1016 XCDR (val) = cdr;
|
|
1017 return val;
|
|
1018 }
|
|
1019
|
|
1020 DEFUN ("list", Flist, Slist, 0, MANY, 0 /*
|
|
1021 Return a newly created list with specified arguments as elements.
|
|
1022 Any number of arguments, even zero arguments, are allowed.
|
|
1023 */ )
|
|
1024 (nargs, args)
|
|
1025 int nargs;
|
|
1026 Lisp_Object *args;
|
|
1027 {
|
|
1028 Lisp_Object len, val, val_tail;
|
|
1029
|
|
1030 len = make_int (nargs);
|
|
1031 val = Fmake_list (len, Qnil);
|
|
1032 val_tail = val;
|
|
1033 while (!NILP (val_tail))
|
|
1034 {
|
|
1035 XCAR (val_tail) = *args++;
|
|
1036 val_tail = XCDR (val_tail);
|
|
1037 }
|
|
1038 return val;
|
|
1039 }
|
|
1040
|
|
1041 Lisp_Object
|
|
1042 list1 (Lisp_Object obj0)
|
|
1043 {
|
|
1044 /* This cannot GC. */
|
|
1045 return (Fcons (obj0, Qnil));
|
|
1046 }
|
|
1047
|
|
1048 Lisp_Object
|
|
1049 list2 (Lisp_Object obj0, Lisp_Object obj1)
|
|
1050 {
|
|
1051 /* This cannot GC. */
|
|
1052 return Fcons (obj0, list1 (obj1));
|
|
1053 }
|
|
1054
|
|
1055 Lisp_Object
|
|
1056 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1057 {
|
|
1058 /* This cannot GC. */
|
|
1059 return Fcons (obj0, list2 (obj1, obj2));
|
|
1060 }
|
|
1061
|
|
1062 static Lisp_Object
|
|
1063 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1064 {
|
|
1065 /* This cannot GC. */
|
|
1066 return Fcons (obj0, Fcons (obj1, obj2));
|
|
1067 }
|
|
1068
|
|
1069 Lisp_Object
|
|
1070 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3)
|
|
1071 {
|
|
1072 /* This cannot GC. */
|
|
1073 return Fcons (obj0, list3 (obj1, obj2, obj3));
|
|
1074 }
|
|
1075
|
|
1076 Lisp_Object
|
|
1077 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
|
|
1078 Lisp_Object obj4)
|
|
1079 {
|
|
1080 /* This cannot GC. */
|
|
1081 return Fcons (obj0, list4 (obj1, obj2, obj3, obj4));
|
|
1082 }
|
|
1083
|
|
1084 Lisp_Object
|
|
1085 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
|
|
1086 Lisp_Object obj4, Lisp_Object obj5)
|
|
1087 {
|
|
1088 /* This cannot GC. */
|
|
1089 return Fcons (obj0, list5 (obj1, obj2, obj3, obj4, obj5));
|
|
1090 }
|
|
1091
|
|
1092 DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0 /*
|
|
1093 Return a newly created list of length LENGTH, with each element being INIT.
|
|
1094 */ )
|
|
1095 (length, init)
|
|
1096 Lisp_Object length, init;
|
|
1097 {
|
|
1098 Lisp_Object val;
|
|
1099 int size;
|
|
1100
|
|
1101 CHECK_NATNUM (length);
|
|
1102 size = XINT (length);
|
|
1103
|
|
1104 val = Qnil;
|
|
1105 while (size-- > 0)
|
|
1106 val = Fcons (init, val);
|
|
1107 return val;
|
|
1108 }
|
|
1109
|
|
1110
|
|
1111 /**********************************************************************/
|
|
1112 /* Float allocation */
|
|
1113 /**********************************************************************/
|
|
1114
|
|
1115 #ifdef LISP_FLOAT_TYPE
|
|
1116
|
|
1117 DECLARE_FIXED_TYPE_ALLOC (float, struct Lisp_Float);
|
|
1118 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
|
|
1119
|
|
1120 Lisp_Object
|
|
1121 make_float (double float_value)
|
|
1122 {
|
|
1123 Lisp_Object val;
|
|
1124 struct Lisp_Float *f;
|
|
1125
|
|
1126 ALLOCATE_FIXED_TYPE (float, struct Lisp_Float, f);
|
|
1127 f->lheader.implementation = lrecord_float;
|
|
1128 float_next (f) = ((struct Lisp_Float *) -1);
|
|
1129 float_data (f) = float_value;
|
|
1130 XSETFLOAT (val, f);
|
|
1131 return (val);
|
|
1132 }
|
|
1133
|
|
1134 #endif /* LISP_FLOAT_TYPE */
|
|
1135
|
|
1136
|
|
1137 /**********************************************************************/
|
|
1138 /* Vector allocation */
|
|
1139 /**********************************************************************/
|
|
1140
|
|
1141 static Lisp_Object all_vectors;
|
|
1142
|
|
1143 /* #### should allocate `small' vectors from a frob-block */
|
|
1144 static struct Lisp_Vector *
|
|
1145 make_vector_internal (EMACS_INT sizei)
|
|
1146 {
|
|
1147 EMACS_INT sizem = (sizeof (struct Lisp_Vector)
|
|
1148 /* -1 because struct Lisp_Vector includes 1 slot,
|
|
1149 * +1 to account for vector_next */
|
|
1150 + (sizei - 1 + 1) * sizeof (Lisp_Object)
|
|
1151 );
|
|
1152 struct Lisp_Vector *p = allocate_lisp_storage (sizem);
|
|
1153 #ifdef LRECORD_VECTOR
|
|
1154 set_lheader_implementation (&(p->lheader), lrecord_vector);
|
|
1155 #endif
|
|
1156
|
|
1157 INCREMENT_CONS_COUNTER (sizem, "vector");
|
|
1158
|
|
1159 p->size = sizei;
|
|
1160 vector_next (p) = all_vectors;
|
|
1161 XSETVECTOR (all_vectors, p);
|
|
1162 return (p);
|
|
1163 }
|
|
1164
|
|
1165 Lisp_Object
|
|
1166 make_vector (EMACS_INT length, Lisp_Object init)
|
|
1167 {
|
|
1168 EMACS_INT elt;
|
|
1169 Lisp_Object vector = Qnil;
|
|
1170 struct Lisp_Vector *p;
|
|
1171
|
|
1172 if (length < 0)
|
|
1173 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
|
|
1174
|
|
1175 p = make_vector_internal (length);
|
|
1176 XSETVECTOR (vector, p);
|
|
1177
|
|
1178 #if 0
|
|
1179 /* Initialize big arrays full of 0's quickly, for what that's worth */
|
|
1180 {
|
|
1181 char *travesty = (char *) &init;
|
|
1182 for (i = 1; i < sizeof (Lisp_Object); i++)
|
|
1183 {
|
|
1184 if (travesty[i] != travesty[0])
|
|
1185 goto fill;
|
|
1186 }
|
|
1187 memset (vector_data (p), travesty[0], length * sizeof (Lisp_Object));
|
|
1188 return (vector);
|
|
1189 }
|
|
1190 fill:
|
|
1191 #endif
|
|
1192 for (elt = 0; elt < length; elt++)
|
|
1193 vector_data(p)[elt] = init;
|
|
1194
|
|
1195 return (vector);
|
|
1196 }
|
|
1197
|
|
1198 DEFUN ("make-vector", Fmake_vector, Smake_vector, 2, 2, 0 /*
|
|
1199 Return a newly created vector of length LENGTH, with each element being INIT.
|
|
1200 See also the function `vector'.
|
|
1201 */ )
|
|
1202 (length, init)
|
|
1203 Lisp_Object length, init;
|
|
1204 {
|
|
1205 if (!INTP (length) || XINT (length) < 0)
|
|
1206 length = wrong_type_argument (Qnatnump, length);
|
|
1207
|
|
1208 return (make_vector (XINT (length), init));
|
|
1209 }
|
|
1210
|
|
1211 DEFUN ("vector", Fvector, Svector, 0, MANY, 0 /*
|
|
1212 Return a newly created vector with specified arguments as elements.
|
|
1213 Any number of arguments, even zero arguments, are allowed.
|
|
1214 */ )
|
|
1215 (nargs, args)
|
|
1216 int nargs;
|
|
1217 Lisp_Object *args;
|
|
1218 {
|
|
1219 Lisp_Object vector = Qnil;
|
|
1220 int elt;
|
|
1221 struct Lisp_Vector *p;
|
|
1222
|
|
1223 p = make_vector_internal (nargs);
|
|
1224 XSETVECTOR (vector, p);
|
|
1225
|
|
1226 for (elt = 0; elt < nargs; elt++)
|
|
1227 vector_data(p)[elt] = args[elt];
|
|
1228
|
|
1229 return (vector);
|
|
1230 }
|
|
1231
|
|
1232 Lisp_Object
|
|
1233 vector1 (Lisp_Object obj0)
|
|
1234 {
|
|
1235 return Fvector (1, &obj0);
|
|
1236 }
|
|
1237
|
|
1238 Lisp_Object
|
|
1239 vector2 (Lisp_Object obj0, Lisp_Object obj1)
|
|
1240 {
|
|
1241 Lisp_Object args[2];
|
|
1242 args[0] = obj0;
|
|
1243 args[1] = obj1;
|
|
1244 return Fvector (2, args);
|
|
1245 }
|
|
1246
|
|
1247 Lisp_Object
|
|
1248 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1249 {
|
|
1250 Lisp_Object args[3];
|
|
1251 args[0] = obj0;
|
|
1252 args[1] = obj1;
|
|
1253 args[2] = obj2;
|
|
1254 return Fvector (3, args);
|
|
1255 }
|
|
1256
|
|
1257 Lisp_Object
|
|
1258 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1259 Lisp_Object obj3)
|
|
1260 {
|
|
1261 Lisp_Object args[4];
|
|
1262 args[0] = obj0;
|
|
1263 args[1] = obj1;
|
|
1264 args[2] = obj2;
|
|
1265 args[3] = obj3;
|
|
1266 return Fvector (4, args);
|
|
1267 }
|
|
1268
|
|
1269 Lisp_Object
|
|
1270 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1271 Lisp_Object obj3, Lisp_Object obj4)
|
|
1272 {
|
|
1273 Lisp_Object args[5];
|
|
1274 args[0] = obj0;
|
|
1275 args[1] = obj1;
|
|
1276 args[2] = obj2;
|
|
1277 args[3] = obj3;
|
|
1278 args[4] = obj4;
|
|
1279 return Fvector (5, args);
|
|
1280 }
|
|
1281
|
|
1282 Lisp_Object
|
|
1283 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1284 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5)
|
|
1285 {
|
|
1286 Lisp_Object args[6];
|
|
1287 args[0] = obj0;
|
|
1288 args[1] = obj1;
|
|
1289 args[2] = obj2;
|
|
1290 args[3] = obj3;
|
|
1291 args[4] = obj4;
|
|
1292 args[5] = obj5;
|
|
1293 return Fvector (6, args);
|
|
1294 }
|
|
1295
|
|
1296 Lisp_Object
|
|
1297 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1298 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
|
|
1299 Lisp_Object obj6)
|
|
1300 {
|
|
1301 Lisp_Object args[7];
|
|
1302 args[0] = obj0;
|
|
1303 args[1] = obj1;
|
|
1304 args[2] = obj2;
|
|
1305 args[3] = obj3;
|
|
1306 args[4] = obj4;
|
|
1307 args[5] = obj5;
|
|
1308 args[6] = obj6;
|
|
1309 return Fvector (7, args);
|
|
1310 }
|
|
1311
|
|
1312 Lisp_Object
|
|
1313 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1314 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
|
|
1315 Lisp_Object obj6, Lisp_Object obj7)
|
|
1316 {
|
|
1317 Lisp_Object args[8];
|
|
1318 args[0] = obj0;
|
|
1319 args[1] = obj1;
|
|
1320 args[2] = obj2;
|
|
1321 args[3] = obj3;
|
|
1322 args[4] = obj4;
|
|
1323 args[5] = obj5;
|
|
1324 args[6] = obj6;
|
|
1325 args[7] = obj7;
|
|
1326 return Fvector (8, args);
|
|
1327 }
|
|
1328
|
|
1329 /**********************************************************************/
|
|
1330 /* Bit Vector allocation */
|
|
1331 /**********************************************************************/
|
|
1332
|
|
1333 static Lisp_Object all_bit_vectors;
|
|
1334
|
|
1335 /* #### should allocate `small' bit vectors from a frob-block */
|
|
1336 static struct Lisp_Bit_Vector *
|
|
1337 make_bit_vector_internal (EMACS_INT sizei)
|
|
1338 {
|
|
1339 EMACS_INT sizem = (sizeof (struct Lisp_Bit_Vector) +
|
|
1340 /* -1 because struct Lisp_Bit_Vector includes 1 slot */
|
|
1341 sizeof (long) * (BIT_VECTOR_LONG_STORAGE (sizei) - 1));
|
|
1342 struct Lisp_Bit_Vector *p = allocate_lisp_storage (sizem);
|
|
1343 set_lheader_implementation (&(p->lheader), lrecord_bit_vector);
|
|
1344
|
|
1345 INCREMENT_CONS_COUNTER (sizem, "bit-vector");
|
|
1346
|
|
1347 bit_vector_length (p) = sizei;
|
|
1348 bit_vector_next (p) = all_bit_vectors;
|
|
1349 /* make sure the extra bits in the last long are 0; the calling
|
|
1350 functions might not set them. */
|
|
1351 p->bits[BIT_VECTOR_LONG_STORAGE (sizei) - 1] = 0;
|
|
1352 XSETBIT_VECTOR (all_bit_vectors, p);
|
|
1353 return (p);
|
|
1354 }
|
|
1355
|
|
1356 Lisp_Object
|
|
1357 make_bit_vector (EMACS_INT length, Lisp_Object init)
|
|
1358 {
|
|
1359 Lisp_Object bit_vector = Qnil;
|
|
1360 struct Lisp_Bit_Vector *p;
|
|
1361 EMACS_INT num_longs;
|
|
1362
|
|
1363 if (length < 0)
|
|
1364 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
|
|
1365
|
|
1366 CHECK_BIT (init);
|
|
1367
|
|
1368 num_longs = BIT_VECTOR_LONG_STORAGE (length);
|
|
1369 p = make_bit_vector_internal (length);
|
|
1370 XSETBIT_VECTOR (bit_vector, p);
|
|
1371
|
|
1372 if (ZEROP (init))
|
|
1373 memset (p->bits, 0, num_longs * sizeof (long));
|
|
1374 else
|
|
1375 {
|
|
1376 EMACS_INT bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
|
|
1377 memset (p->bits, ~0, num_longs * sizeof (long));
|
|
1378 /* But we have to make sure that the unused bits in the
|
|
1379 last integer are 0, so that equal/hash is easy. */
|
|
1380 if (bits_in_last)
|
|
1381 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1;
|
|
1382 }
|
|
1383
|
|
1384 return (bit_vector);
|
|
1385 }
|
|
1386
|
|
1387 Lisp_Object
|
|
1388 make_bit_vector_from_byte_vector (unsigned char *bytevec, EMACS_INT length)
|
|
1389 {
|
|
1390 Lisp_Object bit_vector = Qnil;
|
|
1391 struct Lisp_Bit_Vector *p;
|
|
1392 EMACS_INT i;
|
|
1393
|
|
1394 if (length < 0)
|
|
1395 length = XINT (wrong_type_argument (Qnatnump, make_int (length)));
|
|
1396
|
|
1397 p = make_bit_vector_internal (length);
|
|
1398 XSETBIT_VECTOR (bit_vector, p);
|
|
1399
|
|
1400 for (i = 0; i < length; i++)
|
|
1401 set_bit_vector_bit (p, i, bytevec[i]);
|
|
1402
|
|
1403 return bit_vector;
|
|
1404 }
|
|
1405
|
|
1406 DEFUN ("make-bit-vector", Fmake_bit_vector, Smake_bit_vector, 2, 2, 0 /*
|
|
1407 Return a newly created bit vector of length LENGTH.
|
|
1408 Each element is set to INIT. See also the function `bit-vector'.
|
|
1409 */ )
|
|
1410 (length, init)
|
|
1411 Lisp_Object length, init;
|
|
1412 {
|
|
1413 if (!INTP (length) || XINT (length) < 0)
|
|
1414 length = wrong_type_argument (Qnatnump, length);
|
|
1415
|
|
1416 return (make_bit_vector (XINT (length), init));
|
|
1417 }
|
|
1418
|
|
1419 DEFUN ("bit-vector", Fbit_vector, Sbit_vector, 0, MANY, 0 /*
|
|
1420 Return a newly created bit vector with specified arguments as elements.
|
|
1421 Any number of arguments, even zero arguments, are allowed.
|
|
1422 */ )
|
|
1423 (nargs, args)
|
|
1424 int nargs;
|
|
1425 Lisp_Object *args;
|
|
1426 {
|
|
1427 Lisp_Object bit_vector = Qnil;
|
|
1428 int elt;
|
|
1429 struct Lisp_Bit_Vector *p;
|
|
1430
|
|
1431 for (elt = 0; elt < nargs; elt++)
|
|
1432 CHECK_BIT (args[elt]);
|
|
1433
|
|
1434 p = make_bit_vector_internal (nargs);
|
|
1435 XSETBIT_VECTOR (bit_vector, p);
|
|
1436
|
|
1437 for (elt = 0; elt < nargs; elt++)
|
|
1438 set_bit_vector_bit (p, elt, !ZEROP (args[elt]));
|
|
1439
|
|
1440 return (bit_vector);
|
|
1441 }
|
|
1442
|
|
1443
|
|
1444 /**********************************************************************/
|
|
1445 /* Compiled-function allocation */
|
|
1446 /**********************************************************************/
|
|
1447
|
|
1448 DECLARE_FIXED_TYPE_ALLOC (compiled_function, struct Lisp_Compiled_Function);
|
|
1449 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000
|
|
1450
|
|
1451 static Lisp_Object
|
|
1452 make_compiled_function (int make_pure)
|
|
1453 {
|
|
1454 struct Lisp_Compiled_Function *b;
|
|
1455 Lisp_Object new;
|
|
1456 int size = sizeof (struct Lisp_Compiled_Function);
|
|
1457
|
|
1458 if (make_pure && check_purespace (size))
|
|
1459 {
|
|
1460 b = (struct Lisp_Compiled_Function *) (PUREBEG + pureptr);
|
|
1461 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
|
|
1462 pureptr += size;
|
|
1463 bump_purestat (&purestat_bytecode, size);
|
|
1464 }
|
|
1465 else
|
|
1466 {
|
|
1467 ALLOCATE_FIXED_TYPE (compiled_function, struct Lisp_Compiled_Function,
|
|
1468 b);
|
|
1469 set_lheader_implementation (&(b->lheader), lrecord_compiled_function);
|
|
1470 }
|
|
1471 b->maxdepth = 0;
|
|
1472 b->flags.documentationp = 0;
|
|
1473 b->flags.interactivep = 0;
|
|
1474 b->flags.domainp = 0; /* I18N3 */
|
|
1475 b->bytecodes = Qzero;
|
|
1476 b->constants = Qzero;
|
|
1477 b->arglist = Qnil;
|
|
1478 b->doc_and_interactive = Qnil;
|
|
1479 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1480 b->annotated = Qnil;
|
|
1481 #endif
|
|
1482 XSETCOMPILED_FUNCTION (new, b);
|
|
1483 return (new);
|
|
1484 }
|
|
1485
|
|
1486 DEFUN ("make-byte-code", Fmake_byte_code, Smake_byte_code, 4, MANY, 0 /*
|
|
1487 Create a compiled-function object.
|
|
1488 Usage: (arglist instructions constants stack-size
|
|
1489 &optional doc-string interactive-spec)
|
|
1490 Note that, unlike all other emacs-lisp functions, calling this with five
|
|
1491 arguments is NOT the same as calling it with six arguments, the last of
|
|
1492 which is nil. If the INTERACTIVE arg is specified as nil, then that means
|
|
1493 that this function was defined with `(interactive)'. If the arg is not
|
|
1494 specified, then that means the function is not interactive.
|
|
1495 This is terrible behavior which is retained for compatibility with old
|
|
1496 `.elc' files which expected these semantics.
|
|
1497 */ )
|
|
1498 (nargs, args)
|
|
1499 int nargs;
|
|
1500 Lisp_Object *args;
|
|
1501 {
|
|
1502 /* In a non-insane world this function would have this arglist...
|
|
1503 (arglist, instructions, constants, stack_size, doc_string, interactive)
|
|
1504 Lisp_Object arglist, instructions, constants, stack_size, doc_string,
|
|
1505 interactive;
|
|
1506 */
|
|
1507 Lisp_Object arglist = args[0];
|
|
1508 Lisp_Object instructions = args[1];
|
|
1509 Lisp_Object constants = args[2];
|
|
1510 Lisp_Object stack_size = args[3];
|
|
1511 Lisp_Object doc_string = ((nargs > 4) ? args[4] : Qnil);
|
|
1512 Lisp_Object interactive = ((nargs > 5) ? args[5] : Qunbound);
|
|
1513 /* Don't purecopy the doc references in instructions because it's
|
|
1514 wasteful; they will get fixed up later.
|
|
1515
|
|
1516 #### If something goes wrong and they don't get fixed up,
|
|
1517 we're screwed, because pure stuff isn't marked and thus the
|
|
1518 cons references won't be marked and will get reused.
|
|
1519
|
|
1520 Note: there will be a window after the byte code is created and
|
|
1521 before the doc references are fixed up in which there will be
|
|
1522 impure objects inside a pure object, which apparently won't
|
|
1523 get marked, leading the trouble. But during that entire window,
|
|
1524 the objects are sitting on Vload_force_doc_string_list, which
|
|
1525 is staticpro'd, so we're OK. */
|
|
1526 int purecopy_instructions = 1;
|
|
1527
|
|
1528 if (nargs > 6)
|
|
1529 return Fsignal (Qwrong_number_of_arguments,
|
|
1530 list2 (intern ("make-byte-code"), make_int (nargs)));
|
|
1531
|
|
1532 CHECK_LIST (arglist);
|
|
1533 /* instructions is a string or a cons (string . int) for a
|
|
1534 lazy-loaded function. */
|
|
1535 if (CONSP (instructions))
|
|
1536 {
|
|
1537 CHECK_STRING (XCAR (instructions));
|
|
1538 CHECK_INT (XCDR (instructions));
|
|
1539 if (!NILP (constants))
|
|
1540 CHECK_VECTOR (constants);
|
|
1541 purecopy_instructions = 0;
|
|
1542 }
|
|
1543 else
|
|
1544 {
|
|
1545 CHECK_STRING (instructions);
|
|
1546 CHECK_VECTOR (constants);
|
|
1547 }
|
|
1548 CHECK_NATNUM (stack_size);
|
|
1549 /* doc_string may be nil, string, int, or a cons (string . int). */
|
|
1550
|
|
1551 /* interactive may be list or string (or unbound). */
|
|
1552
|
|
1553 if (purify_flag)
|
|
1554 {
|
|
1555 if (!purified (arglist))
|
|
1556 arglist = Fpurecopy (arglist);
|
|
1557 if (purecopy_instructions && !purified (instructions))
|
|
1558 instructions = Fpurecopy (instructions);
|
|
1559 if (!purified (doc_string))
|
|
1560 doc_string = Fpurecopy (doc_string);
|
|
1561 if (!purified (interactive) && !UNBOUNDP (interactive))
|
|
1562 interactive = Fpurecopy (interactive);
|
|
1563
|
|
1564 /* Statistics are kept differently for the constants */
|
|
1565 if (!purified (constants))
|
|
1566 #ifdef PURESTAT
|
|
1567 {
|
|
1568 int old = purecopying_for_bytecode;
|
|
1569 purecopying_for_bytecode = 1;
|
|
1570 constants = Fpurecopy (constants);
|
|
1571 purecopying_for_bytecode = old;
|
|
1572 }
|
|
1573 #else
|
|
1574 constants = Fpurecopy (constants);
|
|
1575 #endif /* PURESTAT */
|
|
1576
|
|
1577 #ifdef PURESTAT
|
|
1578 if (STRINGP (instructions))
|
|
1579 bump_purestat (&purestat_string_bytecodes, pure_sizeof (instructions));
|
|
1580 if (VECTORP (constants))
|
|
1581 bump_purestat (&purestat_vector_bytecode_constants,
|
|
1582 pure_sizeof (constants));
|
|
1583 if (STRINGP (doc_string))
|
|
1584 /* These should be have been snagged by make-docfile... */
|
|
1585 bump_purestat (&purestat_string_documentation,
|
|
1586 pure_sizeof (doc_string));
|
|
1587 if (STRINGP (interactive))
|
|
1588 bump_purestat (&purestat_string_interactive,
|
|
1589 pure_sizeof (interactive));
|
|
1590 #endif /* PURESTAT */
|
|
1591 }
|
|
1592
|
|
1593 {
|
|
1594 int docp = !NILP (doc_string);
|
|
1595 int intp = !UNBOUNDP (interactive);
|
|
1596 #ifdef I18N3
|
|
1597 int domp = !NILP (Vfile_domain);
|
|
1598 #endif
|
|
1599 Lisp_Object val = make_compiled_function (purify_flag);
|
|
1600 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (val);
|
|
1601 b->flags.documentationp = docp;
|
|
1602 b->flags.interactivep = intp;
|
|
1603 #ifdef I18N3
|
|
1604 b->flags.domainp = domp;
|
|
1605 #endif
|
|
1606 b->maxdepth = XINT (stack_size);
|
|
1607 b->bytecodes = instructions;
|
|
1608 b->constants = constants;
|
|
1609 b->arglist = arglist;
|
|
1610 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1611 if (!NILP (Vcurrent_compiled_function_annotation))
|
|
1612 b->annotated = Fpurecopy (Vcurrent_compiled_function_annotation);
|
|
1613 else if (!NILP (Vload_file_name_internal_the_purecopy))
|
|
1614 b->annotated = Vload_file_name_internal_the_purecopy;
|
|
1615 else if (!NILP (Vload_file_name_internal))
|
|
1616 {
|
|
1617 Vload_file_name_internal_the_purecopy =
|
|
1618 Fpurecopy (Ffile_name_nondirectory (Vload_file_name_internal));
|
|
1619 b->annotated = Vload_file_name_internal_the_purecopy;
|
|
1620 }
|
|
1621 #endif
|
|
1622
|
|
1623 #ifdef I18N3
|
|
1624 if (docp && intp && domp)
|
|
1625 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1626 (doc_string,
|
|
1627 (((purify_flag) ? pure_cons : Fcons)
|
|
1628 (interactive, Vfile_domain))));
|
|
1629 else if (docp && domp)
|
|
1630 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1631 (doc_string, Vfile_domain));
|
|
1632 else if (intp && domp)
|
|
1633 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1634 (interactive, Vfile_domain));
|
|
1635 else
|
|
1636 #endif
|
|
1637 if (docp && intp)
|
|
1638 b->doc_and_interactive = (((purify_flag) ? pure_cons : Fcons)
|
|
1639 (doc_string, interactive));
|
|
1640 else if (intp)
|
|
1641 b->doc_and_interactive = interactive;
|
|
1642 #ifdef I18N3
|
|
1643 else if (domp)
|
|
1644 b->doc_and_interactive = Vfile_domain;
|
|
1645 #endif
|
|
1646 else
|
|
1647 b->doc_and_interactive = doc_string;
|
|
1648
|
|
1649 return (val);
|
|
1650 }
|
|
1651 }
|
|
1652
|
|
1653
|
|
1654 /**********************************************************************/
|
|
1655 /* Symbol allocation */
|
|
1656 /**********************************************************************/
|
|
1657
|
|
1658 DECLARE_FIXED_TYPE_ALLOC (symbol, struct Lisp_Symbol);
|
|
1659 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000
|
|
1660
|
|
1661 DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0 /*
|
|
1662 Return a newly allocated uninterned symbol whose name is NAME.
|
|
1663 Its value and function definition are void, and its property list is nil.
|
|
1664 */ )
|
|
1665 (str)
|
|
1666 Lisp_Object str;
|
|
1667 {
|
|
1668 Lisp_Object val;
|
|
1669 struct Lisp_Symbol *p;
|
|
1670
|
|
1671 CHECK_STRING (str);
|
|
1672
|
|
1673 ALLOCATE_FIXED_TYPE (symbol, struct Lisp_Symbol, p);
|
|
1674 #ifdef LRECORD_SYMBOL
|
|
1675 set_lheader_implementation (&(p->lheader), lrecord_symbol);
|
|
1676 #endif
|
|
1677 p->name = XSTRING (str);
|
|
1678 p->plist = Qnil;
|
|
1679 p->value = Qunbound;
|
|
1680 p->function = Qunbound;
|
|
1681 symbol_next (p) = 0;
|
|
1682 XSETSYMBOL (val, p);
|
|
1683 return val;
|
|
1684 }
|
|
1685
|
|
1686
|
|
1687 /**********************************************************************/
|
|
1688 /* Extent allocation */
|
|
1689 /**********************************************************************/
|
|
1690
|
|
1691 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent);
|
|
1692 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000
|
|
1693
|
|
1694 struct extent *
|
|
1695 allocate_extent (void)
|
|
1696 {
|
|
1697 struct extent *e;
|
|
1698
|
|
1699 ALLOCATE_FIXED_TYPE (extent, struct extent, e);
|
|
1700 /* memset (e, 0, sizeof (struct extent)); */
|
|
1701 set_lheader_implementation (&(e->lheader), lrecord_extent);
|
|
1702 extent_object (e) = Qnil;
|
|
1703 set_extent_start (e, -1);
|
|
1704 set_extent_end (e, -1);
|
|
1705 e->plist = Qnil;
|
|
1706
|
|
1707 memset (&e->flags, 0, sizeof (e->flags));
|
|
1708
|
|
1709 extent_face (e) = Qnil;
|
|
1710 e->flags.end_open = 1; /* default is for endpoints to behave like markers */
|
|
1711 e->flags.detachable = 1;
|
|
1712
|
|
1713 return (e);
|
|
1714 }
|
|
1715
|
|
1716
|
|
1717 /**********************************************************************/
|
|
1718 /* Event allocation */
|
|
1719 /**********************************************************************/
|
|
1720
|
|
1721 DECLARE_FIXED_TYPE_ALLOC (event, struct Lisp_Event);
|
|
1722 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000
|
|
1723
|
|
1724 Lisp_Object
|
|
1725 allocate_event (void)
|
|
1726 {
|
|
1727 Lisp_Object val;
|
|
1728 struct Lisp_Event *e;
|
|
1729
|
|
1730 ALLOCATE_FIXED_TYPE (event, struct Lisp_Event, e);
|
|
1731 set_lheader_implementation (&(e->lheader), lrecord_event);
|
|
1732
|
|
1733 XSETEVENT (val, e);
|
|
1734 return val;
|
|
1735 }
|
|
1736
|
|
1737
|
|
1738 /**********************************************************************/
|
|
1739 /* Marker allocation */
|
|
1740 /**********************************************************************/
|
|
1741
|
|
1742 DECLARE_FIXED_TYPE_ALLOC (marker, struct Lisp_Marker);
|
|
1743 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000
|
|
1744
|
|
1745 DEFUN ("make-marker", Fmake_marker, Smake_marker, 0, 0, 0 /*
|
|
1746 Return a newly allocated marker which does not point at any place.
|
|
1747 */ )
|
|
1748 ()
|
|
1749 {
|
|
1750 Lisp_Object val;
|
|
1751 struct Lisp_Marker *p;
|
|
1752
|
|
1753 ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
|
|
1754 set_lheader_implementation (&(p->lheader), lrecord_marker);
|
|
1755 p->buffer = 0;
|
|
1756 p->memind = 0;
|
|
1757 marker_next (p) = 0;
|
|
1758 marker_prev (p) = 0;
|
|
1759 p->insertion_type = 0;
|
|
1760 XSETMARKER (val, p);
|
|
1761 return val;
|
|
1762 }
|
|
1763
|
|
1764 Lisp_Object
|
|
1765 noseeum_make_marker (void)
|
|
1766 {
|
|
1767 Lisp_Object val;
|
|
1768 struct Lisp_Marker *p;
|
|
1769
|
|
1770 NOSEEUM_ALLOCATE_FIXED_TYPE (marker, struct Lisp_Marker, p);
|
|
1771 set_lheader_implementation (&(p->lheader), lrecord_marker);
|
|
1772 p->buffer = 0;
|
|
1773 p->memind = 0;
|
|
1774 marker_next (p) = 0;
|
|
1775 marker_prev (p) = 0;
|
|
1776 p->insertion_type = 0;
|
|
1777 XSETMARKER (val, p);
|
|
1778 return val;
|
|
1779 }
|
|
1780
|
|
1781
|
|
1782 /**********************************************************************/
|
|
1783 /* String allocation */
|
|
1784 /**********************************************************************/
|
|
1785
|
|
1786 /* The data for "short" strings generally resides inside of structs of type
|
|
1787 string_chars_block. The Lisp_String structure is allocated just like any
|
|
1788 other Lisp object (except for vectors), and these are freelisted when
|
|
1789 they get garbage collected. The data for short strings get compacted,
|
|
1790 but the data for large strings do not.
|
|
1791
|
|
1792 Previously Lisp_String structures were relocated, but this caused a lot
|
|
1793 of bus-errors because the C code didn't include enough GCPRO's for
|
|
1794 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so
|
|
1795 that the reference would get relocated).
|
|
1796
|
|
1797 This new method makes things somewhat bigger, but it is MUCH safer. */
|
|
1798
|
|
1799 DECLARE_FIXED_TYPE_ALLOC (string, struct Lisp_String);
|
|
1800 /* strings are used and freed quite often */
|
|
1801 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */
|
|
1802 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000
|
|
1803
|
|
1804 /* String blocks contain this many useful bytes. */
|
|
1805 #define STRING_CHARS_BLOCK_SIZE \
|
|
1806 (8192 - MALLOC_OVERHEAD - ((2 * sizeof (struct string_chars_block *)) \
|
|
1807 + sizeof (EMACS_INT)))
|
|
1808 /* Block header for small strings. */
|
|
1809 struct string_chars_block
|
|
1810 {
|
|
1811 EMACS_INT pos;
|
|
1812 struct string_chars_block *next;
|
|
1813 struct string_chars_block *prev;
|
|
1814 /* Contents of string_chars_block->string_chars are interleaved
|
|
1815 string_chars structures (see below) and the actual string data */
|
|
1816 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE];
|
|
1817 };
|
|
1818
|
|
1819 struct string_chars_block *first_string_chars_block;
|
|
1820 struct string_chars_block *current_string_chars_block;
|
|
1821
|
|
1822 /* If SIZE is the length of a string, this returns how many bytes
|
|
1823 * the string occupies in string_chars_block->string_chars
|
|
1824 * (including alignment padding).
|
|
1825 */
|
|
1826 #define STRING_FULLSIZE(s) \
|
|
1827 ALIGN_SIZE (((s) + 1 + sizeof (struct Lisp_String *)),\
|
|
1828 ALIGNOF (struct Lisp_String *))
|
|
1829
|
|
1830 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE)
|
|
1831 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size)))
|
|
1832
|
|
1833 #define CHARS_TO_STRING_CHAR(x) \
|
|
1834 ((struct string_chars *) \
|
|
1835 (((char *) (x)) - (slot_offset (struct string_chars, chars))))
|
|
1836
|
|
1837
|
|
1838 struct string_chars
|
|
1839 {
|
|
1840 struct Lisp_String *string;
|
|
1841 unsigned char chars[1];
|
|
1842 };
|
|
1843
|
|
1844 struct unused_string_chars
|
|
1845 {
|
|
1846 struct Lisp_String *string;
|
|
1847 EMACS_INT fullsize;
|
|
1848 };
|
|
1849
|
|
1850 static void
|
|
1851 init_string_chars_alloc (void)
|
|
1852 {
|
|
1853 first_string_chars_block =
|
|
1854 (struct string_chars_block *) xmalloc (sizeof (struct string_chars_block));
|
|
1855 first_string_chars_block->prev = 0;
|
|
1856 first_string_chars_block->next = 0;
|
|
1857 first_string_chars_block->pos = 0;
|
|
1858 current_string_chars_block = first_string_chars_block;
|
|
1859 }
|
|
1860
|
|
1861 static struct string_chars *
|
|
1862 allocate_string_chars_struct (struct Lisp_String *string_it_goes_with,
|
|
1863 EMACS_INT fullsize)
|
|
1864 {
|
|
1865 struct string_chars *s_chars;
|
|
1866
|
|
1867 /* Allocate the string's actual data */
|
|
1868 if (BIG_STRING_FULLSIZE_P (fullsize))
|
|
1869 {
|
|
1870 s_chars = (struct string_chars *) xmalloc (fullsize);
|
|
1871 }
|
|
1872 else if (fullsize <=
|
|
1873 (countof (current_string_chars_block->string_chars)
|
|
1874 - current_string_chars_block->pos))
|
|
1875 {
|
|
1876 /* This string can fit in the current string chars block */
|
|
1877 s_chars = (struct string_chars *)
|
|
1878 (current_string_chars_block->string_chars
|
|
1879 + current_string_chars_block->pos);
|
|
1880 current_string_chars_block->pos += fullsize;
|
|
1881 }
|
|
1882 else
|
|
1883 {
|
|
1884 /* Make a new current string chars block */
|
|
1885 struct string_chars_block *new
|
|
1886 = (struct string_chars_block *)
|
|
1887 xmalloc (sizeof (struct string_chars_block));
|
|
1888
|
|
1889 current_string_chars_block->next = new;
|
|
1890 new->prev = current_string_chars_block;
|
|
1891 new->next = 0;
|
|
1892 current_string_chars_block = new;
|
|
1893 new->pos = fullsize;
|
|
1894 s_chars = (struct string_chars *)
|
|
1895 current_string_chars_block->string_chars;
|
|
1896 }
|
|
1897
|
|
1898 s_chars->string = string_it_goes_with;
|
|
1899
|
|
1900 INCREMENT_CONS_COUNTER (fullsize, "string chars");
|
|
1901
|
|
1902 return s_chars;
|
|
1903 }
|
|
1904
|
|
1905 Lisp_Object
|
|
1906 make_uninit_string (Bytecount length)
|
|
1907 {
|
|
1908 struct Lisp_String *s;
|
|
1909 struct string_chars *s_chars;
|
|
1910 EMACS_INT fullsize = STRING_FULLSIZE (length);
|
|
1911 Lisp_Object val;
|
|
1912
|
|
1913 if ((length < 0) || (fullsize <= 0))
|
|
1914 abort ();
|
|
1915
|
|
1916 /* Allocate the string header */
|
|
1917 ALLOCATE_FIXED_TYPE (string, struct Lisp_String, s);
|
|
1918
|
|
1919 s_chars = allocate_string_chars_struct (s, fullsize);
|
|
1920
|
|
1921 set_string_data (s, &(s_chars->chars[0]));
|
|
1922 set_string_length (s, length);
|
|
1923 s->plist = Qnil;
|
|
1924
|
|
1925 set_string_byte (s, length, 0);
|
|
1926
|
|
1927 XSETSTRING (val, s);
|
|
1928 return (val);
|
|
1929 }
|
|
1930
|
|
1931 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
1932 static void verify_string_chars_integrity (void);
|
|
1933 #endif
|
|
1934
|
|
1935 /* Resize the string S so that DELTA bytes can be inserted starting
|
|
1936 at POS. If DELTA < 0, it means deletion starting at POS. If
|
|
1937 POS < 0, resize the string but don't copy any characters. Use
|
|
1938 this if you're planning on completely overwriting the string.
|
|
1939 */
|
|
1940
|
|
1941 void
|
|
1942 resize_string (struct Lisp_String *s, Bytecount pos, Bytecount delta)
|
|
1943 {
|
|
1944 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
1945 verify_string_chars_integrity ();
|
|
1946 #endif
|
|
1947
|
|
1948 #ifdef ERROR_CHECK_BUFPOS
|
|
1949 if (pos >= 0)
|
|
1950 {
|
|
1951 assert (pos <= string_length (s));
|
|
1952 if (delta < 0)
|
|
1953 assert (pos + (-delta) <= string_length (s));
|
|
1954 }
|
|
1955 else
|
|
1956 {
|
|
1957 if (delta < 0)
|
|
1958 assert ((-delta) <= string_length (s));
|
|
1959 }
|
|
1960 #endif
|
|
1961
|
|
1962 if (pos >= 0 && delta < 0)
|
|
1963 /* If DELTA < 0, the functions below will delete the characters
|
|
1964 before POS. We want to delete characters *after* POS, however,
|
|
1965 so convert this to the appropriate form. */
|
|
1966 pos += -delta;
|
|
1967
|
|
1968 if (delta == 0)
|
|
1969 /* simplest case: no size change. */
|
|
1970 return;
|
|
1971 else
|
|
1972 {
|
|
1973 EMACS_INT oldfullsize = STRING_FULLSIZE (string_length (s));
|
|
1974 EMACS_INT newfullsize = STRING_FULLSIZE (string_length (s) + delta);
|
|
1975
|
|
1976 if (oldfullsize == newfullsize)
|
|
1977 {
|
|
1978 /* next simplest case; size change but the necessary
|
|
1979 allocation size won't change (up or down; code somewhere
|
|
1980 depends on there not being any unused allocation space,
|
|
1981 modulo any alignment constraints). */
|
|
1982 if (pos >= 0)
|
|
1983 {
|
|
1984 Bufbyte *addroff = pos + string_data (s);
|
|
1985
|
|
1986 memmove (addroff + delta, addroff,
|
|
1987 /* +1 due to zero-termination. */
|
|
1988 string_length (s) + 1 - pos);
|
|
1989 }
|
|
1990 }
|
|
1991 else if (BIG_STRING_FULLSIZE_P (oldfullsize) &&
|
|
1992 BIG_STRING_FULLSIZE_P (newfullsize))
|
|
1993 {
|
|
1994 /* next simplest case; the string is big enough to be malloc()ed
|
|
1995 itself, so we just realloc.
|
|
1996
|
|
1997 It's important not to let the string get below the threshold
|
|
1998 for making big strings and still remain malloc()ed; if that
|
|
1999 were the case, repeated calls to this function on the same
|
|
2000 string could result in memory leakage. */
|
|
2001 set_string_data (s, (Bufbyte *) xrealloc (string_data (s),
|
|
2002 newfullsize));
|
|
2003 if (pos >= 0)
|
|
2004 {
|
|
2005 Bufbyte *addroff = pos + string_data (s);
|
|
2006
|
|
2007 memmove (addroff + delta, addroff,
|
|
2008 /* +1 due to zero-termination. */
|
|
2009 string_length (s) + 1 - pos);
|
|
2010 }
|
|
2011 }
|
|
2012 else
|
|
2013 {
|
|
2014 /* worst case. We make a new string_chars struct and copy
|
|
2015 the string's data into it, inserting/deleting the delta
|
|
2016 in the process. The old string data will either get
|
|
2017 freed by us (if it was malloc()ed) or will be reclaimed
|
|
2018 in the normal course of garbage collection. */
|
|
2019 struct string_chars *s_chars =
|
|
2020 allocate_string_chars_struct (s, newfullsize);
|
|
2021 Bufbyte *new_addr = &(s_chars->chars[0]);
|
|
2022 Bufbyte *old_addr = string_data (s);
|
|
2023 if (pos >= 0)
|
|
2024 {
|
|
2025 memcpy (new_addr, old_addr, pos);
|
|
2026 memcpy (new_addr + pos + delta, old_addr + pos,
|
|
2027 string_length (s) + 1 - pos);
|
|
2028 }
|
|
2029 set_string_data (s, new_addr);
|
|
2030 if (BIG_STRING_FULLSIZE_P (oldfullsize))
|
|
2031 xfree (old_addr);
|
|
2032 else
|
|
2033 {
|
|
2034 /* We need to mark this chunk of the string_chars_block
|
|
2035 as unused so that compact_string_chars() doesn't
|
|
2036 freak. */
|
|
2037 struct string_chars *old_s_chars =
|
|
2038 (struct string_chars *) ((char *) old_addr -
|
|
2039 sizeof (struct Lisp_String *));
|
|
2040 /* Sanity check to make sure we aren't hosed by strange
|
|
2041 alignment/padding. */
|
|
2042 assert (old_s_chars->string == s);
|
|
2043 MARK_STRUCT_AS_FREE (old_s_chars);
|
|
2044 ((struct unused_string_chars *) old_s_chars)->fullsize =
|
|
2045 oldfullsize;
|
|
2046 }
|
|
2047 }
|
|
2048
|
|
2049 set_string_length (s, string_length (s) + delta);
|
|
2050 /* If pos < 0, the string won't be zero-terminated.
|
|
2051 Terminate now just to make sure. */
|
|
2052 string_data (s)[string_length (s)] = '\0';
|
|
2053
|
|
2054 if (pos >= 0)
|
|
2055 {
|
|
2056 Lisp_Object string = Qnil;
|
|
2057
|
|
2058 XSETSTRING (string, s);
|
|
2059 /* We also have to adjust all of the extent indices after the
|
|
2060 place we did the change. We say "pos - 1" because
|
|
2061 adjust_extents() is exclusive of the starting position
|
|
2062 passed to it. */
|
|
2063 adjust_extents (string, pos - 1, string_length (s),
|
|
2064 delta);
|
|
2065 }
|
|
2066 }
|
|
2067
|
|
2068 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
2069 verify_string_chars_integrity ();
|
|
2070 #endif
|
|
2071 }
|
|
2072
|
|
2073 DEFUN ("make-string", Fmake_string, Smake_string, 2, 2, 0 /*
|
|
2074 Return a newly created string of length LENGTH, with each element being INIT.
|
|
2075 LENGTH must be an integer and INIT must be a character.
|
|
2076 */ )
|
|
2077 (length, init)
|
|
2078 Lisp_Object length, init;
|
|
2079 {
|
|
2080 Lisp_Object val;
|
|
2081
|
|
2082 CHECK_NATNUM (length);
|
|
2083 CHECK_CHAR_COERCE_INT (init);
|
|
2084 {
|
|
2085 Bufbyte str[MAX_EMCHAR_LEN];
|
|
2086 int len = set_charptr_emchar (str, XCHAR (init));
|
|
2087
|
|
2088 val = make_uninit_string (len * XINT (length));
|
|
2089 if (len == 1)
|
|
2090 /* Optimize the single-byte case */
|
14
|
2091 memset (XSTRING_DATA (val), XCHAR (init), XSTRING_LENGTH (val));
|
0
|
2092 else
|
|
2093 {
|
|
2094 int i, j, k;
|
14
|
2095 Bufbyte *ptr = XSTRING_DATA (val);
|
0
|
2096
|
|
2097 k = 0;
|
|
2098 for (i = 0; i < XINT (length); i++)
|
|
2099 for (j = 0; j < len; j++)
|
|
2100 ptr[k++] = str[j];
|
|
2101 }
|
|
2102 }
|
|
2103 return (val);
|
|
2104 }
|
|
2105
|
|
2106 /* Take some raw memory, which MUST already be in internal format,
|
|
2107 and package it up it into a Lisp string. */
|
|
2108 Lisp_Object
|
|
2109 make_string (CONST Bufbyte *contents, Bytecount length)
|
|
2110 {
|
|
2111 Lisp_Object val;
|
|
2112
|
|
2113 val = make_uninit_string (length);
|
14
|
2114 memcpy (XSTRING_DATA (val), contents, length);
|
0
|
2115 return (val);
|
|
2116 }
|
|
2117
|
|
2118 /* Take some raw memory, encoded in some external data format,
|
|
2119 and convert it into a Lisp string. */
|
|
2120 Lisp_Object
|
|
2121 make_ext_string (CONST Extbyte *contents, EMACS_INT length,
|
|
2122 enum external_data_format fmt)
|
|
2123 {
|
|
2124 CONST Bufbyte *intstr;
|
|
2125 Bytecount intlen;
|
|
2126
|
|
2127 GET_CHARPTR_INT_DATA_ALLOCA (contents, length, fmt, intstr, intlen);
|
|
2128 return make_string (intstr, intlen);
|
|
2129 }
|
|
2130
|
|
2131 Lisp_Object
|
|
2132 build_string (CONST char *str)
|
|
2133 {
|
|
2134 Bytecount length;
|
|
2135
|
|
2136 /* Some strlen crash and burn if passed null. */
|
|
2137 if (!str)
|
|
2138 length = 0;
|
|
2139 else
|
|
2140 length = strlen (str);
|
|
2141
|
|
2142 return make_string ((CONST Bufbyte *) str, length);
|
|
2143 }
|
|
2144
|
|
2145 Lisp_Object
|
|
2146 build_ext_string (CONST char *str, enum external_data_format fmt)
|
|
2147 {
|
|
2148 Bytecount length;
|
|
2149
|
|
2150 /* Some strlen crash and burn if passed null. */
|
|
2151 if (!str)
|
|
2152 length = 0;
|
|
2153 else
|
|
2154 length = strlen (str);
|
|
2155
|
|
2156 return make_ext_string ((Extbyte *) str, length, fmt);
|
|
2157 }
|
|
2158
|
|
2159 Lisp_Object
|
|
2160 build_translated_string (CONST char *str)
|
|
2161 {
|
|
2162 return build_string (GETTEXT (str));
|
|
2163 }
|
|
2164
|
|
2165
|
|
2166 /************************************************************************/
|
|
2167 /* lcrecord lists */
|
|
2168 /************************************************************************/
|
|
2169
|
|
2170 /* Lcrecord lists are used to manage the allocation of particular
|
|
2171 sorts of lcrecords, to avoid calling alloc_lcrecord() (and thus
|
|
2172 malloc() and garbage-collection junk) as much as possible.
|
|
2173 It is similar to the Blocktype class.
|
|
2174
|
|
2175 It works like this:
|
|
2176
|
|
2177 1) Create an lcrecord-list object using make_lcrecord_list().
|
|
2178 This is often done at initialization. Remember to staticpro
|
|
2179 this object! The arguments to make_lcrecord_list() are the
|
|
2180 same as would be passed to alloc_lcrecord().
|
|
2181 2) Instead of calling alloc_lcrecord(), call allocate_managed_lcrecord()
|
|
2182 and pass the lcrecord-list earlier created.
|
|
2183 3) When done with the lcrecord, call free_managed_lcrecord().
|
|
2184 The standard freeing caveats apply: ** make sure there are no
|
|
2185 pointers to the object anywhere! **
|
|
2186 4) Calling free_managed_lcrecord() is just like kissing the
|
|
2187 lcrecord goodbye as if it were garbage-collected. This means:
|
|
2188 -- the contents of the freed lcrecord are undefined, and the
|
|
2189 contents of something produced by allocate_managed_lcrecord()
|
|
2190 are undefined, just like for alloc_lcrecord().
|
|
2191 -- the mark method for the lcrecord's type will *NEVER* be called
|
|
2192 on freed lcrecords.
|
|
2193 -- the finalize method for the lcrecord's type will be called
|
|
2194 at the time that free_managed_lcrecord() is called.
|
|
2195
|
|
2196 */
|
|
2197
|
|
2198 static Lisp_Object mark_lcrecord_list (Lisp_Object, void (*) (Lisp_Object));
|
|
2199 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list,
|
|
2200 mark_lcrecord_list, internal_object_printer,
|
|
2201 0, 0, 0, struct lcrecord_list);
|
|
2202
|
|
2203 static Lisp_Object
|
|
2204 mark_lcrecord_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
2205 {
|
|
2206 struct lcrecord_list *list = XLCRECORD_LIST (obj);
|
|
2207 Lisp_Object chain = list->free;
|
|
2208
|
|
2209 while (!NILP (chain))
|
|
2210 {
|
|
2211 struct lrecord_header *lheader = XRECORD_LHEADER (chain);
|
|
2212 struct free_lcrecord_header *free_header =
|
|
2213 (struct free_lcrecord_header *) lheader;
|
14
|
2214
|
|
2215 #ifdef ERROR_CHECK_GC
|
0
|
2216 CONST struct lrecord_implementation *implementation
|
|
2217 = lheader->implementation;
|
|
2218
|
|
2219 /* There should be no other pointers to the free list. */
|
|
2220 assert (!MARKED_RECORD_HEADER_P (lheader));
|
|
2221 /* Only lcrecords should be here. */
|
|
2222 assert (!implementation->basic_p);
|
|
2223 /* Only free lcrecords should be here. */
|
|
2224 assert (free_header->lcheader.free);
|
|
2225 /* The type of the lcrecord must be right. */
|
|
2226 assert (implementation == list->implementation);
|
|
2227 /* So must the size. */
|
|
2228 assert (implementation->static_size == 0
|
|
2229 || implementation->static_size == list->size);
|
14
|
2230 #endif /* ERROR_CHECK_GC */
|
|
2231
|
0
|
2232 MARK_RECORD_HEADER (lheader);
|
|
2233 chain = free_header->chain;
|
|
2234 }
|
|
2235
|
|
2236 return Qnil;
|
|
2237 }
|
|
2238
|
|
2239 Lisp_Object
|
|
2240 make_lcrecord_list (int size,
|
|
2241 CONST struct lrecord_implementation *implementation)
|
|
2242 {
|
|
2243 struct lcrecord_list *p = alloc_lcrecord (sizeof (*p),
|
|
2244 lrecord_lcrecord_list);
|
|
2245 Lisp_Object val = Qnil;
|
|
2246
|
|
2247 p->implementation = implementation;
|
|
2248 p->size = size;
|
|
2249 p->free = Qnil;
|
|
2250 XSETLCRECORD_LIST (val, p);
|
|
2251 return val;
|
|
2252 }
|
|
2253
|
|
2254 Lisp_Object
|
|
2255 allocate_managed_lcrecord (Lisp_Object lcrecord_list)
|
|
2256 {
|
|
2257 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
|
|
2258 if (!NILP (list->free))
|
|
2259 {
|
|
2260 Lisp_Object val = list->free;
|
|
2261 struct free_lcrecord_header *free_header =
|
|
2262 (struct free_lcrecord_header *) XPNTR (val);
|
|
2263
|
|
2264 #ifdef ERROR_CHECK_GC
|
|
2265 struct lrecord_header *lheader =
|
|
2266 (struct lrecord_header *) free_header;
|
|
2267 CONST struct lrecord_implementation *implementation
|
|
2268 = lheader->implementation;
|
|
2269
|
|
2270 /* There should be no other pointers to the free list. */
|
|
2271 assert (!MARKED_RECORD_HEADER_P (lheader));
|
|
2272 /* Only lcrecords should be here. */
|
|
2273 assert (!implementation->basic_p);
|
|
2274 /* Only free lcrecords should be here. */
|
|
2275 assert (free_header->lcheader.free);
|
|
2276 /* The type of the lcrecord must be right. */
|
|
2277 assert (implementation == list->implementation);
|
|
2278 /* So must the size. */
|
|
2279 assert (implementation->static_size == 0
|
|
2280 || implementation->static_size == list->size);
|
|
2281 #endif
|
|
2282 list->free = free_header->chain;
|
|
2283 free_header->lcheader.free = 0;
|
|
2284 return val;
|
|
2285 }
|
|
2286 else
|
|
2287 {
|
|
2288 Lisp_Object foo = Qnil;
|
|
2289
|
|
2290 XSETOBJ (foo, Lisp_Record,
|
|
2291 alloc_lcrecord (list->size, list->implementation));
|
|
2292 return foo;
|
|
2293 }
|
|
2294 }
|
|
2295
|
|
2296 void
|
|
2297 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord)
|
|
2298 {
|
|
2299 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
|
|
2300 struct free_lcrecord_header *free_header =
|
|
2301 (struct free_lcrecord_header *) XPNTR (lcrecord);
|
|
2302 struct lrecord_header *lheader =
|
|
2303 (struct lrecord_header *) free_header;
|
|
2304 CONST struct lrecord_implementation *implementation
|
|
2305 = lheader->implementation;
|
|
2306
|
|
2307 #ifdef ERROR_CHECK_GC
|
|
2308 /* Make sure the size is correct. This will catch, for example,
|
|
2309 putting a window configuration on the wrong free list. */
|
|
2310 if (implementation->size_in_bytes_method)
|
|
2311 assert (((implementation->size_in_bytes_method) (lheader))
|
|
2312 == list->size);
|
|
2313 else
|
|
2314 assert (implementation->static_size == list->size);
|
|
2315 #endif
|
|
2316
|
|
2317 if (implementation->finalizer)
|
|
2318 ((implementation->finalizer) (lheader, 0));
|
|
2319 free_header->chain = list->free;
|
|
2320 free_header->lcheader.free = 1;
|
|
2321 list->free = lcrecord;
|
|
2322 }
|
|
2323
|
|
2324
|
|
2325 /**********************************************************************/
|
|
2326 /* Purity of essence, peace on earth */
|
|
2327 /**********************************************************************/
|
|
2328
|
|
2329 static int symbols_initialized;
|
|
2330
|
|
2331 Lisp_Object
|
|
2332 make_pure_string (CONST Bufbyte *data, Bytecount length,
|
|
2333 Lisp_Object plist, int no_need_to_copy_data)
|
|
2334 {
|
|
2335 Lisp_Object new;
|
|
2336 struct Lisp_String *s;
|
|
2337 int size = (sizeof (struct Lisp_String) + ((no_need_to_copy_data)
|
|
2338 ? 0
|
|
2339 /* + 1 for terminating 0 */
|
|
2340 : (length + 1)));
|
|
2341 size = ALIGN_SIZE (size, ALIGNOF (Lisp_Object));
|
|
2342
|
|
2343 if (symbols_initialized && !pure_lossage)
|
|
2344 {
|
|
2345 /* Try to share some names. Saves a few kbytes. */
|
|
2346 Lisp_Object tem = oblookup (Vobarray, data, length);
|
|
2347 if (SYMBOLP (tem))
|
|
2348 {
|
|
2349 s = XSYMBOL (tem)->name;
|
|
2350 if (!PURIFIED (s)) abort ();
|
|
2351 XSETSTRING (new, s);
|
|
2352 return (new);
|
|
2353 }
|
|
2354 }
|
|
2355
|
|
2356 if (!check_purespace (size))
|
|
2357 return (make_string (data, length));
|
|
2358
|
|
2359 s = (struct Lisp_String *) (PUREBEG + pureptr);
|
|
2360 set_string_length (s, length);
|
|
2361 if (no_need_to_copy_data)
|
|
2362 {
|
|
2363 set_string_data (s, (Bufbyte *) data);
|
|
2364 }
|
|
2365 else
|
|
2366 {
|
|
2367 set_string_data (s, (Bufbyte *) s + sizeof (struct Lisp_String));
|
|
2368 memcpy (string_data (s), data, length);
|
|
2369 set_string_byte (s, length, 0);
|
|
2370 }
|
|
2371 s->plist = Qnil;
|
|
2372 pureptr += size;
|
|
2373
|
|
2374 #ifdef PURESTAT
|
|
2375 bump_purestat (&purestat_string_all, size);
|
|
2376 if (purecopying_for_bytecode)
|
|
2377 bump_purestat (&purestat_string_other_function, size);
|
|
2378 #endif
|
|
2379
|
|
2380 /* Do this after the official "completion" of the purecopying. */
|
|
2381 s->plist = Fpurecopy (plist);
|
|
2382
|
|
2383 XSETSTRING (new, s);
|
|
2384 return (new);
|
|
2385 }
|
|
2386
|
|
2387
|
|
2388 Lisp_Object
|
|
2389 make_pure_pname (CONST Bufbyte *data, Bytecount length,
|
|
2390 int no_need_to_copy_data)
|
|
2391 {
|
|
2392 Lisp_Object name = make_pure_string (data, length, Qnil,
|
|
2393 no_need_to_copy_data);
|
|
2394 bump_purestat (&purestat_string_pname, pure_sizeof (name));
|
|
2395
|
|
2396 /* We've made (at least) Qnil now, and Vobarray will soon be set up. */
|
|
2397 symbols_initialized = 1;
|
|
2398
|
|
2399 return (name);
|
|
2400 }
|
|
2401
|
|
2402
|
|
2403 Lisp_Object
|
|
2404 pure_cons (Lisp_Object car, Lisp_Object cdr)
|
|
2405 {
|
|
2406 Lisp_Object new;
|
|
2407
|
|
2408 if (!check_purespace (sizeof (struct Lisp_Cons)))
|
|
2409 return (Fcons (Fpurecopy (car), Fpurecopy (cdr)));
|
|
2410
|
|
2411 XSETCONS (new, PUREBEG + pureptr);
|
|
2412 pureptr += sizeof (struct Lisp_Cons);
|
|
2413 bump_purestat (&purestat_cons, sizeof (struct Lisp_Cons));
|
|
2414
|
|
2415 XCAR (new) = Fpurecopy (car);
|
|
2416 XCDR (new) = Fpurecopy (cdr);
|
|
2417 return (new);
|
|
2418 }
|
|
2419
|
|
2420 Lisp_Object
|
|
2421 pure_list (int nargs, Lisp_Object *args)
|
|
2422 {
|
|
2423 Lisp_Object foo = Qnil;
|
|
2424
|
|
2425 for (--nargs; nargs >= 0; nargs--)
|
|
2426 foo = pure_cons (args[nargs], foo);
|
|
2427
|
|
2428 return foo;
|
|
2429 }
|
|
2430
|
|
2431 #ifdef LISP_FLOAT_TYPE
|
|
2432
|
|
2433 Lisp_Object
|
|
2434 make_pure_float (double num)
|
|
2435 {
|
|
2436 struct Lisp_Float *f;
|
|
2437 Lisp_Object val;
|
|
2438
|
|
2439 /* Make sure that PUREBEG + pureptr is aligned on at least a sizeof
|
|
2440 (double) boundary. Some architectures (like the sparc) require
|
|
2441 this, and I suspect that floats are rare enough that it's no
|
|
2442 tragedy for those that don't. */
|
|
2443 {
|
|
2444 #if defined (__GNUC__) && (__GNUC__ >= 2)
|
|
2445 /* In gcc, we can directly ask what the alignment constraints of a
|
|
2446 structure are, but in general, that's not possible... Arrgh!!
|
|
2447 */
|
|
2448 int alignment = __alignof (struct Lisp_Float);
|
|
2449 #else /* !GNUC */
|
|
2450 /* Best guess is to make the `double' slot be aligned to the size
|
|
2451 of double (which is probably 8 bytes). This assumes that it's
|
|
2452 ok to align the beginning of the structure to the same boundary
|
|
2453 that the `double' slot in it is supposed to be aligned to; this
|
|
2454 should be ok because presumably there is padding in the layout
|
|
2455 of the struct to account for this.
|
|
2456 */
|
|
2457 int alignment = sizeof (float_data (f));
|
|
2458 #endif
|
|
2459 char *p = ((char *) PUREBEG + pureptr);
|
|
2460
|
|
2461 p = (char *) (((unsigned EMACS_INT) p + alignment - 1) & - alignment);
|
|
2462 pureptr = p - (char *) PUREBEG;
|
|
2463 }
|
|
2464
|
|
2465 if (!check_purespace (sizeof (struct Lisp_Float)))
|
|
2466 return (make_float (num));
|
|
2467
|
|
2468 f = (struct Lisp_Float *) (PUREBEG + pureptr);
|
|
2469 set_lheader_implementation (&(f->lheader), lrecord_float);
|
|
2470 pureptr += sizeof (struct Lisp_Float);
|
|
2471 bump_purestat (&purestat_float, sizeof (struct Lisp_Float));
|
|
2472
|
|
2473 float_next (f) = ((struct Lisp_Float *) -1);
|
|
2474 float_data (f) = num;
|
|
2475 XSETFLOAT (val, f);
|
|
2476 return (val);
|
|
2477 }
|
|
2478
|
|
2479 #endif /* LISP_FLOAT_TYPE */
|
|
2480
|
|
2481 Lisp_Object
|
|
2482 make_pure_vector (EMACS_INT len, Lisp_Object init)
|
|
2483 {
|
|
2484 Lisp_Object new;
|
|
2485 EMACS_INT size = (sizeof (struct Lisp_Vector)
|
|
2486 + (len - 1) * sizeof (Lisp_Object));
|
|
2487
|
|
2488 init = Fpurecopy (init);
|
|
2489
|
|
2490 if (!check_purespace (size))
|
|
2491 return (make_vector (len, init));
|
|
2492
|
|
2493 XSETVECTOR (new, PUREBEG + pureptr);
|
|
2494 pureptr += size;
|
|
2495 bump_purestat (&purestat_vector_all, size);
|
|
2496
|
|
2497 XVECTOR (new)->size = len;
|
|
2498
|
|
2499 for (size = 0; size < len; size++)
|
|
2500 vector_data (XVECTOR (new))[size] = init;
|
|
2501
|
|
2502 return (new);
|
|
2503 }
|
|
2504
|
|
2505 #if 0
|
|
2506 /* Presently unused */
|
|
2507 void *
|
|
2508 alloc_pure_lrecord (int size, struct lrecord_implementation *implementation)
|
|
2509 {
|
|
2510 struct lrecord_header *header = (void *) (PUREBEG + pureptr);
|
|
2511
|
|
2512 if (pureptr + size > PURESIZE)
|
|
2513 pure_storage_exhausted ();
|
|
2514
|
|
2515 set_lheader_implementation (header, implementation);
|
|
2516 header->next = 0;
|
|
2517 return (header);
|
|
2518 }
|
|
2519 #endif
|
|
2520
|
|
2521
|
|
2522
|
|
2523 DEFUN ("purecopy", Fpurecopy, Spurecopy, 1, 1, 0 /*
|
|
2524 Make a copy of OBJECT in pure storage.
|
|
2525 Recursively copies contents of vectors and cons cells.
|
|
2526 Does not copy symbols.
|
|
2527 */ )
|
|
2528 (obj)
|
|
2529 Lisp_Object obj;
|
|
2530 {
|
|
2531 int i;
|
|
2532 if (!purify_flag)
|
|
2533 return (obj);
|
|
2534
|
|
2535 if (!POINTER_TYPE_P (XTYPE (obj))
|
|
2536 || PURIFIED (XPNTR (obj)))
|
|
2537 return (obj);
|
|
2538
|
|
2539 switch (XTYPE (obj))
|
|
2540 {
|
|
2541 case Lisp_Cons:
|
|
2542 return pure_cons (XCAR (obj), XCDR (obj));
|
|
2543
|
|
2544 case Lisp_String:
|
16
|
2545 return make_pure_string (XSTRING_DATA (obj),
|
|
2546 XSTRING_LENGTH (obj),
|
0
|
2547 XSTRING (obj)->plist,
|
|
2548 0);
|
|
2549
|
|
2550 case Lisp_Vector:
|
|
2551 {
|
|
2552 struct Lisp_Vector *o = XVECTOR (obj);
|
|
2553 Lisp_Object new = make_pure_vector (vector_length (o), Qnil);
|
|
2554 for (i = 0; i < vector_length (o); i++)
|
|
2555 vector_data (XVECTOR (new))[i] = Fpurecopy (o->contents[i]);
|
|
2556 return (new);
|
|
2557 }
|
|
2558
|
|
2559 default:
|
|
2560 {
|
|
2561 if (COMPILED_FUNCTIONP (obj))
|
|
2562 {
|
|
2563 struct Lisp_Compiled_Function *o = XCOMPILED_FUNCTION (obj);
|
|
2564 Lisp_Object new = make_compiled_function (1);
|
|
2565 struct Lisp_Compiled_Function *n = XCOMPILED_FUNCTION (obj);
|
|
2566 n->flags = o->flags;
|
|
2567 n->bytecodes = Fpurecopy (o->bytecodes);
|
|
2568 n->constants = Fpurecopy (o->constants);
|
|
2569 n->arglist = Fpurecopy (o->arglist);
|
|
2570 n->doc_and_interactive = Fpurecopy (o->doc_and_interactive);
|
|
2571 return (new);
|
|
2572 }
|
|
2573 #ifdef LISP_FLOAT_TYPE
|
|
2574 else if (FLOATP (obj))
|
|
2575 return make_pure_float (float_data (XFLOAT (obj)));
|
|
2576 #endif /* LISP_FLOAT_TYPE */
|
|
2577 else if (!SYMBOLP (obj))
|
|
2578 signal_simple_error ("Can't purecopy %S", obj);
|
|
2579 }
|
|
2580 }
|
|
2581 return (obj);
|
|
2582 }
|
|
2583
|
|
2584
|
|
2585
|
|
2586 void
|
|
2587 report_pure_usage (int report_impurities,
|
|
2588 int die_if_pure_storage_exceeded)
|
|
2589 {
|
|
2590 if (pure_lossage)
|
|
2591 {
|
|
2592 CONST long report_round = 5000;
|
|
2593
|
|
2594 message ("\n****\tPure Lisp storage exhausted!\n"
|
|
2595 "\tCheck whether you are loading .el files when .elc files were intended.\n"
|
|
2596 "\tOtherwise, increase PURESIZE in puresize.h and relink.\n\n"
|
|
2597 "\tPURESIZE is presently %ld.\n"
|
|
2598 "\tAn additional %ld bytes will guarantee enough pure space;\n"
|
|
2599 "\ta smaller increment may work (due to structure-sharing).\n"
|
|
2600 "****",
|
|
2601 (long) PURESIZE,
|
|
2602 (((pure_lossage + report_round - 1)
|
|
2603 / report_round) * report_round));
|
|
2604 }
|
|
2605 else
|
|
2606 {
|
|
2607 int lost = (PURESIZE - pureptr) / 1024;
|
|
2608 char buf[200];
|
|
2609
|
|
2610 sprintf (buf, "Purespace usage: %ld of %ld (%d%%",
|
|
2611 pureptr, (long) PURESIZE,
|
|
2612 (int) (pureptr / (PURESIZE / 100.0) + 0.5));
|
|
2613 if (lost > 2)
|
|
2614 sprintf (buf + strlen (buf), " -- %dk wasted", lost);
|
|
2615 strcat (buf, ").");
|
|
2616 message ("%s", buf);
|
|
2617 }
|
|
2618
|
|
2619 #ifdef PURESTAT
|
|
2620 {
|
|
2621 int iii;
|
|
2622
|
|
2623 purestat_vector_other.nbytes =
|
|
2624 purestat_vector_all.nbytes - purestat_vector_bytecode_constants.nbytes;
|
|
2625 purestat_vector_other.nobjects =
|
|
2626 purestat_vector_all.nobjects -
|
|
2627 purestat_vector_bytecode_constants.nobjects;
|
|
2628
|
|
2629 purestat_string_other.nbytes =
|
|
2630 purestat_string_all.nbytes - (purestat_string_pname.nbytes +
|
|
2631 purestat_string_bytecodes.nbytes +
|
|
2632 purestat_string_interactive.nbytes +
|
|
2633 purestat_string_documentation.nbytes +
|
|
2634 #ifdef I18N3
|
|
2635 purestat_string_domain.nbytes +
|
|
2636 #endif
|
|
2637 purestat_string_other_function.nbytes);
|
|
2638 purestat_string_other.nobjects =
|
|
2639 purestat_string_all.nobjects - (purestat_string_pname.nobjects +
|
|
2640 purestat_string_bytecodes.nobjects +
|
|
2641 purestat_string_interactive.nobjects +
|
|
2642 purestat_string_documentation.nobjects +
|
|
2643 #ifdef I18N3
|
|
2644 purestat_string_domain.nobjects +
|
|
2645 #endif
|
|
2646 purestat_string_other_function.nobjects);
|
|
2647
|
|
2648 message (" %-24stotal: bytes:", "");
|
|
2649
|
|
2650 for (iii = 0; iii < countof (purestats); iii++)
|
|
2651 if (!purestats[iii])
|
|
2652 clear_message ();
|
|
2653 else
|
|
2654 message (" %-24s%5d %7d %2d%%",
|
|
2655 purestats[iii]->name,
|
|
2656 purestats[iii]->nobjects,
|
|
2657 purestats[iii]->nbytes,
|
|
2658 (int) (purestats[iii]->nbytes / (pureptr / 100.0) + 0.5));
|
|
2659 }
|
|
2660 #endif /* PURESTAT */
|
|
2661
|
|
2662
|
|
2663 if (report_impurities)
|
|
2664 {
|
|
2665 Lisp_Object tem = Felt (Fgarbage_collect (), make_int (5));
|
|
2666 struct gcpro gcpro1;
|
|
2667 GCPRO1 (tem);
|
|
2668 message ("\nImpurities:");
|
|
2669 while (!NILP (tem))
|
|
2670 {
|
|
2671 if (CONSP (tem) && SYMBOLP (Fcar (tem)) && CONSP (Fcdr (tem)))
|
|
2672 {
|
|
2673 int total = XINT (Fcar (Fcdr (tem)));
|
|
2674 if (total > 0)
|
|
2675 {
|
|
2676 char buf [100];
|
|
2677 char *s = buf;
|
|
2678 memcpy (buf, string_data (XSYMBOL (Fcar (tem))->name),
|
|
2679 string_length (XSYMBOL (Fcar (tem))->name) + 1);
|
|
2680 while (*s++) if (*s == '-') *s = ' ';
|
|
2681 s--; *s++ = ':'; *s = 0;
|
|
2682 message (" %-32s%6d", buf, total);
|
|
2683 }
|
|
2684 tem = Fcdr (Fcdr (tem));
|
|
2685 }
|
|
2686 else /* WTF?! */
|
|
2687 {
|
|
2688 Fprin1 (tem, Qexternal_debugging_output);
|
|
2689 tem = Qnil;
|
|
2690 }
|
|
2691 }
|
|
2692 UNGCPRO;
|
|
2693 garbage_collect_1 (); /* GC garbage_collect's garbage */
|
|
2694 }
|
|
2695 clear_message ();
|
|
2696
|
|
2697 if (pure_lossage && die_if_pure_storage_exceeded)
|
|
2698 fatal ("Pure storage exhausted");
|
|
2699 }
|
|
2700
|
|
2701
|
|
2702 /**********************************************************************/
|
|
2703 /* staticpro */
|
|
2704 /**********************************************************************/
|
|
2705
|
|
2706 struct gcpro *gcprolist;
|
|
2707
|
|
2708 /* 415 used Mly 29-Jun-93 */
|
|
2709 #define NSTATICS 1500
|
|
2710 /* Not "static" because of linker lossage on some systems */
|
|
2711 Lisp_Object *staticvec[NSTATICS]
|
|
2712 /* Force it into data space! */
|
|
2713 = {0};
|
|
2714 static int staticidx;
|
|
2715
|
|
2716 /* Put an entry in staticvec, pointing at the variable whose address is given
|
|
2717 */
|
|
2718 void
|
|
2719 staticpro (Lisp_Object *varaddress)
|
|
2720 {
|
|
2721 if (staticidx >= countof (staticvec))
|
|
2722 abort ();
|
|
2723 staticvec[staticidx++] = varaddress;
|
|
2724 }
|
|
2725
|
|
2726
|
|
2727 /* Mark reference to a Lisp_Object. If the object referred to has not been
|
|
2728 seen yet, recursively mark all the references contained in it. */
|
|
2729
|
|
2730 static void
|
|
2731 mark_object (Lisp_Object obj)
|
|
2732 {
|
|
2733 tail_recurse:
|
|
2734
|
|
2735 if (!POINTER_TYPE_P (XGCTYPE (obj)))
|
|
2736 return;
|
|
2737 if (PURIFIED (XPNTR (obj)))
|
|
2738 return;
|
|
2739 switch (XGCTYPE (obj))
|
|
2740 {
|
|
2741 case Lisp_Cons:
|
|
2742 {
|
|
2743 struct Lisp_Cons *ptr = XCONS (obj);
|
|
2744 if (CONS_MARKED_P (ptr))
|
|
2745 break;
|
|
2746 MARK_CONS (ptr);
|
|
2747 /* If the cdr is nil, tail-recurse on the car. */
|
|
2748 if (NILP (ptr->cdr))
|
|
2749 {
|
|
2750 obj = ptr->car;
|
|
2751 }
|
|
2752 else
|
|
2753 {
|
|
2754 mark_object (ptr->car);
|
|
2755 obj = ptr->cdr;
|
|
2756 }
|
|
2757 goto tail_recurse;
|
|
2758 }
|
|
2759
|
|
2760 case Lisp_Record:
|
|
2761 /* case Lisp_Symbol_Value_Magic: */
|
|
2762 {
|
|
2763 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
2764 CONST struct lrecord_implementation *implementation
|
|
2765 = lheader->implementation;
|
|
2766
|
|
2767 if (! MARKED_RECORD_HEADER_P (lheader) &&
|
|
2768 ! UNMARKABLE_RECORD_HEADER_P (lheader))
|
|
2769 {
|
|
2770 MARK_RECORD_HEADER (lheader);
|
|
2771 #ifdef ERROR_CHECK_GC
|
|
2772 if (!implementation->basic_p)
|
|
2773 assert (! ((struct lcrecord_header *) lheader)->free);
|
|
2774 #endif
|
|
2775 if (implementation->marker != 0)
|
|
2776 {
|
|
2777 obj = ((implementation->marker) (obj, mark_object));
|
|
2778 if (!NILP (obj)) goto tail_recurse;
|
|
2779 }
|
|
2780 }
|
|
2781 }
|
|
2782 break;
|
|
2783
|
|
2784 case Lisp_String:
|
|
2785 {
|
|
2786 struct Lisp_String *ptr = XSTRING (obj);
|
|
2787
|
|
2788 if (!XMARKBIT (ptr->plist))
|
|
2789 {
|
|
2790 if (CONSP (ptr->plist) &&
|
|
2791 EXTENT_INFOP (XCAR (ptr->plist)))
|
|
2792 flush_cached_extent_info (XCAR (ptr->plist));
|
|
2793 XMARK (ptr->plist);
|
|
2794 obj = ptr->plist;
|
|
2795 goto tail_recurse;
|
|
2796 }
|
|
2797 }
|
|
2798 break;
|
|
2799
|
|
2800 case Lisp_Vector:
|
|
2801 {
|
|
2802 struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
2803 int len = vector_length (ptr);
|
|
2804 int i;
|
|
2805
|
|
2806 if (len < 0)
|
|
2807 break; /* Already marked */
|
|
2808 ptr->size = -1 - len; /* Else mark it */
|
|
2809 for (i = 0; i < len - 1; i++) /* and then mark its elements */
|
|
2810 mark_object (ptr->contents[i]);
|
|
2811 if (len > 0)
|
|
2812 {
|
|
2813 obj = ptr->contents[len - 1];
|
|
2814 goto tail_recurse;
|
|
2815 }
|
|
2816 }
|
|
2817 break;
|
|
2818
|
|
2819 #ifndef LRECORD_SYMBOL
|
|
2820 case Lisp_Symbol:
|
|
2821 {
|
|
2822 struct Lisp_Symbol *sym = XSYMBOL (obj);
|
|
2823
|
|
2824 while (!XMARKBIT (sym->plist))
|
|
2825 {
|
|
2826 XMARK (sym->plist);
|
|
2827 mark_object (sym->value);
|
|
2828 mark_object (sym->function);
|
|
2829 {
|
|
2830 /* Open-code mark_string */
|
|
2831 /* symbol->name is a struct Lisp_String *, not a Lisp_Object */
|
|
2832 struct Lisp_String *pname = sym->name;
|
|
2833 if (!PURIFIED (pname)
|
|
2834 && !XMARKBIT (pname->plist))
|
|
2835 {
|
|
2836 XMARK (pname->plist);
|
|
2837 mark_object (pname->plist);
|
|
2838 }
|
|
2839 }
|
|
2840 if (!symbol_next (sym))
|
|
2841 {
|
|
2842 obj = sym->plist;
|
|
2843 goto tail_recurse;
|
|
2844 }
|
|
2845 mark_object (sym->plist);
|
|
2846 /* Mark the rest of the symbols in the hash-chain */
|
|
2847 sym = symbol_next (sym);
|
|
2848 }
|
|
2849 }
|
|
2850 break;
|
|
2851 #endif /* !LRECORD_SYMBOL */
|
|
2852
|
|
2853 default:
|
|
2854 abort ();
|
|
2855 }
|
|
2856 }
|
|
2857
|
|
2858 /* mark all of the conses in a list and mark the final cdr; but
|
|
2859 DO NOT mark the cars.
|
|
2860
|
|
2861 Use only for internal lists! There should never be other pointers
|
|
2862 to the cons cells, because if so, the cars will remain unmarked
|
|
2863 even when they maybe should be marked. */
|
|
2864 void
|
|
2865 mark_conses_in_list (Lisp_Object obj)
|
|
2866 {
|
|
2867 Lisp_Object rest;
|
|
2868
|
|
2869 for (rest = obj; CONSP (rest); rest = XCDR (rest))
|
|
2870 {
|
|
2871 if (CONS_MARKED_P (XCONS (rest)))
|
|
2872 return;
|
|
2873 MARK_CONS (XCONS (rest));
|
|
2874 }
|
|
2875
|
|
2876 mark_object (rest);
|
|
2877 }
|
|
2878
|
|
2879
|
|
2880 #ifdef PURESTAT
|
|
2881 /* Simpler than mark-object, because pure structure can't
|
|
2882 have any circularities
|
|
2883 */
|
|
2884
|
|
2885 #if 0 /* unused */
|
|
2886 static int idiot_c_doesnt_have_closures;
|
|
2887 static void
|
|
2888 idiot_c (Lisp_Object obj)
|
|
2889 {
|
|
2890 idiot_c_doesnt_have_closures += pure_sizeof (obj, 1);
|
|
2891 }
|
|
2892 #endif /* unused */
|
|
2893
|
|
2894 /* recurse arg isn't actually used */
|
|
2895 static int
|
|
2896 pure_sizeof (Lisp_Object obj /*, int recurse */)
|
|
2897 {
|
|
2898 int total = 0;
|
|
2899
|
|
2900 /*tail_recurse: */
|
|
2901 if (!POINTER_TYPE_P (XTYPE (obj))
|
|
2902 || !PURIFIED (XPNTR (obj)))
|
|
2903 return (total);
|
|
2904
|
|
2905 /* symbol's sizes are accounted for separately */
|
|
2906 if (SYMBOLP (obj))
|
|
2907 return (total);
|
|
2908
|
|
2909 switch (XTYPE (obj))
|
|
2910 {
|
|
2911 case Lisp_String:
|
|
2912 {
|
|
2913 struct Lisp_String *ptr = XSTRING (obj);
|
|
2914 int size = string_length (ptr);
|
|
2915
|
|
2916 if (string_data (ptr) !=
|
|
2917 (unsigned char *) ptr + sizeof (struct Lisp_String))
|
|
2918 {
|
|
2919 /* string-data not allocated contiguously.
|
|
2920 Probably (better be!!) a pointer constant "C" data. */
|
|
2921 size = sizeof (struct Lisp_String);
|
|
2922 }
|
|
2923 else
|
|
2924 {
|
|
2925 size = sizeof (struct Lisp_String) + size + 1;
|
|
2926 size = ALIGN_SIZE (size, sizeof (Lisp_Object));
|
|
2927 }
|
|
2928 total += size;
|
|
2929 }
|
|
2930 break;
|
|
2931
|
|
2932 case Lisp_Vector:
|
|
2933 {
|
|
2934 struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
2935 int len = vector_length (ptr);
|
|
2936
|
|
2937 total += (sizeof (struct Lisp_Vector)
|
|
2938 + (len - 1) * sizeof (Lisp_Object));
|
|
2939 #if 0 /* unused */
|
|
2940 if (!recurse)
|
|
2941 break;
|
|
2942 {
|
|
2943 int i;
|
|
2944 for (i = 0; i < len - 1; i++)
|
|
2945 total += pure_sizeof (ptr->contents[i], 1);
|
|
2946 }
|
|
2947 if (len > 0)
|
|
2948 {
|
|
2949 obj = ptr->contents[len - 1];
|
|
2950 goto tail_recurse;
|
|
2951 }
|
|
2952 #endif /* unused */
|
|
2953 }
|
|
2954 break;
|
|
2955
|
|
2956 case Lisp_Record:
|
|
2957 {
|
|
2958 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
2959 CONST struct lrecord_implementation *implementation
|
|
2960 = lheader->implementation;
|
|
2961
|
|
2962 if (implementation->size_in_bytes_method)
|
|
2963 total += ((implementation->size_in_bytes_method) (lheader));
|
|
2964 else
|
|
2965 total += implementation->static_size;
|
|
2966
|
|
2967 #if 0 /* unused */
|
|
2968 if (!recurse)
|
|
2969 break;
|
|
2970
|
|
2971 if (implementation->marker != 0)
|
|
2972 {
|
|
2973 int old = idiot_c_doesnt_have_closures;
|
|
2974
|
|
2975 idiot_c_doesnt_have_closures = 0;
|
|
2976 obj = ((implementation->marker) (obj, idiot_c));
|
|
2977 total += idiot_c_doesnt_have_closures;
|
|
2978 idiot_c_doesnt_have_closures = old;
|
|
2979
|
|
2980 if (!NILP (obj)) goto tail_recurse;
|
|
2981 }
|
|
2982 #endif /* unused */
|
|
2983 }
|
|
2984 break;
|
|
2985
|
|
2986 case Lisp_Cons:
|
|
2987 {
|
|
2988 struct Lisp_Cons *ptr = XCONS (obj);
|
|
2989 total += sizeof (*ptr);
|
|
2990 #if 0 /* unused */
|
|
2991 if (!recurse)
|
|
2992 break;
|
|
2993 /* If the cdr is nil, tail-recurse on the car. */
|
|
2994 if (NILP (ptr->cdr))
|
|
2995 {
|
|
2996 obj = ptr->car;
|
|
2997 }
|
|
2998 else
|
|
2999 {
|
|
3000 total += pure_sizeof (ptr->car, 1);
|
|
3001 obj = ptr->cdr;
|
|
3002 }
|
|
3003 goto tail_recurse;
|
|
3004 #endif /* unused */
|
|
3005 }
|
|
3006 break;
|
|
3007
|
|
3008 /* Others can't be purified */
|
|
3009 default:
|
|
3010 abort ();
|
|
3011 }
|
|
3012 return (total);
|
|
3013 }
|
|
3014 #endif /* PURESTAT */
|
|
3015
|
|
3016
|
|
3017
|
|
3018
|
|
3019 /* Find all structures not marked, and free them. */
|
|
3020
|
|
3021 static int gc_count_num_vector_used, gc_count_vector_total_size;
|
|
3022 static int gc_count_vector_storage;
|
|
3023 static int gc_count_num_bit_vector_used, gc_count_bit_vector_total_size;
|
|
3024 static int gc_count_bit_vector_storage;
|
|
3025 static int gc_count_num_short_string_in_use;
|
|
3026 static int gc_count_string_total_size;
|
|
3027 static int gc_count_short_string_total_size;
|
|
3028
|
|
3029 /* static int gc_count_total_records_used, gc_count_records_total_size; */
|
|
3030
|
|
3031
|
|
3032 /* This will be used more extensively In The Future */
|
|
3033 static int last_lrecord_type_index_assigned;
|
|
3034
|
|
3035 static CONST struct lrecord_implementation *lrecord_implementations_table[128];
|
|
3036 #define max_lrecord_type (countof (lrecord_implementations_table) - 1)
|
|
3037
|
|
3038 static int
|
|
3039 lrecord_type_index (CONST struct lrecord_implementation *implementation)
|
|
3040 {
|
|
3041 int type_index = *(implementation->lrecord_type_index);
|
|
3042 /* Have to do this circuitous and validation test because of problems
|
|
3043 dumping out initialized variables (ie can't set xxx_type_index to -1
|
|
3044 because that would make xxx_type_index read-only in a dumped emacs. */
|
|
3045 if (type_index < 0 || type_index > max_lrecord_type
|
|
3046 || lrecord_implementations_table[type_index] != implementation)
|
|
3047 {
|
|
3048 if (last_lrecord_type_index_assigned == max_lrecord_type)
|
|
3049 abort ();
|
|
3050 type_index = ++last_lrecord_type_index_assigned;
|
|
3051 lrecord_implementations_table[type_index] = implementation;
|
|
3052 *(implementation->lrecord_type_index) = type_index;
|
|
3053 }
|
|
3054 return (type_index);
|
|
3055 }
|
|
3056
|
|
3057 /* stats on lcrecords in use - kinda kludgy */
|
|
3058
|
|
3059 static struct
|
|
3060 {
|
|
3061 int instances_in_use;
|
|
3062 int bytes_in_use;
|
|
3063 int instances_freed;
|
|
3064 int bytes_freed;
|
|
3065 int instances_on_free_list;
|
|
3066 } lcrecord_stats [countof (lrecord_implementations_table)];
|
|
3067
|
|
3068
|
|
3069 static void
|
|
3070 reset_lcrecord_stats (void)
|
|
3071 {
|
|
3072 int i;
|
|
3073 for (i = 0; i < countof (lcrecord_stats); i++)
|
|
3074 {
|
|
3075 lcrecord_stats[i].instances_in_use = 0;
|
|
3076 lcrecord_stats[i].bytes_in_use = 0;
|
|
3077 lcrecord_stats[i].instances_freed = 0;
|
|
3078 lcrecord_stats[i].bytes_freed = 0;
|
|
3079 lcrecord_stats[i].instances_on_free_list = 0;
|
|
3080 }
|
|
3081 }
|
|
3082
|
|
3083 static void
|
|
3084 tick_lcrecord_stats (CONST struct lrecord_header *h, int free_p)
|
|
3085 {
|
|
3086 CONST struct lrecord_implementation *implementation = h->implementation;
|
|
3087 int type_index = lrecord_type_index (implementation);
|
|
3088
|
|
3089 if (((struct lcrecord_header *) h)->free)
|
|
3090 {
|
|
3091 assert (!free_p);
|
|
3092 lcrecord_stats[type_index].instances_on_free_list++;
|
|
3093 }
|
|
3094 else
|
|
3095 {
|
|
3096 unsigned int sz = (implementation->size_in_bytes_method
|
|
3097 ? ((implementation->size_in_bytes_method) (h))
|
|
3098 : implementation->static_size);
|
|
3099
|
|
3100 if (free_p)
|
|
3101 {
|
|
3102 lcrecord_stats[type_index].instances_freed++;
|
|
3103 lcrecord_stats[type_index].bytes_freed += sz;
|
|
3104 }
|
|
3105 else
|
|
3106 {
|
|
3107 lcrecord_stats[type_index].instances_in_use++;
|
|
3108 lcrecord_stats[type_index].bytes_in_use += sz;
|
|
3109 }
|
|
3110 }
|
|
3111 }
|
|
3112
|
|
3113
|
|
3114 /* Free all unmarked records */
|
|
3115 static void
|
|
3116 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
|
|
3117 {
|
|
3118 struct lcrecord_header *header;
|
|
3119 int num_used = 0;
|
|
3120 /* int total_size = 0; */
|
|
3121 reset_lcrecord_stats ();
|
|
3122
|
|
3123 /* First go through and call all the finalize methods.
|
|
3124 Then go through and free the objects. There used to
|
|
3125 be only one loop here, with the call to the finalizer
|
|
3126 occurring directly before the xfree() below. That
|
|
3127 is marginally faster but much less safe -- if the
|
|
3128 finalize method for an object needs to reference any
|
|
3129 other objects contained within it (and many do),
|
|
3130 we could easily be screwed by having already freed that
|
|
3131 other object. */
|
|
3132
|
|
3133 for (header = *prev; header; header = header->next)
|
|
3134 {
|
|
3135 struct lrecord_header *h = &(header->lheader);
|
|
3136 if (!MARKED_RECORD_HEADER_P (h) && ! (header->free))
|
|
3137 {
|
|
3138 if (h->implementation->finalizer)
|
|
3139 ((h->implementation->finalizer) (h, 0));
|
|
3140 }
|
|
3141 }
|
|
3142
|
|
3143 for (header = *prev; header; )
|
|
3144 {
|
|
3145 struct lrecord_header *h = &(header->lheader);
|
|
3146 if (MARKED_RECORD_HEADER_P (h))
|
|
3147 {
|
|
3148 UNMARK_RECORD_HEADER (h);
|
|
3149 num_used++;
|
|
3150 /* total_size += ((n->implementation->size_in_bytes) (h));*/
|
|
3151 prev = &(header->next);
|
|
3152 header = *prev;
|
|
3153 tick_lcrecord_stats (h, 0);
|
|
3154 }
|
|
3155 else
|
|
3156 {
|
|
3157 struct lcrecord_header *next = header->next;
|
|
3158 *prev = next;
|
|
3159 tick_lcrecord_stats (h, 1);
|
|
3160 /* used to call finalizer right here. */
|
|
3161 xfree (header);
|
|
3162 header = next;
|
|
3163 }
|
|
3164 }
|
|
3165 *used = num_used;
|
|
3166 /* *total = total_size; */
|
|
3167 }
|
|
3168
|
|
3169 static void
|
|
3170 sweep_vectors_1 (Lisp_Object *prev,
|
|
3171 int *used, int *total, int *storage)
|
|
3172 {
|
|
3173 Lisp_Object vector;
|
|
3174 int num_used = 0;
|
|
3175 int total_size = 0;
|
|
3176 int total_storage = 0;
|
|
3177
|
|
3178 for (vector = *prev; VECTORP (vector); )
|
|
3179 {
|
|
3180 struct Lisp_Vector *v = XVECTOR (vector);
|
|
3181 int len = v->size;
|
|
3182 if (len < 0) /* marked */
|
|
3183 {
|
|
3184 len = - (len + 1);
|
|
3185 v->size = len;
|
|
3186 total_size += len;
|
|
3187 total_storage += (MALLOC_OVERHEAD
|
|
3188 + sizeof (struct Lisp_Vector)
|
|
3189 + (len - 1 + 1) * sizeof (Lisp_Object));
|
|
3190 num_used++;
|
|
3191 prev = &(vector_next (v));
|
|
3192 vector = *prev;
|
|
3193 }
|
|
3194 else
|
|
3195 {
|
|
3196 Lisp_Object next = vector_next (v);
|
|
3197 *prev = next;
|
|
3198 xfree (v);
|
|
3199 vector = next;
|
|
3200 }
|
|
3201 }
|
|
3202 *used = num_used;
|
|
3203 *total = total_size;
|
|
3204 *storage = total_storage;
|
|
3205 }
|
|
3206
|
|
3207 static void
|
|
3208 sweep_bit_vectors_1 (Lisp_Object *prev,
|
|
3209 int *used, int *total, int *storage)
|
|
3210 {
|
|
3211 Lisp_Object bit_vector;
|
|
3212 int num_used = 0;
|
|
3213 int total_size = 0;
|
|
3214 int total_storage = 0;
|
|
3215
|
|
3216 /* BIT_VECTORP fails because the objects are marked, which changes
|
|
3217 their implementation */
|
|
3218 for (bit_vector = *prev; !EQ (bit_vector, Qzero); )
|
|
3219 {
|
|
3220 struct Lisp_Bit_Vector *v = XBIT_VECTOR (bit_vector);
|
|
3221 int len = v->size;
|
|
3222 if (MARKED_RECORD_P (bit_vector))
|
|
3223 {
|
|
3224 UNMARK_RECORD_HEADER (&(v->lheader));
|
|
3225 total_size += len;
|
|
3226 total_storage += (MALLOC_OVERHEAD
|
|
3227 + sizeof (struct Lisp_Bit_Vector)
|
|
3228 + (BIT_VECTOR_LONG_STORAGE (len) - 1)
|
|
3229 * sizeof (long));
|
|
3230 num_used++;
|
|
3231 prev = &(bit_vector_next (v));
|
|
3232 bit_vector = *prev;
|
|
3233 }
|
|
3234 else
|
|
3235 {
|
|
3236 Lisp_Object next = bit_vector_next (v);
|
|
3237 *prev = next;
|
|
3238 xfree (v);
|
|
3239 bit_vector = next;
|
|
3240 }
|
|
3241 }
|
|
3242 *used = num_used;
|
|
3243 *total = total_size;
|
|
3244 *storage = total_storage;
|
|
3245 }
|
|
3246
|
|
3247 /* And the Lord said: Thou shalt use the `c-backslash-region' command
|
|
3248 to make macros prettier. */
|
|
3249
|
|
3250 #ifdef ERROR_CHECK_GC
|
|
3251
|
|
3252 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
|
|
3253 do { \
|
|
3254 struct typename##_block *_frob_current; \
|
|
3255 struct typename##_block **_frob_prev; \
|
|
3256 int _frob_limit; \
|
|
3257 int num_free = 0, num_used = 0; \
|
|
3258 \
|
|
3259 for (_frob_prev = ¤t_##typename##_block, \
|
|
3260 _frob_current = current_##typename##_block, \
|
|
3261 _frob_limit = current_##typename##_block_index; \
|
|
3262 _frob_current; \
|
|
3263 ) \
|
|
3264 { \
|
|
3265 int _frob_iii; \
|
|
3266 \
|
|
3267 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
|
|
3268 { \
|
|
3269 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
|
|
3270 \
|
|
3271 if (FREE_STRUCT_P (_frob_victim)) \
|
|
3272 { \
|
|
3273 num_free++; \
|
|
3274 } \
|
|
3275 else if (!MARKED_##typename##_P (_frob_victim)) \
|
|
3276 { \
|
|
3277 num_free++; \
|
|
3278 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
|
|
3279 } \
|
|
3280 else \
|
|
3281 { \
|
|
3282 num_used++; \
|
|
3283 UNMARK_##typename (_frob_victim); \
|
|
3284 } \
|
|
3285 } \
|
|
3286 _frob_prev = &(_frob_current->prev); \
|
|
3287 _frob_current = _frob_current->prev; \
|
|
3288 _frob_limit = countof (current_##typename##_block->block); \
|
|
3289 } \
|
|
3290 \
|
|
3291 gc_count_num_##typename##_in_use = num_used; \
|
|
3292 gc_count_num_##typename##_freelist = num_free; \
|
|
3293 } while (0)
|
|
3294
|
|
3295 #else
|
|
3296
|
|
3297 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
|
|
3298 do { \
|
|
3299 struct typename##_block *_frob_current; \
|
|
3300 struct typename##_block **_frob_prev; \
|
|
3301 int _frob_limit; \
|
|
3302 int num_free = 0, num_used = 0; \
|
|
3303 \
|
|
3304 typename##_free_list = 0; \
|
|
3305 \
|
|
3306 for (_frob_prev = ¤t_##typename##_block, \
|
|
3307 _frob_current = current_##typename##_block, \
|
|
3308 _frob_limit = current_##typename##_block_index; \
|
|
3309 _frob_current; \
|
|
3310 ) \
|
|
3311 { \
|
|
3312 int _frob_iii; \
|
|
3313 int _frob_empty = 1; \
|
|
3314 obj_type *_frob_old_free_list = typename##_free_list; \
|
|
3315 \
|
|
3316 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
|
|
3317 { \
|
|
3318 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
|
|
3319 \
|
|
3320 if (FREE_STRUCT_P (_frob_victim)) \
|
|
3321 { \
|
|
3322 num_free++; \
|
|
3323 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, _frob_victim); \
|
|
3324 } \
|
|
3325 else if (!MARKED_##typename##_P (_frob_victim)) \
|
|
3326 { \
|
|
3327 num_free++; \
|
|
3328 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
|
|
3329 } \
|
|
3330 else \
|
|
3331 { \
|
|
3332 _frob_empty = 0; \
|
|
3333 num_used++; \
|
|
3334 UNMARK_##typename (_frob_victim); \
|
|
3335 } \
|
|
3336 } \
|
|
3337 if (!_frob_empty) \
|
|
3338 { \
|
|
3339 _frob_prev = &(_frob_current->prev); \
|
|
3340 _frob_current = _frob_current->prev; \
|
|
3341 } \
|
|
3342 else if (_frob_current == current_##typename##_block \
|
|
3343 && !_frob_current->prev) \
|
|
3344 { \
|
|
3345 /* No real point in freeing sole allocation block */ \
|
|
3346 break; \
|
|
3347 } \
|
|
3348 else \
|
|
3349 { \
|
|
3350 struct typename##_block *_frob_victim_block = _frob_current; \
|
|
3351 if (_frob_victim_block == current_##typename##_block) \
|
|
3352 current_##typename##_block_index \
|
|
3353 = countof (current_##typename##_block->block); \
|
|
3354 _frob_current = _frob_current->prev; \
|
|
3355 { \
|
|
3356 *_frob_prev = _frob_current; \
|
|
3357 xfree (_frob_victim_block); \
|
|
3358 /* Restore free list to what it was before victim was swept */ \
|
|
3359 typename##_free_list = _frob_old_free_list; \
|
|
3360 num_free -= _frob_limit; \
|
|
3361 } \
|
|
3362 } \
|
|
3363 _frob_limit = countof (current_##typename##_block->block); \
|
|
3364 } \
|
|
3365 \
|
|
3366 gc_count_num_##typename##_in_use = num_used; \
|
|
3367 gc_count_num_##typename##_freelist = num_free; \
|
|
3368 } while (0)
|
|
3369
|
|
3370 #endif
|
|
3371
|
|
3372
|
|
3373
|
|
3374
|
|
3375 static void
|
|
3376 sweep_conses (void)
|
|
3377 {
|
|
3378 #define MARKED_cons_P(ptr) XMARKBIT ((ptr)->car)
|
|
3379 #define UNMARK_cons(ptr) do { XUNMARK ((ptr)->car); } while (0)
|
|
3380 #define ADDITIONAL_FREE_cons(ptr)
|
|
3381
|
|
3382 SWEEP_FIXED_TYPE_BLOCK (cons, struct Lisp_Cons);
|
|
3383 }
|
|
3384
|
|
3385 /* Explicitly free a cons cell. */
|
|
3386 void
|
|
3387 free_cons (struct Lisp_Cons *ptr)
|
|
3388 {
|
|
3389 #ifdef ERROR_CHECK_GC
|
|
3390 /* If the CAR is not an int, then it will be a pointer, which will
|
|
3391 always be four-byte aligned. If this cons cell has already been
|
|
3392 placed on the free list, however, its car will probably contain
|
|
3393 a chain pointer to the next cons on the list, which has cleverly
|
|
3394 had all its 0's and 1's inverted. This allows for a quick
|
|
3395 check to make sure we're not freeing something already freed. */
|
|
3396 if (POINTER_TYPE_P (XTYPE (ptr->car)))
|
|
3397 ASSERT_VALID_POINTER (XPNTR (ptr->car));
|
|
3398 #endif
|
|
3399 #ifndef ALLOC_NO_POOLS
|
|
3400 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, struct Lisp_Cons, ptr);
|
|
3401 #endif /* ALLOC_NO_POOLS */
|
|
3402 }
|
|
3403
|
|
3404 /* explicitly free a list. You **must make sure** that you have
|
|
3405 created all the cons cells that make up this list and that there
|
|
3406 are no pointers to any of these cons cells anywhere else. If there
|
|
3407 are, you will lose. */
|
|
3408
|
|
3409 void
|
|
3410 free_list (Lisp_Object list)
|
|
3411 {
|
|
3412 Lisp_Object rest, next;
|
|
3413
|
|
3414 for (rest = list; !NILP (rest); rest = next)
|
|
3415 {
|
|
3416 next = XCDR (rest);
|
|
3417 free_cons (XCONS (rest));
|
|
3418 }
|
|
3419 }
|
|
3420
|
|
3421 /* explicitly free an alist. You **must make sure** that you have
|
|
3422 created all the cons cells that make up this alist and that there
|
|
3423 are no pointers to any of these cons cells anywhere else. If there
|
|
3424 are, you will lose. */
|
|
3425
|
|
3426 void
|
|
3427 free_alist (Lisp_Object alist)
|
|
3428 {
|
|
3429 Lisp_Object rest, next;
|
|
3430
|
|
3431 for (rest = alist; !NILP (rest); rest = next)
|
|
3432 {
|
|
3433 next = XCDR (rest);
|
|
3434 free_cons (XCONS (XCAR (rest)));
|
|
3435 free_cons (XCONS (rest));
|
|
3436 }
|
|
3437 }
|
|
3438
|
|
3439 static void
|
|
3440 sweep_compiled_functions (void)
|
|
3441 {
|
|
3442 #define MARKED_compiled_function_P(ptr) \
|
|
3443 MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3444 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3445 #define ADDITIONAL_FREE_compiled_function(ptr)
|
|
3446
|
|
3447 SWEEP_FIXED_TYPE_BLOCK (compiled_function, struct Lisp_Compiled_Function);
|
|
3448 }
|
|
3449
|
|
3450
|
|
3451 #ifdef LISP_FLOAT_TYPE
|
|
3452 static void
|
|
3453 sweep_floats (void)
|
|
3454 {
|
|
3455 #define MARKED_float_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3456 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3457 #define ADDITIONAL_FREE_float(ptr)
|
|
3458
|
|
3459 SWEEP_FIXED_TYPE_BLOCK (float, struct Lisp_Float);
|
|
3460 }
|
|
3461 #endif /* LISP_FLOAT_TYPE */
|
|
3462
|
|
3463 static void
|
|
3464 sweep_symbols (void)
|
|
3465 {
|
|
3466 #ifndef LRECORD_SYMBOL
|
|
3467 # define MARKED_symbol_P(ptr) XMARKBIT ((ptr)->plist)
|
|
3468 # define UNMARK_symbol(ptr) do { XUNMARK ((ptr)->plist); } while (0)
|
|
3469 #else
|
|
3470 # define MARKED_symbol_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3471 # define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3472 #endif /* !LRECORD_SYMBOL */
|
|
3473 #define ADDITIONAL_FREE_symbol(ptr)
|
|
3474
|
|
3475 SWEEP_FIXED_TYPE_BLOCK (symbol, struct Lisp_Symbol);
|
|
3476 }
|
|
3477
|
|
3478
|
|
3479 #ifndef standalone
|
|
3480
|
|
3481 static void
|
|
3482 sweep_extents (void)
|
|
3483 {
|
|
3484 #define MARKED_extent_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3485 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3486 #define ADDITIONAL_FREE_extent(ptr)
|
|
3487
|
|
3488 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent);
|
|
3489 }
|
|
3490
|
|
3491 static void
|
|
3492 sweep_events (void)
|
|
3493 {
|
|
3494 #define MARKED_event_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3495 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3496 #define ADDITIONAL_FREE_event(ptr)
|
|
3497
|
|
3498 SWEEP_FIXED_TYPE_BLOCK (event, struct Lisp_Event);
|
|
3499 }
|
|
3500
|
|
3501 static void
|
|
3502 sweep_markers (void)
|
|
3503 {
|
|
3504 #define MARKED_marker_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3505 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3506 #define ADDITIONAL_FREE_marker(ptr) \
|
|
3507 do { Lisp_Object tem; \
|
|
3508 XSETMARKER (tem, ptr); \
|
|
3509 unchain_marker (tem); \
|
|
3510 } while (0)
|
|
3511
|
|
3512 SWEEP_FIXED_TYPE_BLOCK (marker, struct Lisp_Marker);
|
|
3513 }
|
|
3514
|
|
3515 /* Explicitly free a marker. */
|
|
3516 void
|
|
3517 free_marker (struct Lisp_Marker *ptr)
|
|
3518 {
|
|
3519 #ifdef ERROR_CHECK_GC
|
|
3520 /* Perhaps this will catch freeing an already-freed marker. */
|
|
3521 Lisp_Object temmy;
|
|
3522 XSETMARKER (temmy, ptr);
|
|
3523 assert (GC_MARKERP (temmy));
|
|
3524 #endif
|
|
3525 #ifndef ALLOC_NO_POOLS
|
|
3526 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, struct Lisp_Marker, ptr);
|
|
3527 #endif /* ALLOC_NO_POOLS */
|
|
3528 }
|
|
3529
|
|
3530 #endif /* not standalone */
|
|
3531
|
|
3532
|
|
3533 /* Compactify string chars, relocating the reference to each --
|
|
3534 free any empty string_chars_block we see. */
|
|
3535 static void
|
|
3536 compact_string_chars (void)
|
|
3537 {
|
|
3538 struct string_chars_block *to_sb = first_string_chars_block;
|
|
3539 int to_pos = 0;
|
|
3540 struct string_chars_block *from_sb;
|
|
3541
|
|
3542 /* Scan each existing string block sequentially, string by string. */
|
|
3543 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next)
|
|
3544 {
|
|
3545 int from_pos = 0;
|
|
3546 /* FROM_POS is the index of the next string in the block. */
|
|
3547 while (from_pos < from_sb->pos)
|
|
3548 {
|
|
3549 struct string_chars *from_s_chars =
|
|
3550 (struct string_chars *) &(from_sb->string_chars[from_pos]);
|
|
3551 struct string_chars *to_s_chars;
|
|
3552 struct Lisp_String *string;
|
|
3553 int size;
|
|
3554 int fullsize;
|
|
3555
|
|
3556 /* If the string_chars struct is marked as free (i.e. the STRING
|
|
3557 pointer is 0xFFFFFFFF) then this is an unused chunk of string
|
|
3558 storage. This happens under Mule when a string's size changes
|
|
3559 in such a way that its fullsize changes. (Strings can change
|
|
3560 size because a different-length character can be substituted
|
|
3561 for another character.) In this case, after the bogus string
|
|
3562 pointer is the "fullsize" of this entry, i.e. how many bytes
|
|
3563 to skip. */
|
|
3564
|
|
3565 if (FREE_STRUCT_P (from_s_chars))
|
|
3566 {
|
|
3567 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize;
|
|
3568 from_pos += fullsize;
|
|
3569 continue;
|
|
3570 }
|
|
3571
|
|
3572 string = from_s_chars->string;
|
|
3573 assert (!(FREE_STRUCT_P (string)));
|
|
3574
|
|
3575 size = string_length (string);
|
|
3576 fullsize = STRING_FULLSIZE (size);
|
|
3577
|
|
3578 if (BIG_STRING_FULLSIZE_P (fullsize))
|
|
3579 abort ();
|
|
3580
|
|
3581 /* Just skip it if it isn't marked. */
|
|
3582 if (!XMARKBIT (string->plist))
|
|
3583 {
|
|
3584 from_pos += fullsize;
|
|
3585 continue;
|
|
3586 }
|
|
3587
|
|
3588 /* If it won't fit in what's left of TO_SB, close TO_SB out
|
|
3589 and go on to the next string_chars_block. We know that TO_SB
|
|
3590 cannot advance past FROM_SB here since FROM_SB is large enough
|
|
3591 to currently contain this string. */
|
|
3592 if ((to_pos + fullsize) > countof (to_sb->string_chars))
|
|
3593 {
|
|
3594 to_sb->pos = to_pos;
|
|
3595 to_sb = to_sb->next;
|
|
3596 to_pos = 0;
|
|
3597 }
|
|
3598
|
|
3599 /* Compute new address of this string
|
|
3600 and update TO_POS for the space being used. */
|
|
3601 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]);
|
|
3602
|
|
3603 /* Copy the string_chars to the new place. */
|
|
3604 if (from_s_chars != to_s_chars)
|
|
3605 memmove (to_s_chars, from_s_chars, fullsize);
|
|
3606
|
|
3607 /* Relocate FROM_S_CHARS's reference */
|
|
3608 set_string_data (string, &(to_s_chars->chars[0]));
|
|
3609
|
|
3610 from_pos += fullsize;
|
|
3611 to_pos += fullsize;
|
|
3612 }
|
|
3613 }
|
|
3614
|
|
3615 /* Set current to the last string chars block still used and
|
|
3616 free any that follow. */
|
|
3617 {
|
|
3618 struct string_chars_block *victim;
|
|
3619
|
|
3620 for (victim = to_sb->next; victim; )
|
|
3621 {
|
|
3622 struct string_chars_block *next = victim->next;
|
|
3623 xfree (victim);
|
|
3624 victim = next;
|
|
3625 }
|
|
3626
|
|
3627 current_string_chars_block = to_sb;
|
|
3628 current_string_chars_block->pos = to_pos;
|
|
3629 current_string_chars_block->next = 0;
|
|
3630 }
|
|
3631 }
|
|
3632
|
|
3633 #if 1 /* Hack to debug missing purecopy's */
|
|
3634 static int debug_string_purity;
|
|
3635
|
|
3636 static void
|
|
3637 debug_string_purity_print (struct Lisp_String *p)
|
|
3638 {
|
|
3639 Charcount i;
|
|
3640 Charcount s = string_char_length (p);
|
|
3641 putc ('\"', stderr);
|
|
3642 for (i = 0; i < s; i++)
|
|
3643 {
|
|
3644 Emchar ch = string_char (p, i);
|
|
3645 if (ch < 32 || ch >= 126)
|
|
3646 stderr_out ("\\%03o", ch);
|
|
3647 else if (ch == '\\' || ch == '\"')
|
|
3648 stderr_out ("\\%c", ch);
|
|
3649 else
|
|
3650 stderr_out ("%c", ch);
|
|
3651 }
|
|
3652 stderr_out ("\"\n");
|
|
3653 }
|
|
3654 #endif
|
|
3655
|
|
3656
|
|
3657 static void
|
|
3658 sweep_strings (void)
|
|
3659 {
|
|
3660 int num_small_used = 0, num_small_bytes = 0, num_bytes = 0;
|
|
3661 int debug = debug_string_purity;
|
|
3662
|
|
3663 #define MARKED_string_P(ptr) XMARKBIT ((ptr)->plist)
|
|
3664 #define UNMARK_string(ptr) \
|
|
3665 do { struct Lisp_String *p = (ptr); \
|
|
3666 int size = string_length (p); \
|
|
3667 XUNMARK (p->plist); \
|
|
3668 num_bytes += size; \
|
|
3669 if (!BIG_STRING_SIZE_P (size)) \
|
|
3670 { num_small_bytes += size; \
|
|
3671 num_small_used++; \
|
|
3672 } \
|
|
3673 if (debug) debug_string_purity_print (p); \
|
|
3674 } while (0)
|
|
3675 #define ADDITIONAL_FREE_string(p) \
|
|
3676 do { int size = string_length (p); \
|
|
3677 if (BIG_STRING_SIZE_P (size)) \
|
|
3678 xfree_1 (CHARS_TO_STRING_CHAR (string_data (p))); \
|
|
3679 } while (0)
|
|
3680
|
|
3681 SWEEP_FIXED_TYPE_BLOCK (string, struct Lisp_String);
|
|
3682
|
|
3683 gc_count_num_short_string_in_use = num_small_used;
|
|
3684 gc_count_string_total_size = num_bytes;
|
|
3685 gc_count_short_string_total_size = num_small_bytes;
|
|
3686 }
|
|
3687
|
|
3688
|
|
3689 /* I hate duplicating all this crap! */
|
|
3690 static int
|
|
3691 marked_p (Lisp_Object obj)
|
|
3692 {
|
|
3693 if (!POINTER_TYPE_P (XGCTYPE (obj))) return 1;
|
|
3694 if (PURIFIED (XPNTR (obj))) return 1;
|
|
3695 switch (XGCTYPE (obj))
|
|
3696 {
|
|
3697 case Lisp_Cons:
|
|
3698 return XMARKBIT (XCAR (obj));
|
|
3699 case Lisp_Record:
|
|
3700 return MARKED_RECORD_HEADER_P (XRECORD_LHEADER (obj));
|
|
3701 case Lisp_String:
|
|
3702 return XMARKBIT (XSTRING (obj)->plist);
|
|
3703 case Lisp_Vector:
|
|
3704 return (vector_length (XVECTOR (obj)) < 0);
|
|
3705 #ifndef LRECORD_SYMBOL
|
|
3706 case Lisp_Symbol:
|
|
3707 return XMARKBIT (XSYMBOL (obj)->plist);
|
|
3708 #endif
|
|
3709 default:
|
|
3710 abort ();
|
|
3711 }
|
|
3712 return 0; /* suppress compiler warning */
|
|
3713 }
|
|
3714
|
|
3715 static void
|
|
3716 gc_sweep (void)
|
|
3717 {
|
|
3718 /* Free all unmarked records. Do this at the very beginning,
|
|
3719 before anything else, so that the finalize methods can safely
|
|
3720 examine items in the objects. sweep_lcrecords_1() makes
|
|
3721 sure to call all the finalize methods *before* freeing anything,
|
|
3722 to complete the safety. */
|
|
3723 {
|
|
3724 int ignored;
|
|
3725 sweep_lcrecords_1 (&all_lcrecords, &ignored);
|
|
3726 }
|
|
3727
|
|
3728 compact_string_chars ();
|
|
3729
|
|
3730 /* Finalize methods below (called through the ADDITIONAL_FREE_foo
|
|
3731 macros) must be *extremely* careful to make sure they're not
|
|
3732 referencing freed objects. The only two existing finalize
|
|
3733 methods (for strings and markers) pass muster -- the string
|
|
3734 finalizer doesn't look at anything but its own specially-
|
|
3735 created block, and the marker finalizer only looks at live
|
|
3736 buffers (which will never be freed) and at the markers before
|
|
3737 and after it in the chain (which, by induction, will never be
|
|
3738 freed because if so, they would have already removed themselves
|
|
3739 from the chain). */
|
|
3740
|
|
3741 /* Put all unmarked strings on free list, free'ing the string chars
|
|
3742 of large unmarked strings */
|
|
3743 sweep_strings ();
|
|
3744
|
|
3745 /* Put all unmarked conses on free list */
|
|
3746 sweep_conses ();
|
|
3747
|
|
3748 /* Free all unmarked vectors */
|
|
3749 sweep_vectors_1 (&all_vectors,
|
|
3750 &gc_count_num_vector_used, &gc_count_vector_total_size,
|
|
3751 &gc_count_vector_storage);
|
|
3752
|
|
3753 /* Free all unmarked bit vectors */
|
|
3754 sweep_bit_vectors_1 (&all_bit_vectors,
|
|
3755 &gc_count_num_bit_vector_used,
|
|
3756 &gc_count_bit_vector_total_size,
|
|
3757 &gc_count_bit_vector_storage);
|
|
3758
|
|
3759 /* Free all unmarked compiled-function objects */
|
|
3760 sweep_compiled_functions ();
|
|
3761
|
|
3762 #ifdef LISP_FLOAT_TYPE
|
|
3763 /* Put all unmarked floats on free list */
|
|
3764 sweep_floats ();
|
|
3765 #endif
|
|
3766
|
|
3767 /* Put all unmarked symbols on free list */
|
|
3768 sweep_symbols ();
|
|
3769
|
|
3770 /* Put all unmarked extents on free list */
|
|
3771 sweep_extents ();
|
|
3772
|
|
3773 /* Put all unmarked markers on free list.
|
|
3774 Dechain each one first from the buffer into which it points. */
|
|
3775 sweep_markers ();
|
|
3776
|
|
3777 sweep_events ();
|
|
3778
|
|
3779 }
|
|
3780
|
|
3781 /* Clearing for disksave. */
|
|
3782
|
|
3783 extern Lisp_Object Vprocess_environment;
|
|
3784 extern Lisp_Object Vdoc_directory;
|
|
3785 extern Lisp_Object Vconfigure_info_directory;
|
|
3786 extern Lisp_Object Vload_path;
|
|
3787 extern Lisp_Object Vload_history;
|
|
3788 extern Lisp_Object Vshell_file_name;
|
|
3789
|
|
3790 void
|
|
3791 disksave_object_finalization (void)
|
|
3792 {
|
|
3793 /* It's important that certain information from the environment not get
|
|
3794 dumped with the executable (pathnames, environment variables, etc.).
|
|
3795 To make it easier to tell when this has happend with strings(1) we
|
|
3796 clear some known-to-be-garbage blocks of memory, so that leftover
|
|
3797 results of old evaluation don't look like potential problems.
|
|
3798 But first we set some notable variables to nil and do one more GC,
|
|
3799 to turn those strings into garbage.
|
|
3800 */
|
|
3801
|
|
3802 /* Yeah, this list is pretty ad-hoc... */
|
|
3803 Vprocess_environment = Qnil;
|
|
3804 Vexec_directory = Qnil;
|
|
3805 Vdata_directory = Qnil;
|
|
3806 Vdoc_directory = Qnil;
|
|
3807 Vconfigure_info_directory = Qnil;
|
|
3808 Vexec_path = Qnil;
|
|
3809 Vload_path = Qnil;
|
|
3810 /* Vdump_load_path = Qnil; */
|
|
3811 Vload_history = Qnil;
|
|
3812 Vshell_file_name = Qnil;
|
|
3813
|
|
3814 garbage_collect_1 ();
|
|
3815
|
|
3816 /* Run the disksave finalization methods of all live objects. */
|
|
3817 disksave_object_finalization_1 ();
|
|
3818
|
|
3819 /* Zero out the unused portion of purespace */
|
|
3820 if (!pure_lossage)
|
|
3821 memset ( (char *) (PUREBEG + pureptr), 0,
|
|
3822 (((char *) (PUREBEG + PURESIZE)) -
|
|
3823 ((char *) (PUREBEG + pureptr))));
|
|
3824
|
|
3825 /* Zero out the uninitialized (really, unused) part of the containers
|
|
3826 for the live strings. */
|
|
3827 {
|
|
3828 struct string_chars_block *scb;
|
|
3829 for (scb = first_string_chars_block; scb; scb = scb->next)
|
|
3830 /* from the block's fill ptr to the end */
|
|
3831 memset ((scb->string_chars + scb->pos), 0,
|
|
3832 sizeof (scb->string_chars) - scb->pos);
|
|
3833 }
|
|
3834
|
|
3835 /* There, that ought to be enough... */
|
|
3836
|
|
3837 }
|
|
3838
|
|
3839
|
|
3840 Lisp_Object
|
|
3841 restore_gc_inhibit (Lisp_Object val)
|
|
3842 {
|
|
3843 gc_currently_forbidden = XINT (val);
|
|
3844 return val;
|
|
3845 }
|
|
3846
|
|
3847 /* Maybe we want to use this when doing a "panic" gc after memory_full()? */
|
|
3848 static int gc_hooks_inhibited;
|
|
3849
|
|
3850
|
|
3851 void
|
|
3852 garbage_collect_1 (void)
|
|
3853 {
|
|
3854 char stack_top_variable;
|
|
3855 extern char *stack_bottom;
|
|
3856 int i;
|
|
3857 struct frame *f = selected_frame ();
|
|
3858 int speccount = specpdl_depth ();
|
|
3859 Lisp_Object pre_gc_cursor = Qnil;
|
|
3860 struct gcpro gcpro1;
|
|
3861
|
|
3862 int cursor_changed = 0;
|
|
3863
|
|
3864 if (gc_in_progress != 0)
|
|
3865 return;
|
|
3866
|
|
3867 if (gc_currently_forbidden || in_display)
|
|
3868 return;
|
|
3869
|
|
3870 if (preparing_for_armageddon)
|
|
3871 return;
|
|
3872
|
|
3873 GCPRO1 (pre_gc_cursor);
|
|
3874
|
|
3875 /* Very important to prevent GC during any of the following
|
|
3876 stuff that might run Lisp code; otherwise, we'll likely
|
|
3877 have infinite GC recursion. */
|
|
3878 record_unwind_protect (restore_gc_inhibit,
|
|
3879 make_int (gc_currently_forbidden));
|
|
3880 gc_currently_forbidden = 1;
|
|
3881
|
|
3882 if (!gc_hooks_inhibited)
|
|
3883 run_hook_trapping_errors ("Error in pre-gc-hook", Qpre_gc_hook);
|
|
3884
|
|
3885 /* Now show the GC cursor/message. */
|
|
3886 if (!noninteractive)
|
|
3887 {
|
|
3888 if (FRAME_WIN_P (f))
|
|
3889 {
|
|
3890 Lisp_Object frame = make_frame (f);
|
|
3891 Lisp_Object cursor = glyph_image_instance (Vgc_pointer_glyph,
|
|
3892 FRAME_SELECTED_WINDOW (f),
|
|
3893 ERROR_ME_NOT, 1);
|
|
3894 pre_gc_cursor = f->pointer;
|
|
3895 if (POINTER_IMAGE_INSTANCEP (cursor)
|
|
3896 /* don't change if we don't know how to change back. */
|
|
3897 && POINTER_IMAGE_INSTANCEP (pre_gc_cursor))
|
|
3898 {
|
|
3899 cursor_changed = 1;
|
|
3900 Fset_frame_pointer (frame, cursor);
|
|
3901 }
|
|
3902 }
|
|
3903
|
|
3904 /* Don't print messages to the stream device. */
|
|
3905 if (!cursor_changed && !FRAME_STREAM_P (f))
|
|
3906 {
|
|
3907 char *msg = (STRINGP (Vgc_message)
|
14
|
3908 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
|
0
|
3909 : 0);
|
|
3910 Lisp_Object args[2], whole_msg;
|
|
3911 args[0] = build_string (msg ? msg :
|
|
3912 GETTEXT ((CONST char *) gc_default_message));
|
|
3913 args[1] = build_string ("...");
|
|
3914 whole_msg = Fconcat (2, args);
|
|
3915 echo_area_message (f, (Bufbyte *) 0, whole_msg, 0, -1,
|
|
3916 Qgarbage_collecting);
|
|
3917 }
|
|
3918 }
|
|
3919
|
|
3920 /***** Now we actually start the garbage collection. */
|
|
3921
|
|
3922 gc_in_progress = 1;
|
|
3923
|
|
3924 gc_generation_number[0]++;
|
|
3925
|
|
3926 #if MAX_SAVE_STACK > 0
|
|
3927
|
|
3928 /* Save a copy of the contents of the stack, for debugging. */
|
|
3929 if (!purify_flag)
|
|
3930 {
|
|
3931 i = &stack_top_variable - stack_bottom;
|
|
3932 if (i < 0) i = -i;
|
|
3933 if (i < MAX_SAVE_STACK)
|
|
3934 {
|
|
3935 if (stack_copy == 0)
|
|
3936 stack_copy = (char *) malloc (stack_copy_size = i);
|
|
3937 else if (stack_copy_size < i)
|
|
3938 stack_copy = (char *) realloc (stack_copy, (stack_copy_size = i));
|
|
3939 if (stack_copy)
|
|
3940 {
|
|
3941 if ((int) (&stack_top_variable - stack_bottom) > 0)
|
|
3942 memcpy (stack_copy, stack_bottom, i);
|
|
3943 else
|
|
3944 memcpy (stack_copy, &stack_top_variable, i);
|
|
3945 }
|
|
3946 }
|
|
3947 }
|
|
3948 #endif /* MAX_SAVE_STACK > 0 */
|
|
3949
|
|
3950 /* Do some totally ad-hoc resource clearing. */
|
|
3951 /* #### generalize this? */
|
|
3952 clear_event_resource ();
|
|
3953 cleanup_specifiers ();
|
|
3954
|
|
3955 /* Mark all the special slots that serve as the roots of accessibility. */
|
|
3956 {
|
|
3957 struct gcpro *tail;
|
|
3958 struct catchtag *catch;
|
|
3959 struct backtrace *backlist;
|
|
3960 struct specbinding *bind;
|
|
3961
|
|
3962 for (i = 0; i < staticidx; i++)
|
|
3963 {
|
|
3964 #ifdef GDB_SUCKS
|
|
3965 printf ("%d\n", i);
|
|
3966 debug_print (*staticvec[i]);
|
|
3967 #endif
|
|
3968 mark_object (*(staticvec[i]));
|
|
3969 }
|
|
3970
|
|
3971 for (tail = gcprolist; tail; tail = tail->next)
|
|
3972 {
|
|
3973 for (i = 0; i < tail->nvars; i++)
|
|
3974 mark_object (tail->var[i]);
|
|
3975 }
|
|
3976
|
|
3977 for (bind = specpdl; bind != specpdl_ptr; bind++)
|
|
3978 {
|
|
3979 mark_object (bind->symbol);
|
|
3980 mark_object (bind->old_value);
|
|
3981 }
|
|
3982
|
|
3983 for (catch = catchlist; catch; catch = catch->next)
|
|
3984 {
|
|
3985 mark_object (catch->tag);
|
|
3986 mark_object (catch->val);
|
|
3987 }
|
|
3988
|
|
3989 for (backlist = backtrace_list; backlist; backlist = backlist->next)
|
|
3990 {
|
|
3991 int nargs = backlist->nargs;
|
|
3992
|
|
3993 mark_object (*backlist->function);
|
|
3994 if (nargs == UNEVALLED || nargs == MANY)
|
|
3995 mark_object (backlist->args[0]);
|
|
3996 else
|
|
3997 for (i = 0; i < nargs; i++)
|
|
3998 mark_object (backlist->args[i]);
|
|
3999 }
|
|
4000
|
|
4001 mark_redisplay (mark_object);
|
|
4002 mark_profiling_info (mark_object);
|
|
4003 }
|
|
4004
|
|
4005 /* OK, now do the after-mark stuff. This is for things that
|
|
4006 are only marked when something else is marked (e.g. weak hashtables).
|
|
4007 There may be complex dependencies between such objects -- e.g.
|
|
4008 a weak hashtable might be unmarked, but after processing a later
|
|
4009 weak hashtable, the former one might get marked. So we have to
|
|
4010 iterate until nothing more gets marked. */
|
|
4011 {
|
|
4012 int did_mark;
|
|
4013 /* Need to iterate until there's nothing more to mark, in case
|
|
4014 of chains of mark dependencies. */
|
|
4015 do
|
|
4016 {
|
|
4017 did_mark = 0;
|
|
4018 did_mark += !!finish_marking_weak_hashtables (marked_p, mark_object);
|
|
4019 did_mark += !!finish_marking_weak_lists (marked_p, mark_object);
|
|
4020 }
|
|
4021 while (did_mark);
|
|
4022 }
|
|
4023
|
|
4024 /* And prune (this needs to be called after everything else has been
|
|
4025 marked and before we do any sweeping). */
|
|
4026 /* #### this is somewhat ad-hoc and should probably be an object
|
|
4027 method */
|
|
4028 prune_weak_hashtables (marked_p);
|
|
4029 prune_weak_lists (marked_p);
|
|
4030 prune_specifiers (marked_p);
|
|
4031
|
|
4032 gc_sweep ();
|
|
4033
|
|
4034 consing_since_gc = 0;
|
|
4035 #ifndef DEBUG_XEMACS
|
|
4036 /* Allow you to set it really fucking low if you really want ... */
|
|
4037 if (gc_cons_threshold < 10000)
|
|
4038 gc_cons_threshold = 10000;
|
|
4039 #endif
|
|
4040
|
|
4041 gc_in_progress = 0;
|
|
4042
|
|
4043 /******* End of garbage collection ********/
|
|
4044
|
|
4045 run_hook_trapping_errors ("Error in post-gc-hook", Qpost_gc_hook);
|
|
4046
|
|
4047 /* Now remove the GC cursor/message */
|
|
4048 if (!noninteractive)
|
|
4049 {
|
|
4050 if (cursor_changed)
|
|
4051 Fset_frame_pointer (make_frame (f), pre_gc_cursor);
|
|
4052 else if (!FRAME_STREAM_P (f))
|
|
4053 {
|
|
4054 char *msg = (STRINGP (Vgc_message)
|
14
|
4055 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
|
0
|
4056 : 0);
|
|
4057
|
|
4058 /* Show "...done" only if the echo area would otherwise be empty. */
|
|
4059 if (NILP (clear_echo_area (selected_frame (),
|
|
4060 Qgarbage_collecting, 0)))
|
|
4061 {
|
|
4062 Lisp_Object args[2], whole_msg;
|
|
4063 args[0] = build_string (msg ? msg :
|
|
4064 GETTEXT ((CONST char *)
|
|
4065 gc_default_message));
|
|
4066 args[1] = build_string ("... done");
|
|
4067 whole_msg = Fconcat (2, args);
|
|
4068 echo_area_message (selected_frame (), (Bufbyte *) 0,
|
|
4069 whole_msg, 0, -1,
|
|
4070 Qgarbage_collecting);
|
|
4071 }
|
|
4072 }
|
|
4073 }
|
|
4074
|
|
4075 /* now stop inhibiting GC */
|
|
4076 unbind_to (speccount, Qnil);
|
|
4077
|
|
4078 if (!breathing_space)
|
|
4079 {
|
|
4080 breathing_space = (void *) malloc (4096 - MALLOC_OVERHEAD);
|
|
4081 }
|
|
4082
|
|
4083 UNGCPRO;
|
|
4084 return;
|
|
4085 }
|
|
4086
|
|
4087 #ifdef EMACS_BTL
|
|
4088 /* This isn't actually called. BTL recognizes the stack frame of the top
|
|
4089 of the garbage collector by noting that PC is between &garbage_collect_1
|
|
4090 and &BTL_after_garbage_collect_1_stub. So this fn must be right here.
|
|
4091 There's not any other way to know the address of the end of a function.
|
|
4092 */
|
|
4093 void BTL_after_garbage_collect_1_stub () { abort (); }
|
|
4094 #endif
|
|
4095
|
|
4096 /* Debugging aids. */
|
|
4097
|
|
4098 static Lisp_Object
|
|
4099 gc_plist_hack (CONST char *name, int value, Lisp_Object tail)
|
|
4100 {
|
|
4101 /* C doesn't have local functions (or closures, or GC, or readable syntax,
|
|
4102 or portable numeric datatypes, or bit-vectors, or characters, or
|
|
4103 arrays, or exceptions, or ...) */
|
|
4104 return (cons3 (intern (name), make_int (value), tail));
|
|
4105 }
|
|
4106
|
|
4107 #define HACK_O_MATIC(type, name, pl) \
|
|
4108 { \
|
|
4109 int s = 0; \
|
|
4110 struct type##_block *x = current_##type##_block; \
|
|
4111 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \
|
|
4112 (pl) = gc_plist_hack ((name), s, (pl)); \
|
|
4113 }
|
|
4114
|
|
4115 DEFUN ("garbage-collect", Fgarbage_collect, Sgarbage_collect, 0, 0, "" /*
|
|
4116 Reclaim storage for Lisp objects no longer needed.
|
|
4117 Returns info on amount of space in use:
|
|
4118 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)
|
|
4119 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
|
|
4120 PLIST)
|
|
4121 where `PLIST' is a list of alternating keyword/value pairs providing
|
|
4122 more detailed information.
|
|
4123 Garbage collection happens automatically if you cons more than
|
|
4124 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.
|
|
4125 */ )
|
|
4126 ()
|
|
4127 {
|
|
4128 Lisp_Object pl = Qnil;
|
|
4129 Lisp_Object ret[6];
|
|
4130 int i;
|
|
4131
|
|
4132 garbage_collect_1 ();
|
|
4133
|
|
4134 for (i = 0; i < last_lrecord_type_index_assigned; i++)
|
|
4135 {
|
|
4136 if (lcrecord_stats[i].bytes_in_use != 0
|
|
4137 || lcrecord_stats[i].bytes_freed != 0
|
|
4138 || lcrecord_stats[i].instances_on_free_list != 0)
|
|
4139 {
|
|
4140 char buf [255];
|
|
4141 CONST char *name = lrecord_implementations_table[i]->name;
|
|
4142 int len = strlen (name);
|
|
4143 sprintf (buf, "%s-storage", name);
|
|
4144 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
|
|
4145 /* Okay, simple pluralization check for `symbol-value-varalias' */
|
|
4146 if (name[len-1] == 's')
|
|
4147 sprintf (buf, "%ses-freed", name);
|
|
4148 else
|
|
4149 sprintf (buf, "%ss-freed", name);
|
|
4150 if (lcrecord_stats[i].instances_freed != 0)
|
|
4151 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl);
|
|
4152 if (name[len-1] == 's')
|
|
4153 sprintf (buf, "%ses-on-free-list", name);
|
|
4154 else
|
|
4155 sprintf (buf, "%ss-on-free-list", name);
|
|
4156 if (lcrecord_stats[i].instances_on_free_list != 0)
|
|
4157 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list,
|
|
4158 pl);
|
|
4159 if (name[len-1] == 's')
|
|
4160 sprintf (buf, "%ses-used", name);
|
|
4161 else
|
|
4162 sprintf (buf, "%ss-used", name);
|
|
4163 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl);
|
|
4164 }
|
|
4165 }
|
|
4166
|
|
4167 HACK_O_MATIC (extent, "extent-storage", pl);
|
|
4168 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl);
|
|
4169 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl);
|
|
4170 HACK_O_MATIC (event, "event-storage", pl);
|
|
4171 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl);
|
|
4172 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl);
|
|
4173 HACK_O_MATIC (marker, "marker-storage", pl);
|
|
4174 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
|
|
4175 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
|
|
4176 #ifdef LISP_FLOAT_TYPE
|
|
4177 HACK_O_MATIC (float, "float-storage", pl);
|
|
4178 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
|
|
4179 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
|
|
4180 #endif /* LISP_FLOAT_TYPE */
|
|
4181 HACK_O_MATIC (string, "string-header-storage", pl);
|
|
4182 pl = gc_plist_hack ("long-strings-total-length",
|
|
4183 gc_count_string_total_size
|
|
4184 - gc_count_short_string_total_size, pl);
|
|
4185 HACK_O_MATIC (string_chars, "short-string-storage", pl);
|
|
4186 pl = gc_plist_hack ("short-strings-total-length",
|
|
4187 gc_count_short_string_total_size, pl);
|
|
4188 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl);
|
|
4189 pl = gc_plist_hack ("long-strings-used",
|
|
4190 gc_count_num_string_in_use
|
|
4191 - gc_count_num_short_string_in_use, pl);
|
|
4192 pl = gc_plist_hack ("short-strings-used",
|
|
4193 gc_count_num_short_string_in_use, pl);
|
|
4194
|
|
4195 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl);
|
|
4196 pl = gc_plist_hack ("compiled-functions-free",
|
|
4197 gc_count_num_compiled_function_freelist, pl);
|
|
4198 pl = gc_plist_hack ("compiled-functions-used",
|
|
4199 gc_count_num_compiled_function_in_use, pl);
|
|
4200
|
|
4201 pl = gc_plist_hack ("vector-storage", gc_count_vector_storage, pl);
|
|
4202 pl = gc_plist_hack ("vectors-total-length",
|
|
4203 gc_count_vector_total_size, pl);
|
|
4204 pl = gc_plist_hack ("vectors-used", gc_count_num_vector_used, pl);
|
|
4205
|
|
4206 pl = gc_plist_hack ("bit-vector-storage", gc_count_bit_vector_storage, pl);
|
|
4207 pl = gc_plist_hack ("bit-vectors-total-length",
|
|
4208 gc_count_bit_vector_total_size, pl);
|
|
4209 pl = gc_plist_hack ("bit-vectors-used", gc_count_num_bit_vector_used, pl);
|
|
4210
|
|
4211 HACK_O_MATIC (symbol, "symbol-storage", pl);
|
|
4212 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl);
|
|
4213 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl);
|
|
4214
|
|
4215 HACK_O_MATIC (cons, "cons-storage", pl);
|
|
4216 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl);
|
|
4217 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl);
|
|
4218
|
|
4219 /* The things we do for backwards-compatibility */
|
|
4220 ret[0] = Fcons (make_int (gc_count_num_cons_in_use),
|
|
4221 make_int (gc_count_num_cons_freelist));
|
|
4222 ret[1] = Fcons (make_int (gc_count_num_symbol_in_use),
|
|
4223 make_int (gc_count_num_symbol_freelist));
|
|
4224 ret[2] = Fcons (make_int (gc_count_num_marker_in_use),
|
|
4225 make_int (gc_count_num_marker_freelist));
|
|
4226 ret[3] = make_int (gc_count_string_total_size);
|
|
4227 ret[4] = make_int (gc_count_vector_total_size);
|
|
4228 ret[5] = pl;
|
|
4229 return (Flist (6, ret));
|
|
4230 }
|
|
4231 #undef HACK_O_MATIC
|
|
4232
|
|
4233 DEFUN ("consing-since-gc", Fconsing_since_gc, Sconsing_since_gc, 0, 0, "" /*
|
|
4234 Return the number of bytes consed since the last garbage collection.
|
|
4235 \"Consed\" is a misnomer in that this actually counts allocation
|
|
4236 of all different kinds of objects, not just conses.
|
|
4237
|
|
4238 If this value exceeds `gc-cons-threshold', a garbage collection happens.
|
|
4239 */ )
|
|
4240 ()
|
|
4241 {
|
|
4242 return (make_int (consing_since_gc));
|
|
4243 }
|
|
4244
|
|
4245 DEFUN ("memory-limit", Fmemory_limit, Smemory_limit, 0, 0, "" /*
|
|
4246 Return the address of the last byte Emacs has allocated, divided by 1024.
|
|
4247 This may be helpful in debugging Emacs's memory usage.
|
|
4248 The value is divided by 1024 to make sure it will fit in a lisp integer.
|
|
4249 */ )
|
|
4250 ()
|
|
4251 {
|
|
4252 return (make_int ((EMACS_INT) sbrk (0) / 1024));
|
|
4253 }
|
|
4254
|
|
4255
|
|
4256
|
|
4257 int
|
|
4258 object_dead_p (Lisp_Object obj)
|
|
4259 {
|
|
4260 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) ||
|
|
4261 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) ||
|
|
4262 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) ||
|
|
4263 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) ||
|
|
4264 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) ||
|
|
4265 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) ||
|
|
4266 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj))));
|
|
4267
|
|
4268 }
|
|
4269
|
|
4270 #ifdef MEMORY_USAGE_STATS
|
|
4271
|
|
4272 /* Attempt to determine the actual amount of space that is used for
|
|
4273 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE".
|
|
4274
|
|
4275 It seems that the following holds:
|
|
4276
|
|
4277 1. When using the old allocator (malloc.c):
|
|
4278
|
|
4279 -- blocks are always allocated in chunks of powers of two. For
|
|
4280 each block, there is an overhead of 8 bytes if rcheck is not
|
|
4281 defined, 20 bytes if it is defined. In other words, a
|
|
4282 one-byte allocation needs 8 bytes of overhead for a total of
|
|
4283 9 bytes, and needs to have 16 bytes of memory chunked out for
|
|
4284 it.
|
|
4285
|
|
4286 2. When using the new allocator (gmalloc.c):
|
|
4287
|
|
4288 -- blocks are always allocated in chunks of powers of two up
|
|
4289 to 4096 bytes. Larger blocks are allocated in chunks of
|
|
4290 an integral multiple of 4096 bytes. The minimum block
|
|
4291 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
|
|
4292 is defined. There is no per-block overhead, but there
|
|
4293 is an overhead of 3*sizeof (size_t) for each 4096 bytes
|
|
4294 allocated.
|
|
4295
|
|
4296 3. When using the system malloc, anything goes, but they are
|
|
4297 generally slower and more space-efficient than the GNU
|
|
4298 allocators. One possibly reasonable assumption to make
|
|
4299 for want of better data is that sizeof (void *), or maybe
|
|
4300 2 * sizeof (void *), is required as overhead and that
|
|
4301 blocks are allocated in the minimum required size except
|
|
4302 that some minimum block size is imposed (e.g. 16 bytes). */
|
|
4303
|
|
4304 int
|
|
4305 malloced_storage_size (void *ptr, int claimed_size,
|
|
4306 struct overhead_stats *stats)
|
|
4307 {
|
|
4308 int orig_claimed_size = claimed_size;
|
|
4309
|
|
4310 #ifdef GNU_MALLOC
|
|
4311
|
|
4312 if (claimed_size < 2 * sizeof (void *))
|
|
4313 claimed_size = 2 * sizeof (void *);
|
|
4314 # ifdef SUNOS_LOCALTIME_BUG
|
|
4315 if (claimed_size < 16)
|
|
4316 claimed_size = 16;
|
|
4317 # endif
|
|
4318 if (claimed_size < 4096)
|
|
4319 {
|
|
4320 int log = 1;
|
|
4321
|
|
4322 /* compute the log base two, more or less, then use it to compute
|
|
4323 the block size needed. */
|
|
4324 claimed_size--;
|
|
4325 /* It's big, it's heavy, it's wood! */
|
|
4326 while ((claimed_size /= 2) != 0)
|
|
4327 ++log;
|
|
4328 claimed_size = 1;
|
|
4329 /* It's better than bad, it's good! */
|
|
4330 while (log > 0)
|
|
4331 {
|
|
4332 claimed_size *= 2;
|
|
4333 log--;
|
|
4334 }
|
|
4335 /* We have to come up with some average about the amount of
|
|
4336 blocks used. */
|
|
4337 if ((rand () & 4095) < claimed_size)
|
|
4338 claimed_size += 3 * sizeof (void *);
|
|
4339 }
|
|
4340 else
|
|
4341 {
|
|
4342 claimed_size += 4095;
|
|
4343 claimed_size &= ~4095;
|
|
4344 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t);
|
|
4345 }
|
|
4346
|
|
4347 #elif defined (SYSTEM_MALLOC)
|
|
4348
|
|
4349 if (claimed_size < 16)
|
|
4350 claimed_size = 16;
|
|
4351 claimed_size += 2 * sizeof (void *);
|
|
4352
|
|
4353 #else /* old GNU allocator */
|
|
4354
|
|
4355 # ifdef rcheck /* #### may not be defined here */
|
|
4356 claimed_size += 20;
|
|
4357 # else
|
|
4358 claimed_size += 8;
|
|
4359 # endif
|
|
4360 {
|
|
4361 int log = 1;
|
|
4362
|
|
4363 /* compute the log base two, more or less, then use it to compute
|
|
4364 the block size needed. */
|
|
4365 claimed_size--;
|
|
4366 /* It's big, it's heavy, it's wood! */
|
|
4367 while ((claimed_size /= 2) != 0)
|
|
4368 ++log;
|
|
4369 claimed_size = 1;
|
|
4370 /* It's better than bad, it's good! */
|
|
4371 while (log > 0)
|
|
4372 {
|
|
4373 claimed_size *= 2;
|
|
4374 log--;
|
|
4375 }
|
|
4376 }
|
|
4377
|
|
4378 #endif /* old GNU allocator */
|
|
4379
|
|
4380 if (stats)
|
|
4381 {
|
|
4382 stats->was_requested += orig_claimed_size;
|
|
4383 stats->malloc_overhead += claimed_size - orig_claimed_size;
|
|
4384 }
|
|
4385 return claimed_size;
|
|
4386 }
|
|
4387
|
|
4388 int
|
|
4389 fixed_type_block_overhead (int size)
|
|
4390 {
|
|
4391 int per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
|
|
4392 int overhead = 0;
|
|
4393 int storage_size = malloced_storage_size (0, per_block, 0);
|
|
4394 while (size >= per_block)
|
|
4395 {
|
|
4396 size -= per_block;
|
|
4397 overhead += sizeof (void *) + per_block - storage_size;
|
|
4398
|
|
4399 }
|
|
4400 if (rand () % per_block < size)
|
|
4401 overhead += sizeof (void *) + per_block - storage_size;
|
|
4402 return overhead;
|
|
4403 }
|
|
4404
|
|
4405 #endif /* MEMORY_USAGE_STATS */
|
|
4406
|
|
4407
|
|
4408 /* Initialization */
|
|
4409 void
|
|
4410 init_alloc_once_early (void)
|
|
4411 {
|
|
4412 int iii;
|
|
4413
|
|
4414 #ifdef PURESTAT
|
|
4415 for (iii = 0; iii < countof (purestats); iii++)
|
|
4416 {
|
|
4417 if (! purestats[iii]) continue;
|
|
4418 purestats[iii]->nobjects = 0;
|
|
4419 purestats[iii]->nbytes = 0;
|
|
4420 }
|
|
4421 purecopying_for_bytecode = 0;
|
|
4422 #endif
|
|
4423
|
|
4424 last_lrecord_type_index_assigned = -1;
|
|
4425 for (iii = 0; iii < countof (lrecord_implementations_table); iii++)
|
|
4426 {
|
|
4427 lrecord_implementations_table[iii] = 0;
|
|
4428 }
|
|
4429
|
|
4430 symbols_initialized = 0;
|
|
4431
|
|
4432 gc_generation_number[0] = 0;
|
|
4433 /* purify_flag 1 is correct even if CANNOT_DUMP.
|
|
4434 * loadup.el will set to nil at end. */
|
|
4435 purify_flag = 1;
|
|
4436 pureptr = 0;
|
|
4437 pure_lossage = 0;
|
|
4438 breathing_space = 0;
|
|
4439 XSETINT (all_vectors, 0); /* Qzero may not be set yet. */
|
|
4440 XSETINT (all_bit_vectors, 0); /* Qzero may not be set yet. */
|
|
4441 XSETINT (Vgc_message, 0);
|
|
4442 all_lcrecords = 0;
|
|
4443 ignore_malloc_warnings = 1;
|
|
4444 init_string_alloc ();
|
|
4445 init_string_chars_alloc ();
|
|
4446 init_cons_alloc ();
|
|
4447 init_symbol_alloc ();
|
|
4448 init_compiled_function_alloc ();
|
|
4449 #ifdef LISP_FLOAT_TYPE
|
|
4450 init_float_alloc ();
|
|
4451 #endif /* LISP_FLOAT_TYPE */
|
|
4452 #ifndef standalone
|
|
4453 init_marker_alloc ();
|
|
4454 init_extent_alloc ();
|
|
4455 init_event_alloc ();
|
|
4456 #endif
|
|
4457 ignore_malloc_warnings = 0;
|
|
4458 staticidx = 0;
|
|
4459 consing_since_gc = 0;
|
|
4460 #if 1
|
|
4461 gc_cons_threshold = 500000; /* XEmacs change */
|
|
4462 #else
|
|
4463 gc_cons_threshold = 15000; /* debugging */
|
|
4464 #endif
|
|
4465 #ifdef VIRT_ADDR_VARIES
|
|
4466 malloc_sbrk_unused = 1<<22; /* A large number */
|
|
4467 malloc_sbrk_used = 100000; /* as reasonable as any number */
|
|
4468 #endif /* VIRT_ADDR_VARIES */
|
|
4469 lrecord_uid_counter = 259;
|
|
4470 debug_string_purity = 0;
|
|
4471 gcprolist = 0;
|
|
4472
|
|
4473 gc_currently_forbidden = 0;
|
|
4474 gc_hooks_inhibited = 0;
|
|
4475
|
|
4476 #ifdef ERROR_CHECK_TYPECHECK
|
|
4477 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4478 666;
|
|
4479 ERROR_ME_NOT.
|
|
4480 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42;
|
|
4481 ERROR_ME_WARN.
|
|
4482 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4483 3333632;
|
|
4484 #endif
|
|
4485 }
|
|
4486
|
|
4487 void
|
|
4488 reinit_alloc (void)
|
|
4489 {
|
|
4490 gcprolist = 0;
|
|
4491 }
|
|
4492
|
|
4493 void
|
|
4494 syms_of_alloc (void)
|
|
4495 {
|
|
4496 defsymbol (&Qpre_gc_hook, "pre-gc-hook");
|
|
4497 defsymbol (&Qpost_gc_hook, "post-gc-hook");
|
|
4498 defsymbol (&Qgarbage_collecting, "garbage-collecting");
|
|
4499
|
|
4500 defsubr (&Scons);
|
|
4501 defsubr (&Slist);
|
|
4502 defsubr (&Svector);
|
|
4503 defsubr (&Sbit_vector);
|
|
4504 defsubr (&Smake_byte_code);
|
|
4505 defsubr (&Smake_list);
|
|
4506 defsubr (&Smake_vector);
|
|
4507 defsubr (&Smake_bit_vector);
|
|
4508 defsubr (&Smake_string);
|
|
4509 defsubr (&Smake_symbol);
|
|
4510 defsubr (&Smake_marker);
|
|
4511 defsubr (&Spurecopy);
|
|
4512 defsubr (&Sgarbage_collect);
|
|
4513 defsubr (&Smemory_limit);
|
|
4514 defsubr (&Sconsing_since_gc);
|
|
4515 }
|
|
4516
|
|
4517 void
|
|
4518 vars_of_alloc (void)
|
|
4519 {
|
|
4520 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold /*
|
|
4521 *Number of bytes of consing between garbage collections.
|
|
4522 \"Consing\" is a misnomer in that this actually counts allocation
|
|
4523 of all different kinds of objects, not just conses.
|
|
4524 Garbage collection can happen automatically once this many bytes have been
|
|
4525 allocated since the last garbage collection. All data types count.
|
|
4526
|
|
4527 Garbage collection happens automatically when `eval' or `funcall' are
|
|
4528 called. (Note that `funcall' is called implicitly as part of evaluation.)
|
|
4529 By binding this temporarily to a large number, you can effectively
|
|
4530 prevent garbage collection during a part of the program.
|
|
4531
|
|
4532 See also `consing-since-gc'.
|
|
4533 */ );
|
|
4534
|
|
4535 DEFVAR_INT ("pure-bytes-used", &pureptr /*
|
|
4536 Number of bytes of sharable Lisp data allocated so far.
|
|
4537 */ );
|
|
4538
|
|
4539 #if 0
|
|
4540 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used /*
|
|
4541 Number of bytes of unshared memory allocated in this session.
|
|
4542 */ );
|
|
4543
|
|
4544 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused /*
|
|
4545 Number of bytes of unshared memory remaining available in this session.
|
|
4546 */ );
|
|
4547 #endif
|
|
4548
|
|
4549 #ifdef DEBUG_XEMACS
|
|
4550 DEFVAR_INT ("debug-allocation", &debug_allocation /*
|
|
4551 If non-zero, print out information to stderr about all objects allocated.
|
|
4552 See also `debug-allocation-backtrace-length'.
|
|
4553 */ );
|
|
4554 debug_allocation = 0;
|
|
4555
|
|
4556 DEFVAR_INT ("debug-allocation-backtrace-length",
|
|
4557 &debug_allocation_backtrace_length /*
|
|
4558 Length (in stack frames) of short backtrace printed out by `debug-allocation'.
|
|
4559 */ );
|
|
4560 debug_allocation_backtrace_length = 2;
|
|
4561 #endif
|
|
4562
|
|
4563 DEFVAR_BOOL ("purify-flag", &purify_flag /*
|
|
4564 Non-nil means loading Lisp code in order to dump an executable.
|
|
4565 This means that certain objects should be allocated in shared (pure) space.
|
|
4566 */ );
|
|
4567
|
|
4568 DEFVAR_LISP ("pre-gc-hook", &Vpre_gc_hook /*
|
|
4569 Function or functions to be run just before each garbage collection.
|
|
4570 Interrupts, garbage collection, and errors are inhibited while this hook
|
|
4571 runs, so be extremely careful in what you add here. In particular, avoid
|
|
4572 consing, and do not interact with the user.
|
|
4573 */ );
|
|
4574 Vpre_gc_hook = Qnil;
|
|
4575
|
|
4576 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /*
|
|
4577 Function or functions to be run just after each garbage collection.
|
|
4578 Interrupts, garbage collection, and errors are inhibited while this hook
|
|
4579 runs, so be extremely careful in what you add here. In particular, avoid
|
|
4580 consing, and do not interact with the user.
|
|
4581 */ );
|
|
4582 Vpost_gc_hook = Qnil;
|
|
4583
|
|
4584 DEFVAR_LISP ("gc-message", &Vgc_message /*
|
|
4585 String to print to indicate that a garbage collection is in progress.
|
|
4586 This is printed in the echo area. If the selected frame is on a
|
|
4587 window system and `gc-pointer-glyph' specifies a value (i.e. a pointer
|
|
4588 image instance) in the domain of the selected frame, the mouse pointer
|
|
4589 will change instead of this message being printed.
|
|
4590 */ );
|
|
4591 Vgc_message = make_pure_string ((CONST Bufbyte *) gc_default_message,
|
|
4592 countof (gc_default_message) - 1,
|
|
4593 Qnil, 1);
|
|
4594
|
|
4595 DEFVAR_LISP ("gc-pointer-glyph", &Vgc_pointer_glyph /*
|
|
4596 Pointer glyph used to indicate that a garbage collection is in progress.
|
|
4597 If the selected window is on a window system and this glyph specifies a
|
|
4598 value (i.e. a pointer image instance) in the domain of the selected
|
|
4599 window, the pointer will be changed as specified during garbage collection.
|
|
4600 Otherwise, a message will be printed in the echo area, as controlled
|
|
4601 by `gc-message'.
|
|
4602 */ );
|
|
4603 }
|
|
4604
|
|
4605 void
|
|
4606 complex_vars_of_alloc (void)
|
|
4607 {
|
|
4608 Vgc_pointer_glyph = Fmake_glyph_internal (Qpointer);
|
|
4609 }
|