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