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;
|
|
2851 Fputhash (obj, obj, Vpure_uninterned_symbol_table);
|
|
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 */
|
0
|
3038 #define NSTATICS 1500
|
|
3039 /* Not "static" because of linker lossage on some systems */
|
|
3040 Lisp_Object *staticvec[NSTATICS]
|
|
3041 /* Force it into data space! */
|
|
3042 = {0};
|
|
3043 static int staticidx;
|
|
3044
|
|
3045 /* Put an entry in staticvec, pointing at the variable whose address is given
|
|
3046 */
|
|
3047 void
|
|
3048 staticpro (Lisp_Object *varaddress)
|
|
3049 {
|
|
3050 if (staticidx >= countof (staticvec))
|
|
3051 abort ();
|
|
3052 staticvec[staticidx++] = varaddress;
|
|
3053 }
|
|
3054
|
|
3055
|
|
3056 /* Mark reference to a Lisp_Object. If the object referred to has not been
|
|
3057 seen yet, recursively mark all the references contained in it. */
|
183
|
3058
|
0
|
3059 static void
|
|
3060 mark_object (Lisp_Object obj)
|
|
3061 {
|
|
3062 tail_recurse:
|
|
3063
|
207
|
3064 if (EQ (obj, Qnull_pointer))
|
|
3065 return;
|
0
|
3066 if (!POINTER_TYPE_P (XGCTYPE (obj)))
|
|
3067 return;
|
|
3068 if (PURIFIED (XPNTR (obj)))
|
|
3069 return;
|
|
3070 switch (XGCTYPE (obj))
|
|
3071 {
|
207
|
3072 #ifndef LRECORD_CONS
|
185
|
3073 case Lisp_Type_Cons:
|
0
|
3074 {
|
|
3075 struct Lisp_Cons *ptr = XCONS (obj);
|
|
3076 if (CONS_MARKED_P (ptr))
|
|
3077 break;
|
|
3078 MARK_CONS (ptr);
|
|
3079 /* If the cdr is nil, tail-recurse on the car. */
|
|
3080 if (NILP (ptr->cdr))
|
|
3081 {
|
|
3082 obj = ptr->car;
|
|
3083 }
|
|
3084 else
|
|
3085 {
|
|
3086 mark_object (ptr->car);
|
|
3087 obj = ptr->cdr;
|
|
3088 }
|
|
3089 goto tail_recurse;
|
|
3090 }
|
207
|
3091 #endif
|
0
|
3092
|
185
|
3093 case Lisp_Type_Record:
|
0
|
3094 /* case Lisp_Symbol_Value_Magic: */
|
|
3095 {
|
|
3096 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
3097 CONST struct lrecord_implementation *implementation
|
211
|
3098 = LHEADER_IMPLEMENTATION (lheader);
|
0
|
3099
|
|
3100 if (! MARKED_RECORD_HEADER_P (lheader) &&
|
|
3101 ! UNMARKABLE_RECORD_HEADER_P (lheader))
|
|
3102 {
|
|
3103 MARK_RECORD_HEADER (lheader);
|
|
3104 #ifdef ERROR_CHECK_GC
|
|
3105 if (!implementation->basic_p)
|
|
3106 assert (! ((struct lcrecord_header *) lheader)->free);
|
|
3107 #endif
|
|
3108 if (implementation->marker != 0)
|
|
3109 {
|
|
3110 obj = ((implementation->marker) (obj, mark_object));
|
|
3111 if (!NILP (obj)) goto tail_recurse;
|
|
3112 }
|
|
3113 }
|
|
3114 }
|
|
3115 break;
|
|
3116
|
207
|
3117 #ifndef LRECORD_STRING
|
185
|
3118 case Lisp_Type_String:
|
0
|
3119 {
|
|
3120 struct Lisp_String *ptr = XSTRING (obj);
|
|
3121
|
|
3122 if (!XMARKBIT (ptr->plist))
|
|
3123 {
|
|
3124 if (CONSP (ptr->plist) &&
|
|
3125 EXTENT_INFOP (XCAR (ptr->plist)))
|
|
3126 flush_cached_extent_info (XCAR (ptr->plist));
|
|
3127 XMARK (ptr->plist);
|
|
3128 obj = ptr->plist;
|
|
3129 goto tail_recurse;
|
|
3130 }
|
|
3131 }
|
|
3132 break;
|
207
|
3133 #endif /* ! LRECORD_STRING */
|
0
|
3134
|
185
|
3135 #ifndef LRECORD_VECTOR
|
|
3136 case Lisp_Type_Vector:
|
0
|
3137 {
|
|
3138 struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
3139 int len = vector_length (ptr);
|
|
3140 int i;
|
|
3141
|
|
3142 if (len < 0)
|
|
3143 break; /* Already marked */
|
|
3144 ptr->size = -1 - len; /* Else mark it */
|
|
3145 for (i = 0; i < len - 1; i++) /* and then mark its elements */
|
|
3146 mark_object (ptr->contents[i]);
|
|
3147 if (len > 0)
|
|
3148 {
|
|
3149 obj = ptr->contents[len - 1];
|
|
3150 goto tail_recurse;
|
|
3151 }
|
|
3152 }
|
|
3153 break;
|
185
|
3154 #endif /* !LRECORD_VECTOR */
|
0
|
3155
|
|
3156 #ifndef LRECORD_SYMBOL
|
185
|
3157 case Lisp_Type_Symbol:
|
0
|
3158 {
|
|
3159 struct Lisp_Symbol *sym = XSYMBOL (obj);
|
|
3160
|
|
3161 while (!XMARKBIT (sym->plist))
|
|
3162 {
|
|
3163 XMARK (sym->plist);
|
|
3164 mark_object (sym->value);
|
|
3165 mark_object (sym->function);
|
|
3166 {
|
207
|
3167 /*
|
|
3168 * symbol->name is a struct Lisp_String *, not a
|
|
3169 * Lisp_Object. Fix it up and pass to mark_object.
|
|
3170 */
|
|
3171 Lisp_Object symname;
|
|
3172 XSETSTRING(symname, sym->name);
|
|
3173 mark_object(symname);
|
0
|
3174 }
|
|
3175 if (!symbol_next (sym))
|
|
3176 {
|
|
3177 obj = sym->plist;
|
|
3178 goto tail_recurse;
|
|
3179 }
|
|
3180 mark_object (sym->plist);
|
|
3181 /* Mark the rest of the symbols in the hash-chain */
|
|
3182 sym = symbol_next (sym);
|
|
3183 }
|
|
3184 }
|
|
3185 break;
|
|
3186 #endif /* !LRECORD_SYMBOL */
|
|
3187
|
|
3188 default:
|
|
3189 abort ();
|
|
3190 }
|
|
3191 }
|
|
3192
|
|
3193 /* mark all of the conses in a list and mark the final cdr; but
|
|
3194 DO NOT mark the cars.
|
|
3195
|
|
3196 Use only for internal lists! There should never be other pointers
|
|
3197 to the cons cells, because if so, the cars will remain unmarked
|
|
3198 even when they maybe should be marked. */
|
|
3199 void
|
|
3200 mark_conses_in_list (Lisp_Object obj)
|
|
3201 {
|
|
3202 Lisp_Object rest;
|
|
3203
|
|
3204 for (rest = obj; CONSP (rest); rest = XCDR (rest))
|
|
3205 {
|
|
3206 if (CONS_MARKED_P (XCONS (rest)))
|
|
3207 return;
|
|
3208 MARK_CONS (XCONS (rest));
|
|
3209 }
|
|
3210
|
|
3211 mark_object (rest);
|
|
3212 }
|
|
3213
|
|
3214
|
|
3215 #ifdef PURESTAT
|
183
|
3216 /* Simpler than mark-object, because pure structure can't
|
|
3217 have any circularities */
|
0
|
3218
|
|
3219 #if 0 /* unused */
|
|
3220 static int idiot_c_doesnt_have_closures;
|
|
3221 static void
|
|
3222 idiot_c (Lisp_Object obj)
|
|
3223 {
|
|
3224 idiot_c_doesnt_have_closures += pure_sizeof (obj, 1);
|
|
3225 }
|
|
3226 #endif /* unused */
|
|
3227
|
207
|
3228 static int
|
|
3229 pure_string_sizeof(Lisp_Object obj)
|
|
3230 {
|
|
3231 struct Lisp_String *ptr = XSTRING (obj);
|
|
3232 int size = string_length (ptr);
|
|
3233
|
|
3234 if (string_data (ptr) !=
|
|
3235 (unsigned char *) ptr + sizeof (struct Lisp_String))
|
|
3236 {
|
|
3237 /* string-data not allocated contiguously.
|
|
3238 Probably (better be!!) a pointer constant "C" data. */
|
|
3239 size = sizeof (struct Lisp_String);
|
|
3240 }
|
|
3241 else
|
|
3242 {
|
|
3243 size = sizeof (struct Lisp_String) + size + 1;
|
|
3244 size = ALIGN_SIZE (size, sizeof (Lisp_Object));
|
|
3245 }
|
|
3246 return size;
|
|
3247 }
|
|
3248
|
0
|
3249 /* recurse arg isn't actually used */
|
|
3250 static int
|
|
3251 pure_sizeof (Lisp_Object obj /*, int recurse */)
|
|
3252 {
|
|
3253 int total = 0;
|
|
3254
|
|
3255 /*tail_recurse: */
|
|
3256 if (!POINTER_TYPE_P (XTYPE (obj))
|
|
3257 || !PURIFIED (XPNTR (obj)))
|
173
|
3258 return total;
|
0
|
3259
|
|
3260 /* symbol's sizes are accounted for separately */
|
|
3261 if (SYMBOLP (obj))
|
173
|
3262 return total;
|
0
|
3263
|
|
3264 switch (XTYPE (obj))
|
|
3265 {
|
207
|
3266
|
|
3267 #ifndef LRECORD_STRING
|
185
|
3268 case Lisp_Type_String:
|
0
|
3269 {
|
207
|
3270 total += pure_string_sizeof (obj);
|
0
|
3271 }
|
|
3272 break;
|
207
|
3273 #endif /* ! LRECORD_STRING */
|
0
|
3274
|
185
|
3275 #ifndef LRECORD_VECTOR
|
|
3276 case Lisp_Type_Vector:
|
0
|
3277 {
|
|
3278 struct Lisp_Vector *ptr = XVECTOR (obj);
|
|
3279 int len = vector_length (ptr);
|
|
3280
|
|
3281 total += (sizeof (struct Lisp_Vector)
|
|
3282 + (len - 1) * sizeof (Lisp_Object));
|
|
3283 #if 0 /* unused */
|
|
3284 if (!recurse)
|
|
3285 break;
|
183
|
3286 {
|
0
|
3287 int i;
|
|
3288 for (i = 0; i < len - 1; i++)
|
|
3289 total += pure_sizeof (ptr->contents[i], 1);
|
|
3290 }
|
|
3291 if (len > 0)
|
|
3292 {
|
|
3293 obj = ptr->contents[len - 1];
|
|
3294 goto tail_recurse;
|
|
3295 }
|
|
3296 #endif /* unused */
|
|
3297 }
|
|
3298 break;
|
207
|
3299 #endif /* !LRECORD_VECTOR */
|
185
|
3300
|
|
3301 case Lisp_Type_Record:
|
0
|
3302 {
|
|
3303 struct lrecord_header *lheader = XRECORD_LHEADER (obj);
|
|
3304 CONST struct lrecord_implementation *implementation
|
211
|
3305 = LHEADER_IMPLEMENTATION (lheader);
|
0
|
3306
|
207
|
3307 #ifdef LRECORD_STRING
|
|
3308 if (STRINGP (obj))
|
|
3309 total += pure_string_sizeof (obj);
|
|
3310 else
|
|
3311 #endif
|
0
|
3312 if (implementation->size_in_bytes_method)
|
|
3313 total += ((implementation->size_in_bytes_method) (lheader));
|
|
3314 else
|
|
3315 total += implementation->static_size;
|
|
3316
|
|
3317 #if 0 /* unused */
|
|
3318 if (!recurse)
|
|
3319 break;
|
|
3320
|
|
3321 if (implementation->marker != 0)
|
|
3322 {
|
|
3323 int old = idiot_c_doesnt_have_closures;
|
|
3324
|
|
3325 idiot_c_doesnt_have_closures = 0;
|
|
3326 obj = ((implementation->marker) (obj, idiot_c));
|
|
3327 total += idiot_c_doesnt_have_closures;
|
|
3328 idiot_c_doesnt_have_closures = old;
|
183
|
3329
|
0
|
3330 if (!NILP (obj)) goto tail_recurse;
|
|
3331 }
|
|
3332 #endif /* unused */
|
|
3333 }
|
|
3334 break;
|
|
3335
|
207
|
3336 #ifndef LRECORD_CONS
|
185
|
3337 case Lisp_Type_Cons:
|
0
|
3338 {
|
|
3339 struct Lisp_Cons *ptr = XCONS (obj);
|
|
3340 total += sizeof (*ptr);
|
|
3341 #if 0 /* unused */
|
|
3342 if (!recurse)
|
|
3343 break;
|
|
3344 /* If the cdr is nil, tail-recurse on the car. */
|
|
3345 if (NILP (ptr->cdr))
|
|
3346 {
|
|
3347 obj = ptr->car;
|
|
3348 }
|
|
3349 else
|
|
3350 {
|
|
3351 total += pure_sizeof (ptr->car, 1);
|
|
3352 obj = ptr->cdr;
|
|
3353 }
|
|
3354 goto tail_recurse;
|
|
3355 #endif /* unused */
|
|
3356 }
|
|
3357 break;
|
207
|
3358 #endif
|
0
|
3359
|
|
3360 /* Others can't be purified */
|
|
3361 default:
|
|
3362 abort ();
|
|
3363 }
|
173
|
3364 return total;
|
0
|
3365 }
|
|
3366 #endif /* PURESTAT */
|
|
3367
|
|
3368
|
|
3369
|
|
3370
|
|
3371 /* Find all structures not marked, and free them. */
|
|
3372
|
207
|
3373 #ifndef LRECORD_VECTOR
|
0
|
3374 static int gc_count_num_vector_used, gc_count_vector_total_size;
|
|
3375 static int gc_count_vector_storage;
|
207
|
3376 #endif
|
0
|
3377 static int gc_count_num_bit_vector_used, gc_count_bit_vector_total_size;
|
|
3378 static int gc_count_bit_vector_storage;
|
|
3379 static int gc_count_num_short_string_in_use;
|
|
3380 static int gc_count_string_total_size;
|
|
3381 static int gc_count_short_string_total_size;
|
|
3382
|
|
3383 /* static int gc_count_total_records_used, gc_count_records_total_size; */
|
|
3384
|
|
3385
|
|
3386 /* This will be used more extensively In The Future */
|
|
3387 static int last_lrecord_type_index_assigned;
|
|
3388
|
211
|
3389 CONST struct lrecord_implementation *lrecord_implementations_table[128];
|
0
|
3390 #define max_lrecord_type (countof (lrecord_implementations_table) - 1)
|
|
3391
|
211
|
3392 int
|
0
|
3393 lrecord_type_index (CONST struct lrecord_implementation *implementation)
|
|
3394 {
|
|
3395 int type_index = *(implementation->lrecord_type_index);
|
|
3396 /* Have to do this circuitous and validation test because of problems
|
|
3397 dumping out initialized variables (ie can't set xxx_type_index to -1
|
|
3398 because that would make xxx_type_index read-only in a dumped emacs. */
|
|
3399 if (type_index < 0 || type_index > max_lrecord_type
|
|
3400 || lrecord_implementations_table[type_index] != implementation)
|
|
3401 {
|
|
3402 if (last_lrecord_type_index_assigned == max_lrecord_type)
|
|
3403 abort ();
|
|
3404 type_index = ++last_lrecord_type_index_assigned;
|
|
3405 lrecord_implementations_table[type_index] = implementation;
|
|
3406 *(implementation->lrecord_type_index) = type_index;
|
|
3407 }
|
173
|
3408 return type_index;
|
0
|
3409 }
|
|
3410
|
|
3411 /* stats on lcrecords in use - kinda kludgy */
|
|
3412
|
|
3413 static struct
|
|
3414 {
|
|
3415 int instances_in_use;
|
|
3416 int bytes_in_use;
|
|
3417 int instances_freed;
|
|
3418 int bytes_freed;
|
|
3419 int instances_on_free_list;
|
|
3420 } lcrecord_stats [countof (lrecord_implementations_table)];
|
|
3421
|
|
3422
|
|
3423 static void
|
|
3424 reset_lcrecord_stats (void)
|
|
3425 {
|
|
3426 int i;
|
|
3427 for (i = 0; i < countof (lcrecord_stats); i++)
|
|
3428 {
|
|
3429 lcrecord_stats[i].instances_in_use = 0;
|
|
3430 lcrecord_stats[i].bytes_in_use = 0;
|
|
3431 lcrecord_stats[i].instances_freed = 0;
|
|
3432 lcrecord_stats[i].bytes_freed = 0;
|
|
3433 lcrecord_stats[i].instances_on_free_list = 0;
|
|
3434 }
|
|
3435 }
|
|
3436
|
|
3437 static void
|
|
3438 tick_lcrecord_stats (CONST struct lrecord_header *h, int free_p)
|
|
3439 {
|
211
|
3440 CONST struct lrecord_implementation *implementation =
|
|
3441 LHEADER_IMPLEMENTATION (h);
|
0
|
3442 int type_index = lrecord_type_index (implementation);
|
|
3443
|
|
3444 if (((struct lcrecord_header *) h)->free)
|
|
3445 {
|
|
3446 assert (!free_p);
|
|
3447 lcrecord_stats[type_index].instances_on_free_list++;
|
|
3448 }
|
|
3449 else
|
|
3450 {
|
|
3451 unsigned int sz = (implementation->size_in_bytes_method
|
|
3452 ? ((implementation->size_in_bytes_method) (h))
|
|
3453 : implementation->static_size);
|
|
3454
|
|
3455 if (free_p)
|
|
3456 {
|
|
3457 lcrecord_stats[type_index].instances_freed++;
|
|
3458 lcrecord_stats[type_index].bytes_freed += sz;
|
|
3459 }
|
|
3460 else
|
|
3461 {
|
|
3462 lcrecord_stats[type_index].instances_in_use++;
|
|
3463 lcrecord_stats[type_index].bytes_in_use += sz;
|
|
3464 }
|
|
3465 }
|
|
3466 }
|
|
3467
|
|
3468
|
|
3469 /* Free all unmarked records */
|
|
3470 static void
|
|
3471 sweep_lcrecords_1 (struct lcrecord_header **prev, int *used)
|
|
3472 {
|
|
3473 struct lcrecord_header *header;
|
|
3474 int num_used = 0;
|
|
3475 /* int total_size = 0; */
|
|
3476 reset_lcrecord_stats ();
|
|
3477
|
|
3478 /* First go through and call all the finalize methods.
|
|
3479 Then go through and free the objects. There used to
|
|
3480 be only one loop here, with the call to the finalizer
|
|
3481 occurring directly before the xfree() below. That
|
|
3482 is marginally faster but much less safe -- if the
|
|
3483 finalize method for an object needs to reference any
|
|
3484 other objects contained within it (and many do),
|
|
3485 we could easily be screwed by having already freed that
|
|
3486 other object. */
|
|
3487
|
|
3488 for (header = *prev; header; header = header->next)
|
|
3489 {
|
|
3490 struct lrecord_header *h = &(header->lheader);
|
|
3491 if (!MARKED_RECORD_HEADER_P (h) && ! (header->free))
|
|
3492 {
|
211
|
3493 if (LHEADER_IMPLEMENTATION (h)->finalizer)
|
|
3494 ((LHEADER_IMPLEMENTATION (h)->finalizer) (h, 0));
|
0
|
3495 }
|
|
3496 }
|
|
3497
|
|
3498 for (header = *prev; header; )
|
|
3499 {
|
|
3500 struct lrecord_header *h = &(header->lheader);
|
|
3501 if (MARKED_RECORD_HEADER_P (h))
|
|
3502 {
|
|
3503 UNMARK_RECORD_HEADER (h);
|
|
3504 num_used++;
|
|
3505 /* total_size += ((n->implementation->size_in_bytes) (h));*/
|
|
3506 prev = &(header->next);
|
|
3507 header = *prev;
|
|
3508 tick_lcrecord_stats (h, 0);
|
|
3509 }
|
|
3510 else
|
|
3511 {
|
|
3512 struct lcrecord_header *next = header->next;
|
|
3513 *prev = next;
|
|
3514 tick_lcrecord_stats (h, 1);
|
|
3515 /* used to call finalizer right here. */
|
|
3516 xfree (header);
|
|
3517 header = next;
|
|
3518 }
|
|
3519 }
|
|
3520 *used = num_used;
|
|
3521 /* *total = total_size; */
|
|
3522 }
|
|
3523
|
207
|
3524 #ifndef LRECORD_VECTOR
|
|
3525
|
0
|
3526 static void
|
183
|
3527 sweep_vectors_1 (Lisp_Object *prev,
|
0
|
3528 int *used, int *total, int *storage)
|
|
3529 {
|
|
3530 Lisp_Object vector;
|
|
3531 int num_used = 0;
|
|
3532 int total_size = 0;
|
|
3533 int total_storage = 0;
|
|
3534
|
|
3535 for (vector = *prev; VECTORP (vector); )
|
|
3536 {
|
|
3537 struct Lisp_Vector *v = XVECTOR (vector);
|
|
3538 int len = v->size;
|
|
3539 if (len < 0) /* marked */
|
|
3540 {
|
|
3541 len = - (len + 1);
|
|
3542 v->size = len;
|
|
3543 total_size += len;
|
|
3544 total_storage += (MALLOC_OVERHEAD
|
|
3545 + sizeof (struct Lisp_Vector)
|
|
3546 + (len - 1 + 1) * sizeof (Lisp_Object));
|
|
3547 num_used++;
|
|
3548 prev = &(vector_next (v));
|
|
3549 vector = *prev;
|
|
3550 }
|
|
3551 else
|
|
3552 {
|
|
3553 Lisp_Object next = vector_next (v);
|
|
3554 *prev = next;
|
|
3555 xfree (v);
|
|
3556 vector = next;
|
|
3557 }
|
|
3558 }
|
|
3559 *used = num_used;
|
|
3560 *total = total_size;
|
|
3561 *storage = total_storage;
|
|
3562 }
|
|
3563
|
207
|
3564 #endif /* ! LRECORD_VECTOR */
|
|
3565
|
0
|
3566 static void
|
183
|
3567 sweep_bit_vectors_1 (Lisp_Object *prev,
|
0
|
3568 int *used, int *total, int *storage)
|
|
3569 {
|
|
3570 Lisp_Object bit_vector;
|
|
3571 int num_used = 0;
|
|
3572 int total_size = 0;
|
|
3573 int total_storage = 0;
|
|
3574
|
|
3575 /* BIT_VECTORP fails because the objects are marked, which changes
|
|
3576 their implementation */
|
|
3577 for (bit_vector = *prev; !EQ (bit_vector, Qzero); )
|
|
3578 {
|
|
3579 struct Lisp_Bit_Vector *v = XBIT_VECTOR (bit_vector);
|
|
3580 int len = v->size;
|
|
3581 if (MARKED_RECORD_P (bit_vector))
|
|
3582 {
|
|
3583 UNMARK_RECORD_HEADER (&(v->lheader));
|
|
3584 total_size += len;
|
|
3585 total_storage += (MALLOC_OVERHEAD
|
|
3586 + sizeof (struct Lisp_Bit_Vector)
|
|
3587 + (BIT_VECTOR_LONG_STORAGE (len) - 1)
|
|
3588 * sizeof (long));
|
|
3589 num_used++;
|
|
3590 prev = &(bit_vector_next (v));
|
|
3591 bit_vector = *prev;
|
|
3592 }
|
|
3593 else
|
|
3594 {
|
|
3595 Lisp_Object next = bit_vector_next (v);
|
|
3596 *prev = next;
|
|
3597 xfree (v);
|
|
3598 bit_vector = next;
|
|
3599 }
|
|
3600 }
|
|
3601 *used = num_used;
|
|
3602 *total = total_size;
|
|
3603 *storage = total_storage;
|
|
3604 }
|
|
3605
|
|
3606 /* And the Lord said: Thou shalt use the `c-backslash-region' command
|
|
3607 to make macros prettier. */
|
|
3608
|
|
3609 #ifdef ERROR_CHECK_GC
|
|
3610
|
|
3611 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
|
|
3612 do { \
|
|
3613 struct typename##_block *_frob_current; \
|
|
3614 struct typename##_block **_frob_prev; \
|
|
3615 int _frob_limit; \
|
|
3616 int num_free = 0, num_used = 0; \
|
|
3617 \
|
|
3618 for (_frob_prev = ¤t_##typename##_block, \
|
|
3619 _frob_current = current_##typename##_block, \
|
|
3620 _frob_limit = current_##typename##_block_index; \
|
|
3621 _frob_current; \
|
|
3622 ) \
|
|
3623 { \
|
|
3624 int _frob_iii; \
|
|
3625 \
|
|
3626 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
|
|
3627 { \
|
|
3628 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
|
|
3629 \
|
|
3630 if (FREE_STRUCT_P (_frob_victim)) \
|
|
3631 { \
|
|
3632 num_free++; \
|
|
3633 } \
|
|
3634 else if (!MARKED_##typename##_P (_frob_victim)) \
|
|
3635 { \
|
|
3636 num_free++; \
|
|
3637 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
|
|
3638 } \
|
|
3639 else \
|
|
3640 { \
|
|
3641 num_used++; \
|
|
3642 UNMARK_##typename (_frob_victim); \
|
|
3643 } \
|
|
3644 } \
|
|
3645 _frob_prev = &(_frob_current->prev); \
|
|
3646 _frob_current = _frob_current->prev; \
|
|
3647 _frob_limit = countof (current_##typename##_block->block); \
|
|
3648 } \
|
|
3649 \
|
|
3650 gc_count_num_##typename##_in_use = num_used; \
|
|
3651 gc_count_num_##typename##_freelist = num_free; \
|
|
3652 } while (0)
|
|
3653
|
183
|
3654 #else /* !ERROR_CHECK_GC */
|
0
|
3655
|
|
3656 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
|
|
3657 do { \
|
|
3658 struct typename##_block *_frob_current; \
|
|
3659 struct typename##_block **_frob_prev; \
|
|
3660 int _frob_limit; \
|
|
3661 int num_free = 0, num_used = 0; \
|
|
3662 \
|
|
3663 typename##_free_list = 0; \
|
|
3664 \
|
|
3665 for (_frob_prev = ¤t_##typename##_block, \
|
|
3666 _frob_current = current_##typename##_block, \
|
|
3667 _frob_limit = current_##typename##_block_index; \
|
|
3668 _frob_current; \
|
|
3669 ) \
|
|
3670 { \
|
|
3671 int _frob_iii; \
|
|
3672 int _frob_empty = 1; \
|
|
3673 obj_type *_frob_old_free_list = typename##_free_list; \
|
|
3674 \
|
|
3675 for (_frob_iii = 0; _frob_iii < _frob_limit; _frob_iii++) \
|
|
3676 { \
|
|
3677 obj_type *_frob_victim = &(_frob_current->block[_frob_iii]); \
|
|
3678 \
|
|
3679 if (FREE_STRUCT_P (_frob_victim)) \
|
|
3680 { \
|
|
3681 num_free++; \
|
|
3682 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, _frob_victim); \
|
|
3683 } \
|
|
3684 else if (!MARKED_##typename##_P (_frob_victim)) \
|
|
3685 { \
|
|
3686 num_free++; \
|
|
3687 FREE_FIXED_TYPE (typename, obj_type, _frob_victim); \
|
|
3688 } \
|
|
3689 else \
|
|
3690 { \
|
|
3691 _frob_empty = 0; \
|
|
3692 num_used++; \
|
|
3693 UNMARK_##typename (_frob_victim); \
|
|
3694 } \
|
|
3695 } \
|
|
3696 if (!_frob_empty) \
|
|
3697 { \
|
|
3698 _frob_prev = &(_frob_current->prev); \
|
|
3699 _frob_current = _frob_current->prev; \
|
|
3700 } \
|
|
3701 else if (_frob_current == current_##typename##_block \
|
|
3702 && !_frob_current->prev) \
|
|
3703 { \
|
|
3704 /* No real point in freeing sole allocation block */ \
|
|
3705 break; \
|
|
3706 } \
|
|
3707 else \
|
|
3708 { \
|
|
3709 struct typename##_block *_frob_victim_block = _frob_current; \
|
|
3710 if (_frob_victim_block == current_##typename##_block) \
|
|
3711 current_##typename##_block_index \
|
|
3712 = countof (current_##typename##_block->block); \
|
|
3713 _frob_current = _frob_current->prev; \
|
|
3714 { \
|
|
3715 *_frob_prev = _frob_current; \
|
|
3716 xfree (_frob_victim_block); \
|
|
3717 /* Restore free list to what it was before victim was swept */ \
|
|
3718 typename##_free_list = _frob_old_free_list; \
|
|
3719 num_free -= _frob_limit; \
|
|
3720 } \
|
|
3721 } \
|
|
3722 _frob_limit = countof (current_##typename##_block->block); \
|
|
3723 } \
|
|
3724 \
|
|
3725 gc_count_num_##typename##_in_use = num_used; \
|
|
3726 gc_count_num_##typename##_freelist = num_free; \
|
|
3727 } while (0)
|
|
3728
|
183
|
3729 #endif /* !ERROR_CHECK_GC */
|
0
|
3730
|
|
3731
|
|
3732
|
|
3733
|
|
3734 static void
|
|
3735 sweep_conses (void)
|
|
3736 {
|
207
|
3737 #ifndef LRECORD_CONS
|
|
3738 # define MARKED_cons_P(ptr) XMARKBIT ((ptr)->car)
|
|
3739 # define UNMARK_cons(ptr) do { XUNMARK ((ptr)->car); } while (0)
|
|
3740 #else /* LRECORD_CONS */
|
|
3741 # define MARKED_cons_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3742 # define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3743 #endif /* LRECORD_CONS */
|
0
|
3744 #define ADDITIONAL_FREE_cons(ptr)
|
|
3745
|
|
3746 SWEEP_FIXED_TYPE_BLOCK (cons, struct Lisp_Cons);
|
|
3747 }
|
|
3748
|
|
3749 /* Explicitly free a cons cell. */
|
|
3750 void
|
|
3751 free_cons (struct Lisp_Cons *ptr)
|
|
3752 {
|
|
3753 #ifdef ERROR_CHECK_GC
|
|
3754 /* If the CAR is not an int, then it will be a pointer, which will
|
|
3755 always be four-byte aligned. If this cons cell has already been
|
|
3756 placed on the free list, however, its car will probably contain
|
|
3757 a chain pointer to the next cons on the list, which has cleverly
|
|
3758 had all its 0's and 1's inverted. This allows for a quick
|
|
3759 check to make sure we're not freeing something already freed. */
|
|
3760 if (POINTER_TYPE_P (XTYPE (ptr->car)))
|
|
3761 ASSERT_VALID_POINTER (XPNTR (ptr->car));
|
183
|
3762 #endif /* ERROR_CHECK_GC */
|
|
3763
|
0
|
3764 #ifndef ALLOC_NO_POOLS
|
|
3765 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, struct Lisp_Cons, ptr);
|
|
3766 #endif /* ALLOC_NO_POOLS */
|
|
3767 }
|
|
3768
|
|
3769 /* explicitly free a list. You **must make sure** that you have
|
|
3770 created all the cons cells that make up this list and that there
|
|
3771 are no pointers to any of these cons cells anywhere else. If there
|
|
3772 are, you will lose. */
|
|
3773
|
|
3774 void
|
|
3775 free_list (Lisp_Object list)
|
|
3776 {
|
|
3777 Lisp_Object rest, next;
|
|
3778
|
|
3779 for (rest = list; !NILP (rest); rest = next)
|
|
3780 {
|
|
3781 next = XCDR (rest);
|
|
3782 free_cons (XCONS (rest));
|
|
3783 }
|
|
3784 }
|
|
3785
|
|
3786 /* explicitly free an alist. You **must make sure** that you have
|
|
3787 created all the cons cells that make up this alist and that there
|
|
3788 are no pointers to any of these cons cells anywhere else. If there
|
|
3789 are, you will lose. */
|
|
3790
|
|
3791 void
|
|
3792 free_alist (Lisp_Object alist)
|
|
3793 {
|
|
3794 Lisp_Object rest, next;
|
|
3795
|
|
3796 for (rest = alist; !NILP (rest); rest = next)
|
|
3797 {
|
|
3798 next = XCDR (rest);
|
|
3799 free_cons (XCONS (XCAR (rest)));
|
|
3800 free_cons (XCONS (rest));
|
|
3801 }
|
|
3802 }
|
|
3803
|
|
3804 static void
|
|
3805 sweep_compiled_functions (void)
|
|
3806 {
|
|
3807 #define MARKED_compiled_function_P(ptr) \
|
|
3808 MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3809 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3810 #define ADDITIONAL_FREE_compiled_function(ptr)
|
|
3811
|
|
3812 SWEEP_FIXED_TYPE_BLOCK (compiled_function, struct Lisp_Compiled_Function);
|
|
3813 }
|
|
3814
|
|
3815
|
|
3816 #ifdef LISP_FLOAT_TYPE
|
|
3817 static void
|
|
3818 sweep_floats (void)
|
|
3819 {
|
|
3820 #define MARKED_float_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3821 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3822 #define ADDITIONAL_FREE_float(ptr)
|
|
3823
|
|
3824 SWEEP_FIXED_TYPE_BLOCK (float, struct Lisp_Float);
|
|
3825 }
|
|
3826 #endif /* LISP_FLOAT_TYPE */
|
|
3827
|
|
3828 static void
|
|
3829 sweep_symbols (void)
|
|
3830 {
|
|
3831 #ifndef LRECORD_SYMBOL
|
|
3832 # define MARKED_symbol_P(ptr) XMARKBIT ((ptr)->plist)
|
|
3833 # define UNMARK_symbol(ptr) do { XUNMARK ((ptr)->plist); } while (0)
|
|
3834 #else
|
|
3835 # define MARKED_symbol_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3836 # define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3837 #endif /* !LRECORD_SYMBOL */
|
|
3838 #define ADDITIONAL_FREE_symbol(ptr)
|
|
3839
|
|
3840 SWEEP_FIXED_TYPE_BLOCK (symbol, struct Lisp_Symbol);
|
|
3841 }
|
|
3842
|
|
3843
|
|
3844 #ifndef standalone
|
|
3845
|
|
3846 static void
|
|
3847 sweep_extents (void)
|
|
3848 {
|
|
3849 #define MARKED_extent_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3850 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3851 #define ADDITIONAL_FREE_extent(ptr)
|
|
3852
|
|
3853 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent);
|
|
3854 }
|
|
3855
|
|
3856 static void
|
|
3857 sweep_events (void)
|
|
3858 {
|
|
3859 #define MARKED_event_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3860 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3861 #define ADDITIONAL_FREE_event(ptr)
|
|
3862
|
|
3863 SWEEP_FIXED_TYPE_BLOCK (event, struct Lisp_Event);
|
|
3864 }
|
|
3865
|
|
3866 static void
|
|
3867 sweep_markers (void)
|
|
3868 {
|
|
3869 #define MARKED_marker_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
3870 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3871 #define ADDITIONAL_FREE_marker(ptr) \
|
|
3872 do { Lisp_Object tem; \
|
|
3873 XSETMARKER (tem, ptr); \
|
|
3874 unchain_marker (tem); \
|
|
3875 } while (0)
|
|
3876
|
|
3877 SWEEP_FIXED_TYPE_BLOCK (marker, struct Lisp_Marker);
|
|
3878 }
|
|
3879
|
|
3880 /* Explicitly free a marker. */
|
|
3881 void
|
|
3882 free_marker (struct Lisp_Marker *ptr)
|
|
3883 {
|
|
3884 #ifdef ERROR_CHECK_GC
|
|
3885 /* Perhaps this will catch freeing an already-freed marker. */
|
|
3886 Lisp_Object temmy;
|
|
3887 XSETMARKER (temmy, ptr);
|
|
3888 assert (GC_MARKERP (temmy));
|
183
|
3889 #endif /* ERROR_CHECK_GC */
|
|
3890
|
0
|
3891 #ifndef ALLOC_NO_POOLS
|
|
3892 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, struct Lisp_Marker, ptr);
|
|
3893 #endif /* ALLOC_NO_POOLS */
|
|
3894 }
|
|
3895
|
|
3896 #endif /* not standalone */
|
|
3897
|
|
3898
|
70
|
3899
|
|
3900 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY)
|
|
3901
|
|
3902 static void
|
|
3903 verify_string_chars_integrity (void)
|
|
3904 {
|
|
3905 struct string_chars_block *sb;
|
|
3906
|
|
3907 /* Scan each existing string block sequentially, string by string. */
|
|
3908 for (sb = first_string_chars_block; sb; sb = sb->next)
|
|
3909 {
|
|
3910 int pos = 0;
|
|
3911 /* POS is the index of the next string in the block. */
|
|
3912 while (pos < sb->pos)
|
|
3913 {
|
183
|
3914 struct string_chars *s_chars =
|
70
|
3915 (struct string_chars *) &(sb->string_chars[pos]);
|
|
3916 struct Lisp_String *string;
|
|
3917 int size;
|
|
3918 int fullsize;
|
|
3919
|
|
3920 /* If the string_chars struct is marked as free (i.e. the STRING
|
|
3921 pointer is 0xFFFFFFFF) then this is an unused chunk of string
|
|
3922 storage. (See below.) */
|
|
3923
|
|
3924 if (FREE_STRUCT_P (s_chars))
|
|
3925 {
|
|
3926 fullsize = ((struct unused_string_chars *) s_chars)->fullsize;
|
|
3927 pos += fullsize;
|
|
3928 continue;
|
|
3929 }
|
|
3930
|
|
3931 string = s_chars->string;
|
|
3932 /* Must be 32-bit aligned. */
|
|
3933 assert ((((int) string) & 3) == 0);
|
|
3934
|
|
3935 size = string_length (string);
|
|
3936 fullsize = STRING_FULLSIZE (size);
|
|
3937
|
|
3938 assert (!BIG_STRING_FULLSIZE_P (fullsize));
|
|
3939 assert (string_data (string) == s_chars->chars);
|
|
3940 pos += fullsize;
|
|
3941 }
|
|
3942 assert (pos == sb->pos);
|
|
3943 }
|
|
3944 }
|
|
3945
|
|
3946 #endif /* MULE && ERROR_CHECK_GC */
|
|
3947
|
0
|
3948 /* Compactify string chars, relocating the reference to each --
|
|
3949 free any empty string_chars_block we see. */
|
|
3950 static void
|
|
3951 compact_string_chars (void)
|
|
3952 {
|
|
3953 struct string_chars_block *to_sb = first_string_chars_block;
|
|
3954 int to_pos = 0;
|
|
3955 struct string_chars_block *from_sb;
|
|
3956
|
|
3957 /* Scan each existing string block sequentially, string by string. */
|
|
3958 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next)
|
|
3959 {
|
|
3960 int from_pos = 0;
|
|
3961 /* FROM_POS is the index of the next string in the block. */
|
|
3962 while (from_pos < from_sb->pos)
|
|
3963 {
|
183
|
3964 struct string_chars *from_s_chars =
|
0
|
3965 (struct string_chars *) &(from_sb->string_chars[from_pos]);
|
|
3966 struct string_chars *to_s_chars;
|
|
3967 struct Lisp_String *string;
|
|
3968 int size;
|
|
3969 int fullsize;
|
|
3970
|
|
3971 /* If the string_chars struct is marked as free (i.e. the STRING
|
|
3972 pointer is 0xFFFFFFFF) then this is an unused chunk of string
|
|
3973 storage. This happens under Mule when a string's size changes
|
|
3974 in such a way that its fullsize changes. (Strings can change
|
|
3975 size because a different-length character can be substituted
|
|
3976 for another character.) In this case, after the bogus string
|
|
3977 pointer is the "fullsize" of this entry, i.e. how many bytes
|
|
3978 to skip. */
|
|
3979
|
|
3980 if (FREE_STRUCT_P (from_s_chars))
|
|
3981 {
|
|
3982 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize;
|
|
3983 from_pos += fullsize;
|
|
3984 continue;
|
|
3985 }
|
|
3986
|
|
3987 string = from_s_chars->string;
|
|
3988 assert (!(FREE_STRUCT_P (string)));
|
|
3989
|
|
3990 size = string_length (string);
|
|
3991 fullsize = STRING_FULLSIZE (size);
|
|
3992
|
|
3993 if (BIG_STRING_FULLSIZE_P (fullsize))
|
|
3994 abort ();
|
|
3995
|
|
3996 /* Just skip it if it isn't marked. */
|
207
|
3997 #ifdef LRECORD_STRING
|
|
3998 if (! MARKED_RECORD_HEADER_P (&(string->lheader)))
|
|
3999 #else
|
0
|
4000 if (!XMARKBIT (string->plist))
|
207
|
4001 #endif
|
0
|
4002 {
|
|
4003 from_pos += fullsize;
|
|
4004 continue;
|
|
4005 }
|
|
4006
|
|
4007 /* If it won't fit in what's left of TO_SB, close TO_SB out
|
|
4008 and go on to the next string_chars_block. We know that TO_SB
|
|
4009 cannot advance past FROM_SB here since FROM_SB is large enough
|
|
4010 to currently contain this string. */
|
|
4011 if ((to_pos + fullsize) > countof (to_sb->string_chars))
|
|
4012 {
|
|
4013 to_sb->pos = to_pos;
|
|
4014 to_sb = to_sb->next;
|
|
4015 to_pos = 0;
|
|
4016 }
|
183
|
4017
|
0
|
4018 /* Compute new address of this string
|
|
4019 and update TO_POS for the space being used. */
|
|
4020 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]);
|
|
4021
|
|
4022 /* Copy the string_chars to the new place. */
|
|
4023 if (from_s_chars != to_s_chars)
|
|
4024 memmove (to_s_chars, from_s_chars, fullsize);
|
|
4025
|
|
4026 /* Relocate FROM_S_CHARS's reference */
|
|
4027 set_string_data (string, &(to_s_chars->chars[0]));
|
183
|
4028
|
0
|
4029 from_pos += fullsize;
|
|
4030 to_pos += fullsize;
|
|
4031 }
|
|
4032 }
|
|
4033
|
183
|
4034 /* Set current to the last string chars block still used and
|
0
|
4035 free any that follow. */
|
|
4036 {
|
|
4037 struct string_chars_block *victim;
|
|
4038
|
|
4039 for (victim = to_sb->next; victim; )
|
|
4040 {
|
|
4041 struct string_chars_block *next = victim->next;
|
|
4042 xfree (victim);
|
|
4043 victim = next;
|
|
4044 }
|
|
4045
|
|
4046 current_string_chars_block = to_sb;
|
|
4047 current_string_chars_block->pos = to_pos;
|
|
4048 current_string_chars_block->next = 0;
|
|
4049 }
|
|
4050 }
|
|
4051
|
|
4052 #if 1 /* Hack to debug missing purecopy's */
|
|
4053 static int debug_string_purity;
|
|
4054
|
|
4055 static void
|
|
4056 debug_string_purity_print (struct Lisp_String *p)
|
|
4057 {
|
|
4058 Charcount i;
|
|
4059 Charcount s = string_char_length (p);
|
|
4060 putc ('\"', stderr);
|
|
4061 for (i = 0; i < s; i++)
|
|
4062 {
|
|
4063 Emchar ch = string_char (p, i);
|
|
4064 if (ch < 32 || ch >= 126)
|
|
4065 stderr_out ("\\%03o", ch);
|
|
4066 else if (ch == '\\' || ch == '\"')
|
|
4067 stderr_out ("\\%c", ch);
|
|
4068 else
|
|
4069 stderr_out ("%c", ch);
|
|
4070 }
|
|
4071 stderr_out ("\"\n");
|
|
4072 }
|
183
|
4073 #endif /* 1 */
|
0
|
4074
|
|
4075
|
|
4076 static void
|
|
4077 sweep_strings (void)
|
|
4078 {
|
|
4079 int num_small_used = 0, num_small_bytes = 0, num_bytes = 0;
|
|
4080 int debug = debug_string_purity;
|
|
4081
|
207
|
4082 #ifdef LRECORD_STRING
|
|
4083
|
|
4084 # define MARKED_string_P(ptr) MARKED_RECORD_HEADER_P (&((ptr)->lheader))
|
|
4085 # define UNMARK_string(ptr) \
|
|
4086 do { struct Lisp_String *p = (ptr); \
|
|
4087 int size = string_length (p); \
|
|
4088 UNMARK_RECORD_HEADER (&(p->lheader)); \
|
|
4089 num_bytes += size; \
|
|
4090 if (!BIG_STRING_SIZE_P (size)) \
|
|
4091 { num_small_bytes += size; \
|
|
4092 num_small_used++; \
|
|
4093 } \
|
|
4094 if (debug) debug_string_purity_print (p); \
|
|
4095 } while (0)
|
|
4096 # define ADDITIONAL_FREE_string(p) \
|
|
4097 do { int size = string_length (p); \
|
|
4098 if (BIG_STRING_SIZE_P (size)) \
|
|
4099 xfree_1 (CHARS_TO_STRING_CHAR (string_data (p))); \
|
|
4100 } while (0)
|
|
4101
|
|
4102 #else
|
|
4103
|
|
4104 # define MARKED_string_P(ptr) XMARKBIT ((ptr)->plist)
|
|
4105 # define UNMARK_string(ptr) \
|
0
|
4106 do { struct Lisp_String *p = (ptr); \
|
|
4107 int size = string_length (p); \
|
|
4108 XUNMARK (p->plist); \
|
|
4109 num_bytes += size; \
|
|
4110 if (!BIG_STRING_SIZE_P (size)) \
|
|
4111 { num_small_bytes += size; \
|
|
4112 num_small_used++; \
|
|
4113 } \
|
|
4114 if (debug) debug_string_purity_print (p); \
|
|
4115 } while (0)
|
207
|
4116 # define ADDITIONAL_FREE_string(p) \
|
0
|
4117 do { int size = string_length (p); \
|
|
4118 if (BIG_STRING_SIZE_P (size)) \
|
|
4119 xfree_1 (CHARS_TO_STRING_CHAR (string_data (p))); \
|
|
4120 } while (0)
|
|
4121
|
207
|
4122 #endif /* ! LRECORD_STRING */
|
|
4123
|
0
|
4124 SWEEP_FIXED_TYPE_BLOCK (string, struct Lisp_String);
|
|
4125
|
|
4126 gc_count_num_short_string_in_use = num_small_used;
|
|
4127 gc_count_string_total_size = num_bytes;
|
|
4128 gc_count_short_string_total_size = num_small_bytes;
|
|
4129 }
|
|
4130
|
|
4131
|
|
4132 /* I hate duplicating all this crap! */
|
|
4133 static int
|
|
4134 marked_p (Lisp_Object obj)
|
|
4135 {
|
207
|
4136 if (EQ (obj, Qnull_pointer)) return 1;
|
0
|
4137 if (!POINTER_TYPE_P (XGCTYPE (obj))) return 1;
|
|
4138 if (PURIFIED (XPNTR (obj))) return 1;
|
|
4139 switch (XGCTYPE (obj))
|
|
4140 {
|
207
|
4141 #ifndef LRECORD_CONS
|
185
|
4142 case Lisp_Type_Cons:
|
0
|
4143 return XMARKBIT (XCAR (obj));
|
207
|
4144 #endif
|
185
|
4145 case Lisp_Type_Record:
|
0
|
4146 return MARKED_RECORD_HEADER_P (XRECORD_LHEADER (obj));
|
207
|
4147 #ifndef LRECORD_STRING
|
185
|
4148 case Lisp_Type_String:
|
0
|
4149 return XMARKBIT (XSTRING (obj)->plist);
|
207
|
4150 #endif /* ! LRECORD_STRING */
|
185
|
4151 #ifndef LRECORD_VECTOR
|
|
4152 case Lisp_Type_Vector:
|
173
|
4153 return XVECTOR_LENGTH (obj) < 0;
|
185
|
4154 #endif /* !LRECORD_VECTOR */
|
0
|
4155 #ifndef LRECORD_SYMBOL
|
185
|
4156 case Lisp_Type_Symbol:
|
0
|
4157 return XMARKBIT (XSYMBOL (obj)->plist);
|
|
4158 #endif
|
|
4159 default:
|
|
4160 abort ();
|
|
4161 }
|
|
4162 return 0; /* suppress compiler warning */
|
|
4163 }
|
|
4164
|
|
4165 static void
|
|
4166 gc_sweep (void)
|
|
4167 {
|
|
4168 /* Free all unmarked records. Do this at the very beginning,
|
|
4169 before anything else, so that the finalize methods can safely
|
|
4170 examine items in the objects. sweep_lcrecords_1() makes
|
|
4171 sure to call all the finalize methods *before* freeing anything,
|
|
4172 to complete the safety. */
|
|
4173 {
|
|
4174 int ignored;
|
|
4175 sweep_lcrecords_1 (&all_lcrecords, &ignored);
|
|
4176 }
|
|
4177
|
|
4178 compact_string_chars ();
|
|
4179
|
|
4180 /* Finalize methods below (called through the ADDITIONAL_FREE_foo
|
|
4181 macros) must be *extremely* careful to make sure they're not
|
|
4182 referencing freed objects. The only two existing finalize
|
|
4183 methods (for strings and markers) pass muster -- the string
|
|
4184 finalizer doesn't look at anything but its own specially-
|
|
4185 created block, and the marker finalizer only looks at live
|
|
4186 buffers (which will never be freed) and at the markers before
|
|
4187 and after it in the chain (which, by induction, will never be
|
|
4188 freed because if so, they would have already removed themselves
|
|
4189 from the chain). */
|
|
4190
|
|
4191 /* Put all unmarked strings on free list, free'ing the string chars
|
|
4192 of large unmarked strings */
|
|
4193 sweep_strings ();
|
|
4194
|
|
4195 /* Put all unmarked conses on free list */
|
|
4196 sweep_conses ();
|
|
4197
|
207
|
4198 #ifndef LRECORD_VECTOR
|
0
|
4199 /* Free all unmarked vectors */
|
|
4200 sweep_vectors_1 (&all_vectors,
|
|
4201 &gc_count_num_vector_used, &gc_count_vector_total_size,
|
|
4202 &gc_count_vector_storage);
|
207
|
4203 #endif
|
0
|
4204
|
|
4205 /* Free all unmarked bit vectors */
|
|
4206 sweep_bit_vectors_1 (&all_bit_vectors,
|
|
4207 &gc_count_num_bit_vector_used,
|
|
4208 &gc_count_bit_vector_total_size,
|
|
4209 &gc_count_bit_vector_storage);
|
|
4210
|
|
4211 /* Free all unmarked compiled-function objects */
|
|
4212 sweep_compiled_functions ();
|
|
4213
|
|
4214 #ifdef LISP_FLOAT_TYPE
|
|
4215 /* Put all unmarked floats on free list */
|
|
4216 sweep_floats ();
|
|
4217 #endif
|
|
4218
|
|
4219 /* Put all unmarked symbols on free list */
|
|
4220 sweep_symbols ();
|
|
4221
|
|
4222 /* Put all unmarked extents on free list */
|
|
4223 sweep_extents ();
|
|
4224
|
|
4225 /* Put all unmarked markers on free list.
|
|
4226 Dechain each one first from the buffer into which it points. */
|
|
4227 sweep_markers ();
|
|
4228
|
|
4229 sweep_events ();
|
|
4230
|
|
4231 }
|
|
4232
|
|
4233 /* Clearing for disksave. */
|
|
4234
|
|
4235 extern Lisp_Object Vprocess_environment;
|
|
4236 extern Lisp_Object Vdoc_directory;
|
|
4237 extern Lisp_Object Vconfigure_info_directory;
|
|
4238 extern Lisp_Object Vload_path;
|
|
4239 extern Lisp_Object Vload_history;
|
|
4240 extern Lisp_Object Vshell_file_name;
|
|
4241
|
|
4242 void
|
|
4243 disksave_object_finalization (void)
|
|
4244 {
|
|
4245 /* It's important that certain information from the environment not get
|
|
4246 dumped with the executable (pathnames, environment variables, etc.).
|
|
4247 To make it easier to tell when this has happend with strings(1) we
|
|
4248 clear some known-to-be-garbage blocks of memory, so that leftover
|
|
4249 results of old evaluation don't look like potential problems.
|
|
4250 But first we set some notable variables to nil and do one more GC,
|
|
4251 to turn those strings into garbage.
|
|
4252 */
|
|
4253
|
|
4254 /* Yeah, this list is pretty ad-hoc... */
|
|
4255 Vprocess_environment = Qnil;
|
|
4256 Vexec_directory = Qnil;
|
|
4257 Vdata_directory = Qnil;
|
110
|
4258 Vsite_directory = Qnil;
|
0
|
4259 Vdoc_directory = Qnil;
|
|
4260 Vconfigure_info_directory = Qnil;
|
|
4261 Vexec_path = Qnil;
|
|
4262 Vload_path = Qnil;
|
|
4263 /* Vdump_load_path = Qnil; */
|
233
|
4264 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \
|
|
4265 defined(LOADHIST_BUILTIN))
|
0
|
4266 Vload_history = Qnil;
|
233
|
4267 #endif
|
0
|
4268 Vshell_file_name = Qnil;
|
|
4269
|
|
4270 garbage_collect_1 ();
|
|
4271
|
|
4272 /* Run the disksave finalization methods of all live objects. */
|
|
4273 disksave_object_finalization_1 ();
|
|
4274
|
249
|
4275 #if 0 /* I don't see any point in this. The purespace starts out all 0's */
|
0
|
4276 /* Zero out the unused portion of purespace */
|
|
4277 if (!pure_lossage)
|
|
4278 memset ( (char *) (PUREBEG + pureptr), 0,
|
171
|
4279 (((char *) (PUREBEG + get_PURESIZE())) -
|
0
|
4280 ((char *) (PUREBEG + pureptr))));
|
249
|
4281 #endif
|
0
|
4282
|
|
4283 /* Zero out the uninitialized (really, unused) part of the containers
|
|
4284 for the live strings. */
|
|
4285 {
|
|
4286 struct string_chars_block *scb;
|
|
4287 for (scb = first_string_chars_block; scb; scb = scb->next)
|
249
|
4288 {
|
|
4289 int count = sizeof (scb->string_chars) - scb->pos;
|
|
4290
|
|
4291 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE);
|
|
4292 if (count != 0) {
|
|
4293 /* from the block's fill ptr to the end */
|
|
4294 memset ((scb->string_chars + scb->pos), 0, count);
|
|
4295 }
|
|
4296 }
|
0
|
4297 }
|
|
4298
|
|
4299 /* There, that ought to be enough... */
|
|
4300
|
|
4301 }
|
|
4302
|
|
4303
|
|
4304 Lisp_Object
|
|
4305 restore_gc_inhibit (Lisp_Object val)
|
|
4306 {
|
|
4307 gc_currently_forbidden = XINT (val);
|
|
4308 return val;
|
|
4309 }
|
|
4310
|
|
4311 /* Maybe we want to use this when doing a "panic" gc after memory_full()? */
|
|
4312 static int gc_hooks_inhibited;
|
|
4313
|
|
4314
|
|
4315 void
|
|
4316 garbage_collect_1 (void)
|
|
4317 {
|
|
4318 char stack_top_variable;
|
|
4319 extern char *stack_bottom;
|
|
4320 int i;
|
261
|
4321 struct frame *f;
|
0
|
4322 int speccount = specpdl_depth ();
|
|
4323 Lisp_Object pre_gc_cursor = Qnil;
|
|
4324 struct gcpro gcpro1;
|
|
4325
|
163
|
4326 int cursor_changed = 0;
|
0
|
4327
|
|
4328 if (gc_in_progress != 0)
|
|
4329 return;
|
|
4330
|
|
4331 if (gc_currently_forbidden || in_display)
|
|
4332 return;
|
|
4333
|
|
4334 if (preparing_for_armageddon)
|
|
4335 return;
|
|
4336
|
261
|
4337 /* This function cannot be called inside GC so we move to after the */
|
|
4338 /* above tests */
|
|
4339 f = selected_frame ();
|
|
4340
|
163
|
4341 GCPRO1 (pre_gc_cursor);
|
0
|
4342
|
|
4343 /* Very important to prevent GC during any of the following
|
|
4344 stuff that might run Lisp code; otherwise, we'll likely
|
|
4345 have infinite GC recursion. */
|
|
4346 record_unwind_protect (restore_gc_inhibit,
|
|
4347 make_int (gc_currently_forbidden));
|
|
4348 gc_currently_forbidden = 1;
|
|
4349
|
|
4350 if (!gc_hooks_inhibited)
|
|
4351 run_hook_trapping_errors ("Error in pre-gc-hook", Qpre_gc_hook);
|
|
4352
|
|
4353 /* Now show the GC cursor/message. */
|
|
4354 if (!noninteractive)
|
|
4355 {
|
163
|
4356 if (FRAME_WIN_P (f))
|
0
|
4357 {
|
163
|
4358 Lisp_Object frame = make_frame (f);
|
|
4359 Lisp_Object cursor = glyph_image_instance (Vgc_pointer_glyph,
|
|
4360 FRAME_SELECTED_WINDOW (f),
|
|
4361 ERROR_ME_NOT, 1);
|
|
4362 pre_gc_cursor = f->pointer;
|
|
4363 if (POINTER_IMAGE_INSTANCEP (cursor)
|
|
4364 /* don't change if we don't know how to change back. */
|
|
4365 && POINTER_IMAGE_INSTANCEP (pre_gc_cursor))
|
0
|
4366 {
|
163
|
4367 cursor_changed = 1;
|
|
4368 Fset_frame_pointer (frame, cursor);
|
0
|
4369 }
|
|
4370 }
|
163
|
4371
|
|
4372 /* Don't print messages to the stream device. */
|
|
4373 if (!cursor_changed && !FRAME_STREAM_P (f))
|
|
4374 {
|
|
4375 char *msg = (STRINGP (Vgc_message)
|
|
4376 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
|
|
4377 : 0);
|
|
4378 Lisp_Object args[2], whole_msg;
|
|
4379 args[0] = build_string (msg ? msg :
|
|
4380 GETTEXT ((CONST char *) gc_default_message));
|
|
4381 args[1] = build_string ("...");
|
|
4382 whole_msg = Fconcat (2, args);
|
|
4383 echo_area_message (f, (Bufbyte *) 0, whole_msg, 0, -1,
|
|
4384 Qgarbage_collecting);
|
|
4385 }
|
0
|
4386 }
|
|
4387
|
|
4388 /***** Now we actually start the garbage collection. */
|
|
4389
|
|
4390 gc_in_progress = 1;
|
|
4391
|
|
4392 gc_generation_number[0]++;
|
|
4393
|
|
4394 #if MAX_SAVE_STACK > 0
|
|
4395
|
|
4396 /* Save a copy of the contents of the stack, for debugging. */
|
|
4397 if (!purify_flag)
|
|
4398 {
|
|
4399 i = &stack_top_variable - stack_bottom;
|
|
4400 if (i < 0) i = -i;
|
|
4401 if (i < MAX_SAVE_STACK)
|
|
4402 {
|
|
4403 if (stack_copy == 0)
|
|
4404 stack_copy = (char *) malloc (stack_copy_size = i);
|
|
4405 else if (stack_copy_size < i)
|
|
4406 stack_copy = (char *) realloc (stack_copy, (stack_copy_size = i));
|
|
4407 if (stack_copy)
|
|
4408 {
|
|
4409 if ((int) (&stack_top_variable - stack_bottom) > 0)
|
|
4410 memcpy (stack_copy, stack_bottom, i);
|
|
4411 else
|
|
4412 memcpy (stack_copy, &stack_top_variable, i);
|
|
4413 }
|
|
4414 }
|
|
4415 }
|
|
4416 #endif /* MAX_SAVE_STACK > 0 */
|
|
4417
|
|
4418 /* Do some totally ad-hoc resource clearing. */
|
|
4419 /* #### generalize this? */
|
|
4420 clear_event_resource ();
|
|
4421 cleanup_specifiers ();
|
|
4422
|
|
4423 /* Mark all the special slots that serve as the roots of accessibility. */
|
|
4424 {
|
|
4425 struct gcpro *tail;
|
|
4426 struct catchtag *catch;
|
|
4427 struct backtrace *backlist;
|
|
4428 struct specbinding *bind;
|
|
4429
|
|
4430 for (i = 0; i < staticidx; i++)
|
|
4431 {
|
|
4432 #ifdef GDB_SUCKS
|
|
4433 printf ("%d\n", i);
|
|
4434 debug_print (*staticvec[i]);
|
|
4435 #endif
|
|
4436 mark_object (*(staticvec[i]));
|
|
4437 }
|
|
4438
|
|
4439 for (tail = gcprolist; tail; tail = tail->next)
|
|
4440 {
|
|
4441 for (i = 0; i < tail->nvars; i++)
|
|
4442 mark_object (tail->var[i]);
|
|
4443 }
|
|
4444
|
|
4445 for (bind = specpdl; bind != specpdl_ptr; bind++)
|
|
4446 {
|
|
4447 mark_object (bind->symbol);
|
|
4448 mark_object (bind->old_value);
|
|
4449 }
|
|
4450
|
|
4451 for (catch = catchlist; catch; catch = catch->next)
|
|
4452 {
|
|
4453 mark_object (catch->tag);
|
|
4454 mark_object (catch->val);
|
|
4455 }
|
|
4456
|
|
4457 for (backlist = backtrace_list; backlist; backlist = backlist->next)
|
|
4458 {
|
|
4459 int nargs = backlist->nargs;
|
|
4460
|
|
4461 mark_object (*backlist->function);
|
|
4462 if (nargs == UNEVALLED || nargs == MANY)
|
|
4463 mark_object (backlist->args[0]);
|
|
4464 else
|
|
4465 for (i = 0; i < nargs; i++)
|
|
4466 mark_object (backlist->args[i]);
|
|
4467 }
|
|
4468
|
|
4469 mark_redisplay (mark_object);
|
100
|
4470 #ifndef WINDOWSNT
|
0
|
4471 mark_profiling_info (mark_object);
|
100
|
4472 #endif
|
0
|
4473 }
|
|
4474
|
|
4475 /* OK, now do the after-mark stuff. This is for things that
|
|
4476 are only marked when something else is marked (e.g. weak hashtables).
|
|
4477 There may be complex dependencies between such objects -- e.g.
|
|
4478 a weak hashtable might be unmarked, but after processing a later
|
|
4479 weak hashtable, the former one might get marked. So we have to
|
|
4480 iterate until nothing more gets marked. */
|
|
4481 {
|
|
4482 int did_mark;
|
|
4483 /* Need to iterate until there's nothing more to mark, in case
|
|
4484 of chains of mark dependencies. */
|
|
4485 do
|
|
4486 {
|
|
4487 did_mark = 0;
|
|
4488 did_mark += !!finish_marking_weak_hashtables (marked_p, mark_object);
|
|
4489 did_mark += !!finish_marking_weak_lists (marked_p, mark_object);
|
|
4490 }
|
|
4491 while (did_mark);
|
|
4492 }
|
|
4493
|
|
4494 /* And prune (this needs to be called after everything else has been
|
|
4495 marked and before we do any sweeping). */
|
|
4496 /* #### this is somewhat ad-hoc and should probably be an object
|
|
4497 method */
|
|
4498 prune_weak_hashtables (marked_p);
|
|
4499 prune_weak_lists (marked_p);
|
|
4500 prune_specifiers (marked_p);
|
70
|
4501 prune_syntax_tables (marked_p);
|
0
|
4502
|
|
4503 gc_sweep ();
|
|
4504
|
|
4505 consing_since_gc = 0;
|
|
4506 #ifndef DEBUG_XEMACS
|
|
4507 /* Allow you to set it really fucking low if you really want ... */
|
|
4508 if (gc_cons_threshold < 10000)
|
|
4509 gc_cons_threshold = 10000;
|
|
4510 #endif
|
|
4511
|
|
4512 gc_in_progress = 0;
|
|
4513
|
|
4514 /******* End of garbage collection ********/
|
|
4515
|
|
4516 run_hook_trapping_errors ("Error in post-gc-hook", Qpost_gc_hook);
|
|
4517
|
|
4518 /* Now remove the GC cursor/message */
|
|
4519 if (!noninteractive)
|
|
4520 {
|
163
|
4521 if (cursor_changed)
|
|
4522 Fset_frame_pointer (make_frame (f), pre_gc_cursor);
|
|
4523 else if (!FRAME_STREAM_P (f))
|
0
|
4524 {
|
|
4525 char *msg = (STRINGP (Vgc_message)
|
14
|
4526 ? GETTEXT ((char *) XSTRING_DATA (Vgc_message))
|
0
|
4527 : 0);
|
|
4528
|
|
4529 /* Show "...done" only if the echo area would otherwise be empty. */
|
183
|
4530 if (NILP (clear_echo_area (selected_frame (),
|
0
|
4531 Qgarbage_collecting, 0)))
|
|
4532 {
|
|
4533 Lisp_Object args[2], whole_msg;
|
|
4534 args[0] = build_string (msg ? msg :
|
|
4535 GETTEXT ((CONST char *)
|
|
4536 gc_default_message));
|
|
4537 args[1] = build_string ("... done");
|
|
4538 whole_msg = Fconcat (2, args);
|
|
4539 echo_area_message (selected_frame (), (Bufbyte *) 0,
|
|
4540 whole_msg, 0, -1,
|
|
4541 Qgarbage_collecting);
|
|
4542 }
|
|
4543 }
|
|
4544 }
|
|
4545
|
|
4546 /* now stop inhibiting GC */
|
|
4547 unbind_to (speccount, Qnil);
|
|
4548
|
|
4549 if (!breathing_space)
|
|
4550 {
|
|
4551 breathing_space = (void *) malloc (4096 - MALLOC_OVERHEAD);
|
|
4552 }
|
|
4553
|
|
4554 UNGCPRO;
|
|
4555 return;
|
|
4556 }
|
|
4557
|
|
4558 #ifdef EMACS_BTL
|
|
4559 /* This isn't actually called. BTL recognizes the stack frame of the top
|
|
4560 of the garbage collector by noting that PC is between &garbage_collect_1
|
|
4561 and &BTL_after_garbage_collect_1_stub. So this fn must be right here.
|
|
4562 There's not any other way to know the address of the end of a function.
|
|
4563 */
|
|
4564 void BTL_after_garbage_collect_1_stub () { abort (); }
|
183
|
4565 #endif /* EMACS_BTL */
|
0
|
4566
|
|
4567 /* Debugging aids. */
|
|
4568
|
|
4569 static Lisp_Object
|
|
4570 gc_plist_hack (CONST char *name, int value, Lisp_Object tail)
|
|
4571 {
|
|
4572 /* C doesn't have local functions (or closures, or GC, or readable syntax,
|
|
4573 or portable numeric datatypes, or bit-vectors, or characters, or
|
|
4574 arrays, or exceptions, or ...) */
|
173
|
4575 return cons3 (intern (name), make_int (value), tail);
|
0
|
4576 }
|
|
4577
|
|
4578 #define HACK_O_MATIC(type, name, pl) \
|
|
4579 { \
|
|
4580 int s = 0; \
|
|
4581 struct type##_block *x = current_##type##_block; \
|
|
4582 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \
|
|
4583 (pl) = gc_plist_hack ((name), s, (pl)); \
|
|
4584 }
|
|
4585
|
20
|
4586 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /*
|
0
|
4587 Reclaim storage for Lisp objects no longer needed.
|
|
4588 Returns info on amount of space in use:
|
|
4589 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)
|
|
4590 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
|
183
|
4591 PLIST)
|
0
|
4592 where `PLIST' is a list of alternating keyword/value pairs providing
|
|
4593 more detailed information.
|
|
4594 Garbage collection happens automatically if you cons more than
|
|
4595 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.
|
20
|
4596 */
|
|
4597 ())
|
0
|
4598 {
|
|
4599 Lisp_Object pl = Qnil;
|
|
4600 Lisp_Object ret[6];
|
|
4601 int i;
|
207
|
4602 #ifdef LRECORD_VECTOR
|
243
|
4603 int gc_count_vector_total_size = 0;
|
207
|
4604 #endif
|
0
|
4605
|
104
|
4606 if (purify_flag && pure_lossage)
|
|
4607 {
|
|
4608 return Qnil;
|
|
4609 }
|
|
4610
|
0
|
4611 garbage_collect_1 ();
|
|
4612
|
|
4613 for (i = 0; i < last_lrecord_type_index_assigned; i++)
|
|
4614 {
|
183
|
4615 if (lcrecord_stats[i].bytes_in_use != 0
|
0
|
4616 || lcrecord_stats[i].bytes_freed != 0
|
|
4617 || lcrecord_stats[i].instances_on_free_list != 0)
|
|
4618 {
|
|
4619 char buf [255];
|
|
4620 CONST char *name = lrecord_implementations_table[i]->name;
|
|
4621 int len = strlen (name);
|
207
|
4622 #ifdef LRECORD_VECTOR
|
|
4623 /* save this for the FSFmacs-compatible part of the summary */
|
|
4624 if (i == *lrecord_vector[0].lrecord_type_index)
|
|
4625 gc_count_vector_total_size =
|
|
4626 lcrecord_stats[i].bytes_in_use + lcrecord_stats[i].bytes_freed;
|
|
4627 #endif
|
0
|
4628 sprintf (buf, "%s-storage", name);
|
|
4629 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
|
|
4630 /* Okay, simple pluralization check for `symbol-value-varalias' */
|
|
4631 if (name[len-1] == 's')
|
|
4632 sprintf (buf, "%ses-freed", name);
|
|
4633 else
|
|
4634 sprintf (buf, "%ss-freed", name);
|
|
4635 if (lcrecord_stats[i].instances_freed != 0)
|
|
4636 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl);
|
|
4637 if (name[len-1] == 's')
|
|
4638 sprintf (buf, "%ses-on-free-list", name);
|
|
4639 else
|
|
4640 sprintf (buf, "%ss-on-free-list", name);
|
|
4641 if (lcrecord_stats[i].instances_on_free_list != 0)
|
|
4642 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list,
|
|
4643 pl);
|
|
4644 if (name[len-1] == 's')
|
|
4645 sprintf (buf, "%ses-used", name);
|
|
4646 else
|
|
4647 sprintf (buf, "%ss-used", name);
|
|
4648 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl);
|
|
4649 }
|
|
4650 }
|
|
4651
|
|
4652 HACK_O_MATIC (extent, "extent-storage", pl);
|
|
4653 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl);
|
|
4654 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl);
|
|
4655 HACK_O_MATIC (event, "event-storage", pl);
|
|
4656 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl);
|
|
4657 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl);
|
|
4658 HACK_O_MATIC (marker, "marker-storage", pl);
|
|
4659 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
|
|
4660 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
|
|
4661 #ifdef LISP_FLOAT_TYPE
|
|
4662 HACK_O_MATIC (float, "float-storage", pl);
|
|
4663 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
|
|
4664 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
|
|
4665 #endif /* LISP_FLOAT_TYPE */
|
|
4666 HACK_O_MATIC (string, "string-header-storage", pl);
|
183
|
4667 pl = gc_plist_hack ("long-strings-total-length",
|
0
|
4668 gc_count_string_total_size
|
|
4669 - gc_count_short_string_total_size, pl);
|
|
4670 HACK_O_MATIC (string_chars, "short-string-storage", pl);
|
|
4671 pl = gc_plist_hack ("short-strings-total-length",
|
|
4672 gc_count_short_string_total_size, pl);
|
|
4673 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl);
|
183
|
4674 pl = gc_plist_hack ("long-strings-used",
|
0
|
4675 gc_count_num_string_in_use
|
|
4676 - gc_count_num_short_string_in_use, pl);
|
183
|
4677 pl = gc_plist_hack ("short-strings-used",
|
0
|
4678 gc_count_num_short_string_in_use, pl);
|
|
4679
|
|
4680 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl);
|
|
4681 pl = gc_plist_hack ("compiled-functions-free",
|
|
4682 gc_count_num_compiled_function_freelist, pl);
|
|
4683 pl = gc_plist_hack ("compiled-functions-used",
|
|
4684 gc_count_num_compiled_function_in_use, pl);
|
|
4685
|
207
|
4686 #ifndef LRECORD_VECTOR
|
0
|
4687 pl = gc_plist_hack ("vector-storage", gc_count_vector_storage, pl);
|
183
|
4688 pl = gc_plist_hack ("vectors-total-length",
|
0
|
4689 gc_count_vector_total_size, pl);
|
|
4690 pl = gc_plist_hack ("vectors-used", gc_count_num_vector_used, pl);
|
207
|
4691 #endif
|
0
|
4692
|
|
4693 pl = gc_plist_hack ("bit-vector-storage", gc_count_bit_vector_storage, pl);
|
183
|
4694 pl = gc_plist_hack ("bit-vectors-total-length",
|
0
|
4695 gc_count_bit_vector_total_size, pl);
|
|
4696 pl = gc_plist_hack ("bit-vectors-used", gc_count_num_bit_vector_used, pl);
|
|
4697
|
|
4698 HACK_O_MATIC (symbol, "symbol-storage", pl);
|
|
4699 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl);
|
|
4700 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl);
|
|
4701
|
|
4702 HACK_O_MATIC (cons, "cons-storage", pl);
|
|
4703 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl);
|
|
4704 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl);
|
|
4705
|
|
4706 /* The things we do for backwards-compatibility */
|
|
4707 ret[0] = Fcons (make_int (gc_count_num_cons_in_use),
|
|
4708 make_int (gc_count_num_cons_freelist));
|
|
4709 ret[1] = Fcons (make_int (gc_count_num_symbol_in_use),
|
|
4710 make_int (gc_count_num_symbol_freelist));
|
|
4711 ret[2] = Fcons (make_int (gc_count_num_marker_in_use),
|
|
4712 make_int (gc_count_num_marker_freelist));
|
|
4713 ret[3] = make_int (gc_count_string_total_size);
|
|
4714 ret[4] = make_int (gc_count_vector_total_size);
|
|
4715 ret[5] = pl;
|
173
|
4716 return Flist (6, ret);
|
0
|
4717 }
|
|
4718 #undef HACK_O_MATIC
|
|
4719
|
20
|
4720 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /*
|
0
|
4721 Return the number of bytes consed since the last garbage collection.
|
|
4722 \"Consed\" is a misnomer in that this actually counts allocation
|
|
4723 of all different kinds of objects, not just conses.
|
|
4724
|
|
4725 If this value exceeds `gc-cons-threshold', a garbage collection happens.
|
20
|
4726 */
|
|
4727 ())
|
0
|
4728 {
|
173
|
4729 return make_int (consing_since_gc);
|
0
|
4730 }
|
183
|
4731
|
20
|
4732 DEFUN ("memory-limit", Fmemory_limit, 0, 0, "", /*
|
0
|
4733 Return the address of the last byte Emacs has allocated, divided by 1024.
|
|
4734 This may be helpful in debugging Emacs's memory usage.
|
|
4735 The value is divided by 1024 to make sure it will fit in a lisp integer.
|
20
|
4736 */
|
|
4737 ())
|
0
|
4738 {
|
173
|
4739 return make_int ((EMACS_INT) sbrk (0) / 1024);
|
0
|
4740 }
|
|
4741
|
|
4742
|
|
4743
|
|
4744 int
|
|
4745 object_dead_p (Lisp_Object obj)
|
|
4746 {
|
173
|
4747 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) ||
|
|
4748 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) ||
|
|
4749 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) ||
|
|
4750 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) ||
|
0
|
4751 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) ||
|
173
|
4752 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) ||
|
|
4753 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj))));
|
183
|
4754
|
0
|
4755 }
|
|
4756
|
|
4757 #ifdef MEMORY_USAGE_STATS
|
|
4758
|
|
4759 /* Attempt to determine the actual amount of space that is used for
|
|
4760 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE".
|
|
4761
|
|
4762 It seems that the following holds:
|
|
4763
|
|
4764 1. When using the old allocator (malloc.c):
|
|
4765
|
|
4766 -- blocks are always allocated in chunks of powers of two. For
|
|
4767 each block, there is an overhead of 8 bytes if rcheck is not
|
|
4768 defined, 20 bytes if it is defined. In other words, a
|
|
4769 one-byte allocation needs 8 bytes of overhead for a total of
|
|
4770 9 bytes, and needs to have 16 bytes of memory chunked out for
|
|
4771 it.
|
|
4772
|
|
4773 2. When using the new allocator (gmalloc.c):
|
|
4774
|
|
4775 -- blocks are always allocated in chunks of powers of two up
|
|
4776 to 4096 bytes. Larger blocks are allocated in chunks of
|
|
4777 an integral multiple of 4096 bytes. The minimum block
|
|
4778 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
|
|
4779 is defined. There is no per-block overhead, but there
|
|
4780 is an overhead of 3*sizeof (size_t) for each 4096 bytes
|
|
4781 allocated.
|
|
4782
|
|
4783 3. When using the system malloc, anything goes, but they are
|
|
4784 generally slower and more space-efficient than the GNU
|
|
4785 allocators. One possibly reasonable assumption to make
|
|
4786 for want of better data is that sizeof (void *), or maybe
|
|
4787 2 * sizeof (void *), is required as overhead and that
|
|
4788 blocks are allocated in the minimum required size except
|
|
4789 that some minimum block size is imposed (e.g. 16 bytes). */
|
|
4790
|
|
4791 int
|
|
4792 malloced_storage_size (void *ptr, int claimed_size,
|
|
4793 struct overhead_stats *stats)
|
|
4794 {
|
|
4795 int orig_claimed_size = claimed_size;
|
|
4796
|
|
4797 #ifdef GNU_MALLOC
|
|
4798
|
|
4799 if (claimed_size < 2 * sizeof (void *))
|
|
4800 claimed_size = 2 * sizeof (void *);
|
|
4801 # ifdef SUNOS_LOCALTIME_BUG
|
|
4802 if (claimed_size < 16)
|
|
4803 claimed_size = 16;
|
|
4804 # endif
|
|
4805 if (claimed_size < 4096)
|
|
4806 {
|
|
4807 int log = 1;
|
|
4808
|
|
4809 /* compute the log base two, more or less, then use it to compute
|
|
4810 the block size needed. */
|
|
4811 claimed_size--;
|
|
4812 /* It's big, it's heavy, it's wood! */
|
|
4813 while ((claimed_size /= 2) != 0)
|
|
4814 ++log;
|
|
4815 claimed_size = 1;
|
|
4816 /* It's better than bad, it's good! */
|
|
4817 while (log > 0)
|
|
4818 {
|
|
4819 claimed_size *= 2;
|
|
4820 log--;
|
|
4821 }
|
|
4822 /* We have to come up with some average about the amount of
|
|
4823 blocks used. */
|
|
4824 if ((rand () & 4095) < claimed_size)
|
|
4825 claimed_size += 3 * sizeof (void *);
|
|
4826 }
|
|
4827 else
|
|
4828 {
|
|
4829 claimed_size += 4095;
|
|
4830 claimed_size &= ~4095;
|
|
4831 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t);
|
|
4832 }
|
|
4833
|
|
4834 #elif defined (SYSTEM_MALLOC)
|
|
4835
|
|
4836 if (claimed_size < 16)
|
|
4837 claimed_size = 16;
|
|
4838 claimed_size += 2 * sizeof (void *);
|
|
4839
|
|
4840 #else /* old GNU allocator */
|
|
4841
|
|
4842 # ifdef rcheck /* #### may not be defined here */
|
|
4843 claimed_size += 20;
|
|
4844 # else
|
|
4845 claimed_size += 8;
|
|
4846 # endif
|
|
4847 {
|
|
4848 int log = 1;
|
|
4849
|
|
4850 /* compute the log base two, more or less, then use it to compute
|
|
4851 the block size needed. */
|
|
4852 claimed_size--;
|
|
4853 /* It's big, it's heavy, it's wood! */
|
|
4854 while ((claimed_size /= 2) != 0)
|
|
4855 ++log;
|
|
4856 claimed_size = 1;
|
|
4857 /* It's better than bad, it's good! */
|
|
4858 while (log > 0)
|
|
4859 {
|
|
4860 claimed_size *= 2;
|
|
4861 log--;
|
|
4862 }
|
|
4863 }
|
|
4864
|
|
4865 #endif /* old GNU allocator */
|
|
4866
|
|
4867 if (stats)
|
|
4868 {
|
|
4869 stats->was_requested += orig_claimed_size;
|
|
4870 stats->malloc_overhead += claimed_size - orig_claimed_size;
|
|
4871 }
|
|
4872 return claimed_size;
|
|
4873 }
|
|
4874
|
|
4875 int
|
|
4876 fixed_type_block_overhead (int size)
|
|
4877 {
|
|
4878 int per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
|
|
4879 int overhead = 0;
|
|
4880 int storage_size = malloced_storage_size (0, per_block, 0);
|
|
4881 while (size >= per_block)
|
|
4882 {
|
|
4883 size -= per_block;
|
|
4884 overhead += sizeof (void *) + per_block - storage_size;
|
|
4885
|
|
4886 }
|
|
4887 if (rand () % per_block < size)
|
|
4888 overhead += sizeof (void *) + per_block - storage_size;
|
|
4889 return overhead;
|
|
4890 }
|
|
4891
|
|
4892 #endif /* MEMORY_USAGE_STATS */
|
|
4893
|
|
4894
|
|
4895 /* Initialization */
|
|
4896 void
|
|
4897 init_alloc_once_early (void)
|
|
4898 {
|
|
4899 int iii;
|
|
4900
|
|
4901 #ifdef PURESTAT
|
|
4902 for (iii = 0; iii < countof (purestats); iii++)
|
|
4903 {
|
|
4904 if (! purestats[iii]) continue;
|
|
4905 purestats[iii]->nobjects = 0;
|
|
4906 purestats[iii]->nbytes = 0;
|
|
4907 }
|
|
4908 purecopying_for_bytecode = 0;
|
183
|
4909 #endif /* PURESTAT */
|
|
4910
|
0
|
4911 last_lrecord_type_index_assigned = -1;
|
|
4912 for (iii = 0; iii < countof (lrecord_implementations_table); iii++)
|
|
4913 {
|
|
4914 lrecord_implementations_table[iii] = 0;
|
|
4915 }
|
183
|
4916
|
211
|
4917 #ifdef USE_INDEXED_LRECORD_IMPLEMENTATION
|
|
4918 /*
|
|
4919 * If USE_INDEXED_LRECORD_IMPLEMENTATION is defined, all the staticly
|
|
4920 * defined subr lrecords were initialized with lheader->type == 0.
|
|
4921 * See subr_lheader_initializer in lisp.h. Force type index 0 to be
|
|
4922 * assigned to lrecord_subr so that those predefined indexes match
|
|
4923 * reality.
|
|
4924 */
|
|
4925 (void) lrecord_type_index (lrecord_subr);
|
|
4926 assert (*(lrecord_subr[0].lrecord_type_index) == 0);
|
|
4927 /*
|
|
4928 * The same is true for symbol_value_forward objects, except the
|
|
4929 * type is 1.
|
|
4930 */
|
|
4931 (void) lrecord_type_index (lrecord_symbol_value_forward);
|
|
4932 assert (*(lrecord_symbol_value_forward[0].lrecord_type_index) == 1);
|
|
4933 #endif
|
|
4934
|
0
|
4935 symbols_initialized = 0;
|
183
|
4936
|
0
|
4937 gc_generation_number[0] = 0;
|
|
4938 /* purify_flag 1 is correct even if CANNOT_DUMP.
|
|
4939 * loadup.el will set to nil at end. */
|
|
4940 purify_flag = 1;
|
|
4941 pureptr = 0;
|
|
4942 pure_lossage = 0;
|
|
4943 breathing_space = 0;
|
207
|
4944 #ifndef LRECORD_VECTOR
|
0
|
4945 XSETINT (all_vectors, 0); /* Qzero may not be set yet. */
|
207
|
4946 #endif
|
0
|
4947 XSETINT (all_bit_vectors, 0); /* Qzero may not be set yet. */
|
|
4948 XSETINT (Vgc_message, 0);
|
|
4949 all_lcrecords = 0;
|
|
4950 ignore_malloc_warnings = 1;
|
255
|
4951 #ifdef DOUG_LEA_MALLOC
|
|
4952 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
|
|
4953 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */
|
261
|
4954 #if 0 /* Moved to emacs.c */
|
|
4955 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */
|
|
4956 #endif
|
255
|
4957 #endif
|
0
|
4958 init_string_alloc ();
|
|
4959 init_string_chars_alloc ();
|
|
4960 init_cons_alloc ();
|
|
4961 init_symbol_alloc ();
|
|
4962 init_compiled_function_alloc ();
|
|
4963 #ifdef LISP_FLOAT_TYPE
|
|
4964 init_float_alloc ();
|
|
4965 #endif /* LISP_FLOAT_TYPE */
|
|
4966 #ifndef standalone
|
|
4967 init_marker_alloc ();
|
|
4968 init_extent_alloc ();
|
|
4969 init_event_alloc ();
|
|
4970 #endif
|
|
4971 ignore_malloc_warnings = 0;
|
|
4972 staticidx = 0;
|
|
4973 consing_since_gc = 0;
|
|
4974 #if 1
|
|
4975 gc_cons_threshold = 500000; /* XEmacs change */
|
|
4976 #else
|
|
4977 gc_cons_threshold = 15000; /* debugging */
|
|
4978 #endif
|
|
4979 #ifdef VIRT_ADDR_VARIES
|
|
4980 malloc_sbrk_unused = 1<<22; /* A large number */
|
|
4981 malloc_sbrk_used = 100000; /* as reasonable as any number */
|
|
4982 #endif /* VIRT_ADDR_VARIES */
|
|
4983 lrecord_uid_counter = 259;
|
|
4984 debug_string_purity = 0;
|
|
4985 gcprolist = 0;
|
|
4986
|
|
4987 gc_currently_forbidden = 0;
|
|
4988 gc_hooks_inhibited = 0;
|
|
4989
|
|
4990 #ifdef ERROR_CHECK_TYPECHECK
|
|
4991 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4992 666;
|
|
4993 ERROR_ME_NOT.
|
|
4994 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42;
|
|
4995 ERROR_ME_WARN.
|
|
4996 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4997 3333632;
|
183
|
4998 #endif /* ERROR_CHECK_TYPECHECK */
|
0
|
4999 }
|
|
5000
|
|
5001 void
|
|
5002 reinit_alloc (void)
|
|
5003 {
|
|
5004 gcprolist = 0;
|
|
5005 }
|
|
5006
|
|
5007 void
|
|
5008 syms_of_alloc (void)
|
|
5009 {
|
|
5010 defsymbol (&Qpre_gc_hook, "pre-gc-hook");
|
|
5011 defsymbol (&Qpost_gc_hook, "post-gc-hook");
|
|
5012 defsymbol (&Qgarbage_collecting, "garbage-collecting");
|
|
5013
|
20
|
5014 DEFSUBR (Fcons);
|
|
5015 DEFSUBR (Flist);
|
|
5016 DEFSUBR (Fvector);
|
|
5017 DEFSUBR (Fbit_vector);
|
|
5018 DEFSUBR (Fmake_byte_code);
|
|
5019 DEFSUBR (Fmake_list);
|
|
5020 DEFSUBR (Fmake_vector);
|
|
5021 DEFSUBR (Fmake_bit_vector);
|
|
5022 DEFSUBR (Fmake_string);
|
|
5023 DEFSUBR (Fmake_symbol);
|
|
5024 DEFSUBR (Fmake_marker);
|
|
5025 DEFSUBR (Fpurecopy);
|
|
5026 DEFSUBR (Fgarbage_collect);
|
|
5027 DEFSUBR (Fmemory_limit);
|
|
5028 DEFSUBR (Fconsing_since_gc);
|
0
|
5029 }
|
|
5030
|
|
5031 void
|
|
5032 vars_of_alloc (void)
|
|
5033 {
|
|
5034 DEFVAR_INT ("gc-cons-threshold", &gc_cons_threshold /*
|
|
5035 *Number of bytes of consing between garbage collections.
|
|
5036 \"Consing\" is a misnomer in that this actually counts allocation
|
|
5037 of all different kinds of objects, not just conses.
|
|
5038 Garbage collection can happen automatically once this many bytes have been
|
|
5039 allocated since the last garbage collection. All data types count.
|
|
5040
|
|
5041 Garbage collection happens automatically when `eval' or `funcall' are
|
|
5042 called. (Note that `funcall' is called implicitly as part of evaluation.)
|
|
5043 By binding this temporarily to a large number, you can effectively
|
|
5044 prevent garbage collection during a part of the program.
|
|
5045
|
|
5046 See also `consing-since-gc'.
|
|
5047 */ );
|
|
5048
|
|
5049 DEFVAR_INT ("pure-bytes-used", &pureptr /*
|
|
5050 Number of bytes of sharable Lisp data allocated so far.
|
|
5051 */ );
|
|
5052
|
|
5053 #if 0
|
|
5054 DEFVAR_INT ("data-bytes-used", &malloc_sbrk_used /*
|
|
5055 Number of bytes of unshared memory allocated in this session.
|
|
5056 */ );
|
|
5057
|
|
5058 DEFVAR_INT ("data-bytes-free", &malloc_sbrk_unused /*
|
|
5059 Number of bytes of unshared memory remaining available in this session.
|
|
5060 */ );
|
|
5061 #endif
|
|
5062
|
|
5063 #ifdef DEBUG_XEMACS
|
|
5064 DEFVAR_INT ("debug-allocation", &debug_allocation /*
|
|
5065 If non-zero, print out information to stderr about all objects allocated.
|
|
5066 See also `debug-allocation-backtrace-length'.
|
|
5067 */ );
|
|
5068 debug_allocation = 0;
|
|
5069
|
|
5070 DEFVAR_INT ("debug-allocation-backtrace-length",
|
|
5071 &debug_allocation_backtrace_length /*
|
|
5072 Length (in stack frames) of short backtrace printed out by `debug-allocation'.
|
|
5073 */ );
|
|
5074 debug_allocation_backtrace_length = 2;
|
|
5075 #endif
|
|
5076
|
|
5077 DEFVAR_BOOL ("purify-flag", &purify_flag /*
|
|
5078 Non-nil means loading Lisp code in order to dump an executable.
|
|
5079 This means that certain objects should be allocated in shared (pure) space.
|
|
5080 */ );
|
|
5081
|
|
5082 DEFVAR_LISP ("pre-gc-hook", &Vpre_gc_hook /*
|
|
5083 Function or functions to be run just before each garbage collection.
|
|
5084 Interrupts, garbage collection, and errors are inhibited while this hook
|
|
5085 runs, so be extremely careful in what you add here. In particular, avoid
|
|
5086 consing, and do not interact with the user.
|
|
5087 */ );
|
|
5088 Vpre_gc_hook = Qnil;
|
|
5089
|
|
5090 DEFVAR_LISP ("post-gc-hook", &Vpost_gc_hook /*
|
|
5091 Function or functions to be run just after each garbage collection.
|
|
5092 Interrupts, garbage collection, and errors are inhibited while this hook
|
|
5093 runs, so be extremely careful in what you add here. In particular, avoid
|
|
5094 consing, and do not interact with the user.
|
|
5095 */ );
|
|
5096 Vpost_gc_hook = Qnil;
|
|
5097
|
|
5098 DEFVAR_LISP ("gc-message", &Vgc_message /*
|
|
5099 String to print to indicate that a garbage collection is in progress.
|
|
5100 This is printed in the echo area. If the selected frame is on a
|
|
5101 window system and `gc-pointer-glyph' specifies a value (i.e. a pointer
|
|
5102 image instance) in the domain of the selected frame, the mouse pointer
|
|
5103 will change instead of this message being printed.
|
|
5104 */ );
|
|
5105 Vgc_message = make_pure_string ((CONST Bufbyte *) gc_default_message,
|
|
5106 countof (gc_default_message) - 1,
|
|
5107 Qnil, 1);
|
|
5108
|
|
5109 DEFVAR_LISP ("gc-pointer-glyph", &Vgc_pointer_glyph /*
|
|
5110 Pointer glyph used to indicate that a garbage collection is in progress.
|
|
5111 If the selected window is on a window system and this glyph specifies a
|
|
5112 value (i.e. a pointer image instance) in the domain of the selected
|
|
5113 window, the pointer will be changed as specified during garbage collection.
|
|
5114 Otherwise, a message will be printed in the echo area, as controlled
|
|
5115 by `gc-message'.
|
|
5116 */ );
|
|
5117 }
|
|
5118
|
|
5119 void
|
|
5120 complex_vars_of_alloc (void)
|
|
5121 {
|
|
5122 Vgc_pointer_glyph = Fmake_glyph_internal (Qpointer);
|
|
5123 }
|