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