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