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