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