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