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