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