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, /*
|
3355
|
1258 Create a new cons cell, give it CAR and CDR as components, and return it.
|
|
1259
|
|
1260 A cons cell is a Lisp object (an area in memory) made up of two pointers
|
|
1261 called the CAR and the CDR. Each of these pointers can point to any other
|
|
1262 Lisp object. The common Lisp data type, the list, is a specially-structured
|
|
1263 series of cons cells.
|
|
1264
|
|
1265 The pointers are accessed from Lisp with `car' and `cdr', and mutated with
|
|
1266 `setcar' and `setcdr' respectively. For historical reasons, the aliases
|
|
1267 `rplaca' and `rplacd' (for `setcar' and `setcdr') are supported.
|
428
|
1268 */
|
|
1269 (car, cdr))
|
|
1270 {
|
|
1271 /* This cannot GC. */
|
|
1272 Lisp_Object val;
|
440
|
1273 Lisp_Cons *c;
|
|
1274
|
3017
|
1275 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (cons, Lisp_Cons, c, &lrecord_cons);
|
793
|
1276 val = wrap_cons (c);
|
853
|
1277 XSETCAR (val, car);
|
|
1278 XSETCDR (val, cdr);
|
428
|
1279 return val;
|
|
1280 }
|
|
1281
|
|
1282 /* This is identical to Fcons() but it used for conses that we're
|
|
1283 going to free later, and is useful when trying to track down
|
|
1284 "real" consing. */
|
|
1285 Lisp_Object
|
|
1286 noseeum_cons (Lisp_Object car, Lisp_Object cdr)
|
|
1287 {
|
|
1288 Lisp_Object val;
|
440
|
1289 Lisp_Cons *c;
|
|
1290
|
3017
|
1291 NOSEEUM_ALLOCATE_FIXED_TYPE_AND_SET_IMPL (cons, Lisp_Cons, c, &lrecord_cons);
|
793
|
1292 val = wrap_cons (c);
|
428
|
1293 XCAR (val) = car;
|
|
1294 XCDR (val) = cdr;
|
|
1295 return val;
|
|
1296 }
|
|
1297
|
|
1298 DEFUN ("list", Flist, 0, MANY, 0, /*
|
|
1299 Return a newly created list with specified arguments as elements.
|
|
1300 Any number of arguments, even zero arguments, are allowed.
|
|
1301 */
|
|
1302 (int nargs, Lisp_Object *args))
|
|
1303 {
|
|
1304 Lisp_Object val = Qnil;
|
|
1305 Lisp_Object *argp = args + nargs;
|
|
1306
|
|
1307 while (argp > args)
|
|
1308 val = Fcons (*--argp, val);
|
|
1309 return val;
|
|
1310 }
|
|
1311
|
|
1312 Lisp_Object
|
|
1313 list1 (Lisp_Object obj0)
|
|
1314 {
|
|
1315 /* This cannot GC. */
|
|
1316 return Fcons (obj0, Qnil);
|
|
1317 }
|
|
1318
|
|
1319 Lisp_Object
|
|
1320 list2 (Lisp_Object obj0, Lisp_Object obj1)
|
|
1321 {
|
|
1322 /* This cannot GC. */
|
|
1323 return Fcons (obj0, Fcons (obj1, Qnil));
|
|
1324 }
|
|
1325
|
|
1326 Lisp_Object
|
|
1327 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1328 {
|
|
1329 /* This cannot GC. */
|
|
1330 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Qnil)));
|
|
1331 }
|
|
1332
|
|
1333 Lisp_Object
|
|
1334 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1335 {
|
|
1336 /* This cannot GC. */
|
|
1337 return Fcons (obj0, Fcons (obj1, obj2));
|
|
1338 }
|
|
1339
|
|
1340 Lisp_Object
|
|
1341 acons (Lisp_Object key, Lisp_Object value, Lisp_Object alist)
|
|
1342 {
|
|
1343 return Fcons (Fcons (key, value), alist);
|
|
1344 }
|
|
1345
|
|
1346 Lisp_Object
|
|
1347 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3)
|
|
1348 {
|
|
1349 /* This cannot GC. */
|
|
1350 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Qnil))));
|
|
1351 }
|
|
1352
|
|
1353 Lisp_Object
|
|
1354 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
|
|
1355 Lisp_Object obj4)
|
|
1356 {
|
|
1357 /* This cannot GC. */
|
|
1358 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Qnil)))));
|
|
1359 }
|
|
1360
|
|
1361 Lisp_Object
|
|
1362 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3,
|
|
1363 Lisp_Object obj4, Lisp_Object obj5)
|
|
1364 {
|
|
1365 /* This cannot GC. */
|
|
1366 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Fcons (obj5, Qnil))))));
|
|
1367 }
|
|
1368
|
|
1369 DEFUN ("make-list", Fmake_list, 2, 2, 0, /*
|
444
|
1370 Return a new list of length LENGTH, with each element being OBJECT.
|
428
|
1371 */
|
444
|
1372 (length, object))
|
428
|
1373 {
|
|
1374 CHECK_NATNUM (length);
|
|
1375
|
|
1376 {
|
|
1377 Lisp_Object val = Qnil;
|
647
|
1378 EMACS_INT size = XINT (length);
|
428
|
1379
|
|
1380 while (size--)
|
444
|
1381 val = Fcons (object, val);
|
428
|
1382 return val;
|
|
1383 }
|
|
1384 }
|
|
1385
|
|
1386
|
|
1387 /************************************************************************/
|
|
1388 /* Float allocation */
|
|
1389 /************************************************************************/
|
|
1390
|
1983
|
1391 /*** With enhanced number support, these are short floats */
|
|
1392
|
440
|
1393 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float);
|
428
|
1394 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000
|
|
1395
|
|
1396 Lisp_Object
|
|
1397 make_float (double float_value)
|
|
1398 {
|
440
|
1399 Lisp_Float *f;
|
|
1400
|
3017
|
1401 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (float, Lisp_Float, f, &lrecord_float);
|
440
|
1402
|
|
1403 /* Avoid dump-time `uninitialized memory read' purify warnings. */
|
|
1404 if (sizeof (struct lrecord_header) + sizeof (double) != sizeof (*f))
|
3017
|
1405 zero_lrecord (f);
|
|
1406
|
428
|
1407 float_data (f) = float_value;
|
793
|
1408 return wrap_float (f);
|
428
|
1409 }
|
|
1410
|
|
1411
|
|
1412 /************************************************************************/
|
1983
|
1413 /* Enhanced number allocation */
|
|
1414 /************************************************************************/
|
|
1415
|
|
1416 /*** Bignum ***/
|
|
1417 #ifdef HAVE_BIGNUM
|
|
1418 DECLARE_FIXED_TYPE_ALLOC (bignum, Lisp_Bignum);
|
|
1419 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bignum 250
|
|
1420
|
|
1421 /* WARNING: This function returns a bignum even if its argument fits into a
|
|
1422 fixnum. See Fcanonicalize_number(). */
|
|
1423 Lisp_Object
|
|
1424 make_bignum (long bignum_value)
|
|
1425 {
|
|
1426 Lisp_Bignum *b;
|
|
1427
|
3017
|
1428 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bignum, Lisp_Bignum, b, &lrecord_bignum);
|
1983
|
1429 bignum_init (bignum_data (b));
|
|
1430 bignum_set_long (bignum_data (b), bignum_value);
|
|
1431 return wrap_bignum (b);
|
|
1432 }
|
|
1433
|
|
1434 /* WARNING: This function returns a bignum even if its argument fits into a
|
|
1435 fixnum. See Fcanonicalize_number(). */
|
|
1436 Lisp_Object
|
|
1437 make_bignum_bg (bignum bg)
|
|
1438 {
|
|
1439 Lisp_Bignum *b;
|
|
1440
|
3017
|
1441 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bignum, Lisp_Bignum, b, &lrecord_bignum);
|
1983
|
1442 bignum_init (bignum_data (b));
|
|
1443 bignum_set (bignum_data (b), bg);
|
|
1444 return wrap_bignum (b);
|
|
1445 }
|
|
1446 #endif /* HAVE_BIGNUM */
|
|
1447
|
|
1448 /*** Ratio ***/
|
|
1449 #ifdef HAVE_RATIO
|
|
1450 DECLARE_FIXED_TYPE_ALLOC (ratio, Lisp_Ratio);
|
|
1451 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_ratio 250
|
|
1452
|
|
1453 Lisp_Object
|
|
1454 make_ratio (long numerator, unsigned long denominator)
|
|
1455 {
|
|
1456 Lisp_Ratio *r;
|
|
1457
|
3017
|
1458 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (ratio, Lisp_Ratio, r, &lrecord_ratio);
|
1983
|
1459 ratio_init (ratio_data (r));
|
|
1460 ratio_set_long_ulong (ratio_data (r), numerator, denominator);
|
|
1461 ratio_canonicalize (ratio_data (r));
|
|
1462 return wrap_ratio (r);
|
|
1463 }
|
|
1464
|
|
1465 Lisp_Object
|
|
1466 make_ratio_bg (bignum numerator, bignum denominator)
|
|
1467 {
|
|
1468 Lisp_Ratio *r;
|
|
1469
|
3017
|
1470 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (ratio, Lisp_Ratio, r, &lrecord_ratio);
|
1983
|
1471 ratio_init (ratio_data (r));
|
|
1472 ratio_set_bignum_bignum (ratio_data (r), numerator, denominator);
|
|
1473 ratio_canonicalize (ratio_data (r));
|
|
1474 return wrap_ratio (r);
|
|
1475 }
|
|
1476
|
|
1477 Lisp_Object
|
|
1478 make_ratio_rt (ratio rat)
|
|
1479 {
|
|
1480 Lisp_Ratio *r;
|
|
1481
|
3017
|
1482 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (ratio, Lisp_Ratio, r, &lrecord_ratio);
|
1983
|
1483 ratio_init (ratio_data (r));
|
|
1484 ratio_set (ratio_data (r), rat);
|
|
1485 return wrap_ratio (r);
|
|
1486 }
|
|
1487 #endif /* HAVE_RATIO */
|
|
1488
|
|
1489 /*** Bigfloat ***/
|
|
1490 #ifdef HAVE_BIGFLOAT
|
|
1491 DECLARE_FIXED_TYPE_ALLOC (bigfloat, Lisp_Bigfloat);
|
|
1492 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigfloat 250
|
|
1493
|
|
1494 /* This function creates a bigfloat with the default precision if the
|
|
1495 PRECISION argument is zero. */
|
|
1496 Lisp_Object
|
|
1497 make_bigfloat (double float_value, unsigned long precision)
|
|
1498 {
|
|
1499 Lisp_Bigfloat *f;
|
|
1500
|
3017
|
1501 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat);
|
1983
|
1502 if (precision == 0UL)
|
|
1503 bigfloat_init (bigfloat_data (f));
|
|
1504 else
|
|
1505 bigfloat_init_prec (bigfloat_data (f), precision);
|
|
1506 bigfloat_set_double (bigfloat_data (f), float_value);
|
|
1507 return wrap_bigfloat (f);
|
|
1508 }
|
|
1509
|
|
1510 /* This function creates a bigfloat with the precision of its argument */
|
|
1511 Lisp_Object
|
|
1512 make_bigfloat_bf (bigfloat float_value)
|
|
1513 {
|
|
1514 Lisp_Bigfloat *f;
|
|
1515
|
3017
|
1516 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat);
|
1983
|
1517 bigfloat_init_prec (bigfloat_data (f), bigfloat_get_prec (float_value));
|
|
1518 bigfloat_set (bigfloat_data (f), float_value);
|
|
1519 return wrap_bigfloat (f);
|
|
1520 }
|
|
1521 #endif /* HAVE_BIGFLOAT */
|
|
1522
|
|
1523 /************************************************************************/
|
428
|
1524 /* Vector allocation */
|
|
1525 /************************************************************************/
|
|
1526
|
|
1527 static Lisp_Object
|
|
1528 mark_vector (Lisp_Object obj)
|
|
1529 {
|
|
1530 Lisp_Vector *ptr = XVECTOR (obj);
|
|
1531 int len = vector_length (ptr);
|
|
1532 int i;
|
|
1533
|
|
1534 for (i = 0; i < len - 1; i++)
|
|
1535 mark_object (ptr->contents[i]);
|
|
1536 return (len > 0) ? ptr->contents[len - 1] : Qnil;
|
|
1537 }
|
|
1538
|
665
|
1539 static Bytecount
|
442
|
1540 size_vector (const void *lheader)
|
428
|
1541 {
|
456
|
1542 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, contents,
|
442
|
1543 ((Lisp_Vector *) lheader)->size);
|
428
|
1544 }
|
|
1545
|
|
1546 static int
|
|
1547 vector_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
1548 {
|
|
1549 int len = XVECTOR_LENGTH (obj1);
|
|
1550 if (len != XVECTOR_LENGTH (obj2))
|
|
1551 return 0;
|
|
1552
|
|
1553 {
|
|
1554 Lisp_Object *ptr1 = XVECTOR_DATA (obj1);
|
|
1555 Lisp_Object *ptr2 = XVECTOR_DATA (obj2);
|
|
1556 while (len--)
|
|
1557 if (!internal_equal (*ptr1++, *ptr2++, depth + 1))
|
|
1558 return 0;
|
|
1559 }
|
|
1560 return 1;
|
|
1561 }
|
|
1562
|
665
|
1563 static Hashcode
|
442
|
1564 vector_hash (Lisp_Object obj, int depth)
|
|
1565 {
|
|
1566 return HASH2 (XVECTOR_LENGTH (obj),
|
|
1567 internal_array_hash (XVECTOR_DATA (obj),
|
|
1568 XVECTOR_LENGTH (obj),
|
|
1569 depth + 1));
|
|
1570 }
|
|
1571
|
1204
|
1572 static const struct memory_description vector_description[] = {
|
440
|
1573 { XD_LONG, offsetof (Lisp_Vector, size) },
|
|
1574 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Vector, contents), XD_INDIRECT(0, 0) },
|
428
|
1575 { XD_END }
|
|
1576 };
|
|
1577
|
1204
|
1578 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("vector", vector,
|
|
1579 1, /*dumpable-flag*/
|
|
1580 mark_vector, print_vector, 0,
|
|
1581 vector_equal,
|
|
1582 vector_hash,
|
|
1583 vector_description,
|
|
1584 size_vector, Lisp_Vector);
|
428
|
1585 /* #### should allocate `small' vectors from a frob-block */
|
|
1586 static Lisp_Vector *
|
665
|
1587 make_vector_internal (Elemcount sizei)
|
428
|
1588 {
|
1204
|
1589 /* no `next' field; we use lcrecords */
|
665
|
1590 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object,
|
1204
|
1591 contents, sizei);
|
|
1592 Lisp_Vector *p =
|
3017
|
1593 (Lisp_Vector *) BASIC_ALLOC_LCRECORD (sizem, &lrecord_vector);
|
428
|
1594
|
|
1595 p->size = sizei;
|
|
1596 return p;
|
|
1597 }
|
|
1598
|
|
1599 Lisp_Object
|
665
|
1600 make_vector (Elemcount length, Lisp_Object object)
|
428
|
1601 {
|
|
1602 Lisp_Vector *vecp = make_vector_internal (length);
|
|
1603 Lisp_Object *p = vector_data (vecp);
|
|
1604
|
|
1605 while (length--)
|
444
|
1606 *p++ = object;
|
428
|
1607
|
793
|
1608 return wrap_vector (vecp);
|
428
|
1609 }
|
|
1610
|
|
1611 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /*
|
444
|
1612 Return a new vector of length LENGTH, with each element being OBJECT.
|
428
|
1613 See also the function `vector'.
|
|
1614 */
|
444
|
1615 (length, object))
|
428
|
1616 {
|
|
1617 CONCHECK_NATNUM (length);
|
444
|
1618 return make_vector (XINT (length), object);
|
428
|
1619 }
|
|
1620
|
|
1621 DEFUN ("vector", Fvector, 0, MANY, 0, /*
|
|
1622 Return a newly created vector with specified arguments as elements.
|
|
1623 Any number of arguments, even zero arguments, are allowed.
|
|
1624 */
|
|
1625 (int nargs, Lisp_Object *args))
|
|
1626 {
|
|
1627 Lisp_Vector *vecp = make_vector_internal (nargs);
|
|
1628 Lisp_Object *p = vector_data (vecp);
|
|
1629
|
|
1630 while (nargs--)
|
|
1631 *p++ = *args++;
|
|
1632
|
793
|
1633 return wrap_vector (vecp);
|
428
|
1634 }
|
|
1635
|
|
1636 Lisp_Object
|
|
1637 vector1 (Lisp_Object obj0)
|
|
1638 {
|
|
1639 return Fvector (1, &obj0);
|
|
1640 }
|
|
1641
|
|
1642 Lisp_Object
|
|
1643 vector2 (Lisp_Object obj0, Lisp_Object obj1)
|
|
1644 {
|
|
1645 Lisp_Object args[2];
|
|
1646 args[0] = obj0;
|
|
1647 args[1] = obj1;
|
|
1648 return Fvector (2, args);
|
|
1649 }
|
|
1650
|
|
1651 Lisp_Object
|
|
1652 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2)
|
|
1653 {
|
|
1654 Lisp_Object args[3];
|
|
1655 args[0] = obj0;
|
|
1656 args[1] = obj1;
|
|
1657 args[2] = obj2;
|
|
1658 return Fvector (3, args);
|
|
1659 }
|
|
1660
|
|
1661 #if 0 /* currently unused */
|
|
1662
|
|
1663 Lisp_Object
|
|
1664 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1665 Lisp_Object obj3)
|
|
1666 {
|
|
1667 Lisp_Object args[4];
|
|
1668 args[0] = obj0;
|
|
1669 args[1] = obj1;
|
|
1670 args[2] = obj2;
|
|
1671 args[3] = obj3;
|
|
1672 return Fvector (4, args);
|
|
1673 }
|
|
1674
|
|
1675 Lisp_Object
|
|
1676 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1677 Lisp_Object obj3, Lisp_Object obj4)
|
|
1678 {
|
|
1679 Lisp_Object args[5];
|
|
1680 args[0] = obj0;
|
|
1681 args[1] = obj1;
|
|
1682 args[2] = obj2;
|
|
1683 args[3] = obj3;
|
|
1684 args[4] = obj4;
|
|
1685 return Fvector (5, args);
|
|
1686 }
|
|
1687
|
|
1688 Lisp_Object
|
|
1689 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1690 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5)
|
|
1691 {
|
|
1692 Lisp_Object args[6];
|
|
1693 args[0] = obj0;
|
|
1694 args[1] = obj1;
|
|
1695 args[2] = obj2;
|
|
1696 args[3] = obj3;
|
|
1697 args[4] = obj4;
|
|
1698 args[5] = obj5;
|
|
1699 return Fvector (6, args);
|
|
1700 }
|
|
1701
|
|
1702 Lisp_Object
|
|
1703 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1704 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
|
|
1705 Lisp_Object obj6)
|
|
1706 {
|
|
1707 Lisp_Object args[7];
|
|
1708 args[0] = obj0;
|
|
1709 args[1] = obj1;
|
|
1710 args[2] = obj2;
|
|
1711 args[3] = obj3;
|
|
1712 args[4] = obj4;
|
|
1713 args[5] = obj5;
|
|
1714 args[6] = obj6;
|
|
1715 return Fvector (7, args);
|
|
1716 }
|
|
1717
|
|
1718 Lisp_Object
|
|
1719 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2,
|
|
1720 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5,
|
|
1721 Lisp_Object obj6, Lisp_Object obj7)
|
|
1722 {
|
|
1723 Lisp_Object args[8];
|
|
1724 args[0] = obj0;
|
|
1725 args[1] = obj1;
|
|
1726 args[2] = obj2;
|
|
1727 args[3] = obj3;
|
|
1728 args[4] = obj4;
|
|
1729 args[5] = obj5;
|
|
1730 args[6] = obj6;
|
|
1731 args[7] = obj7;
|
|
1732 return Fvector (8, args);
|
|
1733 }
|
|
1734 #endif /* unused */
|
|
1735
|
|
1736 /************************************************************************/
|
|
1737 /* Bit Vector allocation */
|
|
1738 /************************************************************************/
|
|
1739
|
|
1740 /* #### should allocate `small' bit vectors from a frob-block */
|
440
|
1741 static Lisp_Bit_Vector *
|
665
|
1742 make_bit_vector_internal (Elemcount sizei)
|
428
|
1743 {
|
1204
|
1744 /* no `next' field; we use lcrecords */
|
665
|
1745 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (sizei);
|
|
1746 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector,
|
1204
|
1747 unsigned long,
|
|
1748 bits, num_longs);
|
|
1749 Lisp_Bit_Vector *p = (Lisp_Bit_Vector *)
|
3017
|
1750 BASIC_ALLOC_LCRECORD (sizem, &lrecord_bit_vector);
|
428
|
1751
|
|
1752 bit_vector_length (p) = sizei;
|
|
1753 return p;
|
|
1754 }
|
|
1755
|
|
1756 Lisp_Object
|
665
|
1757 make_bit_vector (Elemcount length, Lisp_Object bit)
|
428
|
1758 {
|
440
|
1759 Lisp_Bit_Vector *p = make_bit_vector_internal (length);
|
665
|
1760 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (length);
|
428
|
1761
|
444
|
1762 CHECK_BIT (bit);
|
|
1763
|
|
1764 if (ZEROP (bit))
|
428
|
1765 memset (p->bits, 0, num_longs * sizeof (long));
|
|
1766 else
|
|
1767 {
|
665
|
1768 Elemcount bits_in_last = length & (LONGBITS_POWER_OF_2 - 1);
|
428
|
1769 memset (p->bits, ~0, num_longs * sizeof (long));
|
|
1770 /* But we have to make sure that the unused bits in the
|
|
1771 last long are 0, so that equal/hash is easy. */
|
|
1772 if (bits_in_last)
|
|
1773 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1;
|
|
1774 }
|
|
1775
|
793
|
1776 return wrap_bit_vector (p);
|
428
|
1777 }
|
|
1778
|
|
1779 Lisp_Object
|
665
|
1780 make_bit_vector_from_byte_vector (unsigned char *bytevec, Elemcount length)
|
428
|
1781 {
|
665
|
1782 Elemcount i;
|
428
|
1783 Lisp_Bit_Vector *p = make_bit_vector_internal (length);
|
|
1784
|
|
1785 for (i = 0; i < length; i++)
|
|
1786 set_bit_vector_bit (p, i, bytevec[i]);
|
|
1787
|
793
|
1788 return wrap_bit_vector (p);
|
428
|
1789 }
|
|
1790
|
|
1791 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /*
|
444
|
1792 Return a new bit vector of length LENGTH. with each bit set to BIT.
|
|
1793 BIT must be one of the integers 0 or 1. See also the function `bit-vector'.
|
428
|
1794 */
|
444
|
1795 (length, bit))
|
428
|
1796 {
|
|
1797 CONCHECK_NATNUM (length);
|
|
1798
|
444
|
1799 return make_bit_vector (XINT (length), bit);
|
428
|
1800 }
|
|
1801
|
|
1802 DEFUN ("bit-vector", Fbit_vector, 0, MANY, 0, /*
|
|
1803 Return a newly created bit vector with specified arguments as elements.
|
|
1804 Any number of arguments, even zero arguments, are allowed.
|
444
|
1805 Each argument must be one of the integers 0 or 1.
|
428
|
1806 */
|
|
1807 (int nargs, Lisp_Object *args))
|
|
1808 {
|
|
1809 int i;
|
|
1810 Lisp_Bit_Vector *p = make_bit_vector_internal (nargs);
|
|
1811
|
|
1812 for (i = 0; i < nargs; i++)
|
|
1813 {
|
|
1814 CHECK_BIT (args[i]);
|
|
1815 set_bit_vector_bit (p, i, !ZEROP (args[i]));
|
|
1816 }
|
|
1817
|
793
|
1818 return wrap_bit_vector (p);
|
428
|
1819 }
|
|
1820
|
|
1821
|
|
1822 /************************************************************************/
|
|
1823 /* Compiled-function allocation */
|
|
1824 /************************************************************************/
|
|
1825
|
|
1826 DECLARE_FIXED_TYPE_ALLOC (compiled_function, Lisp_Compiled_Function);
|
|
1827 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000
|
|
1828
|
|
1829 static Lisp_Object
|
|
1830 make_compiled_function (void)
|
|
1831 {
|
|
1832 Lisp_Compiled_Function *f;
|
|
1833
|
3017
|
1834 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (compiled_function, Lisp_Compiled_Function,
|
|
1835 f, &lrecord_compiled_function);
|
428
|
1836
|
|
1837 f->stack_depth = 0;
|
|
1838 f->specpdl_depth = 0;
|
|
1839 f->flags.documentationp = 0;
|
|
1840 f->flags.interactivep = 0;
|
|
1841 f->flags.domainp = 0; /* I18N3 */
|
|
1842 f->instructions = Qzero;
|
|
1843 f->constants = Qzero;
|
|
1844 f->arglist = Qnil;
|
3092
|
1845 #ifdef NEW_GC
|
|
1846 f->arguments = Qnil;
|
|
1847 #else /* not NEW_GC */
|
1739
|
1848 f->args = NULL;
|
3092
|
1849 #endif /* not NEW_GC */
|
1739
|
1850 f->max_args = f->min_args = f->args_in_array = 0;
|
428
|
1851 f->doc_and_interactive = Qnil;
|
|
1852 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1853 f->annotated = Qnil;
|
|
1854 #endif
|
793
|
1855 return wrap_compiled_function (f);
|
428
|
1856 }
|
|
1857
|
|
1858 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /*
|
|
1859 Return a new compiled-function object.
|
|
1860 Usage: (arglist instructions constants stack-depth
|
|
1861 &optional doc-string interactive)
|
|
1862 Note that, unlike all other emacs-lisp functions, calling this with five
|
|
1863 arguments is NOT the same as calling it with six arguments, the last of
|
|
1864 which is nil. If the INTERACTIVE arg is specified as nil, then that means
|
|
1865 that this function was defined with `(interactive)'. If the arg is not
|
|
1866 specified, then that means the function is not interactive.
|
|
1867 This is terrible behavior which is retained for compatibility with old
|
|
1868 `.elc' files which expect these semantics.
|
|
1869 */
|
|
1870 (int nargs, Lisp_Object *args))
|
|
1871 {
|
|
1872 /* In a non-insane world this function would have this arglist...
|
|
1873 (arglist instructions constants stack_depth &optional doc_string interactive)
|
|
1874 */
|
|
1875 Lisp_Object fun = make_compiled_function ();
|
|
1876 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun);
|
|
1877
|
|
1878 Lisp_Object arglist = args[0];
|
|
1879 Lisp_Object instructions = args[1];
|
|
1880 Lisp_Object constants = args[2];
|
|
1881 Lisp_Object stack_depth = args[3];
|
|
1882 Lisp_Object doc_string = (nargs > 4) ? args[4] : Qnil;
|
|
1883 Lisp_Object interactive = (nargs > 5) ? args[5] : Qunbound;
|
|
1884
|
|
1885 if (nargs < 4 || nargs > 6)
|
|
1886 return Fsignal (Qwrong_number_of_arguments,
|
|
1887 list2 (intern ("make-byte-code"), make_int (nargs)));
|
|
1888
|
|
1889 /* Check for valid formal parameter list now, to allow us to use
|
|
1890 SPECBIND_FAST_UNSAFE() later in funcall_compiled_function(). */
|
|
1891 {
|
814
|
1892 EXTERNAL_LIST_LOOP_2 (symbol, arglist)
|
428
|
1893 {
|
|
1894 CHECK_SYMBOL (symbol);
|
|
1895 if (EQ (symbol, Qt) ||
|
|
1896 EQ (symbol, Qnil) ||
|
|
1897 SYMBOL_IS_KEYWORD (symbol))
|
563
|
1898 invalid_constant_2
|
428
|
1899 ("Invalid constant symbol in formal parameter list",
|
|
1900 symbol, arglist);
|
|
1901 }
|
|
1902 }
|
|
1903 f->arglist = arglist;
|
|
1904
|
|
1905 /* `instructions' is a string or a cons (string . int) for a
|
|
1906 lazy-loaded function. */
|
|
1907 if (CONSP (instructions))
|
|
1908 {
|
|
1909 CHECK_STRING (XCAR (instructions));
|
|
1910 CHECK_INT (XCDR (instructions));
|
|
1911 }
|
|
1912 else
|
|
1913 {
|
|
1914 CHECK_STRING (instructions);
|
|
1915 }
|
|
1916 f->instructions = instructions;
|
|
1917
|
|
1918 if (!NILP (constants))
|
|
1919 CHECK_VECTOR (constants);
|
|
1920 f->constants = constants;
|
|
1921
|
|
1922 CHECK_NATNUM (stack_depth);
|
442
|
1923 f->stack_depth = (unsigned short) XINT (stack_depth);
|
428
|
1924
|
|
1925 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1926 if (!NILP (Vcurrent_compiled_function_annotation))
|
|
1927 f->annotated = Fcopy (Vcurrent_compiled_function_annotation);
|
|
1928 else if (!NILP (Vload_file_name_internal_the_purecopy))
|
|
1929 f->annotated = Vload_file_name_internal_the_purecopy;
|
|
1930 else if (!NILP (Vload_file_name_internal))
|
|
1931 {
|
|
1932 struct gcpro gcpro1;
|
|
1933 GCPRO1 (fun); /* don't let fun get reaped */
|
|
1934 Vload_file_name_internal_the_purecopy =
|
|
1935 Ffile_name_nondirectory (Vload_file_name_internal);
|
|
1936 f->annotated = Vload_file_name_internal_the_purecopy;
|
|
1937 UNGCPRO;
|
|
1938 }
|
|
1939 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
|
|
1940
|
|
1941 /* doc_string may be nil, string, int, or a cons (string . int).
|
|
1942 interactive may be list or string (or unbound). */
|
|
1943 f->doc_and_interactive = Qunbound;
|
|
1944 #ifdef I18N3
|
|
1945 if ((f->flags.domainp = !NILP (Vfile_domain)) != 0)
|
|
1946 f->doc_and_interactive = Vfile_domain;
|
|
1947 #endif
|
|
1948 if ((f->flags.interactivep = !UNBOUNDP (interactive)) != 0)
|
|
1949 {
|
|
1950 f->doc_and_interactive
|
|
1951 = (UNBOUNDP (f->doc_and_interactive) ? interactive :
|
|
1952 Fcons (interactive, f->doc_and_interactive));
|
|
1953 }
|
|
1954 if ((f->flags.documentationp = !NILP (doc_string)) != 0)
|
|
1955 {
|
|
1956 f->doc_and_interactive
|
|
1957 = (UNBOUNDP (f->doc_and_interactive) ? doc_string :
|
|
1958 Fcons (doc_string, f->doc_and_interactive));
|
|
1959 }
|
|
1960 if (UNBOUNDP (f->doc_and_interactive))
|
|
1961 f->doc_and_interactive = Qnil;
|
|
1962
|
|
1963 return fun;
|
|
1964 }
|
|
1965
|
|
1966
|
|
1967 /************************************************************************/
|
|
1968 /* Symbol allocation */
|
|
1969 /************************************************************************/
|
|
1970
|
440
|
1971 DECLARE_FIXED_TYPE_ALLOC (symbol, Lisp_Symbol);
|
428
|
1972 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000
|
|
1973
|
|
1974 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /*
|
|
1975 Return a newly allocated uninterned symbol whose name is NAME.
|
|
1976 Its value and function definition are void, and its property list is nil.
|
|
1977 */
|
|
1978 (name))
|
|
1979 {
|
440
|
1980 Lisp_Symbol *p;
|
428
|
1981
|
|
1982 CHECK_STRING (name);
|
|
1983
|
3017
|
1984 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (symbol, Lisp_Symbol, p, &lrecord_symbol);
|
793
|
1985 p->name = name;
|
428
|
1986 p->plist = Qnil;
|
|
1987 p->value = Qunbound;
|
|
1988 p->function = Qunbound;
|
|
1989 symbol_next (p) = 0;
|
793
|
1990 return wrap_symbol (p);
|
428
|
1991 }
|
|
1992
|
|
1993
|
|
1994 /************************************************************************/
|
|
1995 /* Extent allocation */
|
|
1996 /************************************************************************/
|
|
1997
|
|
1998 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent);
|
|
1999 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000
|
|
2000
|
|
2001 struct extent *
|
|
2002 allocate_extent (void)
|
|
2003 {
|
|
2004 struct extent *e;
|
|
2005
|
3017
|
2006 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (extent, struct extent, e, &lrecord_extent);
|
428
|
2007 extent_object (e) = Qnil;
|
|
2008 set_extent_start (e, -1);
|
|
2009 set_extent_end (e, -1);
|
|
2010 e->plist = Qnil;
|
|
2011
|
|
2012 xzero (e->flags);
|
|
2013
|
|
2014 extent_face (e) = Qnil;
|
|
2015 e->flags.end_open = 1; /* default is for endpoints to behave like markers */
|
|
2016 e->flags.detachable = 1;
|
|
2017
|
|
2018 return e;
|
|
2019 }
|
|
2020
|
|
2021
|
|
2022 /************************************************************************/
|
|
2023 /* Event allocation */
|
|
2024 /************************************************************************/
|
|
2025
|
440
|
2026 DECLARE_FIXED_TYPE_ALLOC (event, Lisp_Event);
|
428
|
2027 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000
|
|
2028
|
|
2029 Lisp_Object
|
|
2030 allocate_event (void)
|
|
2031 {
|
440
|
2032 Lisp_Event *e;
|
|
2033
|
3017
|
2034 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (event, Lisp_Event, e, &lrecord_event);
|
428
|
2035
|
793
|
2036 return wrap_event (e);
|
428
|
2037 }
|
|
2038
|
1204
|
2039 #ifdef EVENT_DATA_AS_OBJECTS
|
934
|
2040 DECLARE_FIXED_TYPE_ALLOC (key_data, Lisp_Key_Data);
|
|
2041 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_key_data 1000
|
|
2042
|
|
2043 Lisp_Object
|
1204
|
2044 make_key_data (void)
|
934
|
2045 {
|
|
2046 Lisp_Key_Data *d;
|
|
2047
|
3017
|
2048 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (key_data, Lisp_Key_Data, d,
|
|
2049 &lrecord_key_data);
|
|
2050 zero_lrecord (d);
|
1204
|
2051 d->keysym = Qnil;
|
|
2052
|
|
2053 return wrap_key_data (d);
|
934
|
2054 }
|
|
2055
|
|
2056 DECLARE_FIXED_TYPE_ALLOC (button_data, Lisp_Button_Data);
|
|
2057 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_button_data 1000
|
|
2058
|
|
2059 Lisp_Object
|
1204
|
2060 make_button_data (void)
|
934
|
2061 {
|
|
2062 Lisp_Button_Data *d;
|
|
2063
|
3017
|
2064 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (button_data, Lisp_Button_Data, d, &lrecord_button_data);
|
|
2065 zero_lrecord (d);
|
1204
|
2066 return wrap_button_data (d);
|
934
|
2067 }
|
|
2068
|
|
2069 DECLARE_FIXED_TYPE_ALLOC (motion_data, Lisp_Motion_Data);
|
|
2070 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_motion_data 1000
|
|
2071
|
|
2072 Lisp_Object
|
1204
|
2073 make_motion_data (void)
|
934
|
2074 {
|
|
2075 Lisp_Motion_Data *d;
|
|
2076
|
3017
|
2077 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (motion_data, Lisp_Motion_Data, d, &lrecord_motion_data);
|
|
2078 zero_lrecord (d);
|
934
|
2079
|
1204
|
2080 return wrap_motion_data (d);
|
934
|
2081 }
|
|
2082
|
|
2083 DECLARE_FIXED_TYPE_ALLOC (process_data, Lisp_Process_Data);
|
|
2084 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_process_data 1000
|
|
2085
|
|
2086 Lisp_Object
|
1204
|
2087 make_process_data (void)
|
934
|
2088 {
|
|
2089 Lisp_Process_Data *d;
|
|
2090
|
3017
|
2091 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (process_data, Lisp_Process_Data, d, &lrecord_process_data);
|
|
2092 zero_lrecord (d);
|
1204
|
2093 d->process = Qnil;
|
|
2094
|
|
2095 return wrap_process_data (d);
|
934
|
2096 }
|
|
2097
|
|
2098 DECLARE_FIXED_TYPE_ALLOC (timeout_data, Lisp_Timeout_Data);
|
|
2099 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_timeout_data 1000
|
|
2100
|
|
2101 Lisp_Object
|
1204
|
2102 make_timeout_data (void)
|
934
|
2103 {
|
|
2104 Lisp_Timeout_Data *d;
|
|
2105
|
3017
|
2106 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (timeout_data, Lisp_Timeout_Data, d, &lrecord_timeout_data);
|
|
2107 zero_lrecord (d);
|
1204
|
2108 d->function = Qnil;
|
|
2109 d->object = Qnil;
|
|
2110
|
|
2111 return wrap_timeout_data (d);
|
934
|
2112 }
|
|
2113
|
|
2114 DECLARE_FIXED_TYPE_ALLOC (magic_data, Lisp_Magic_Data);
|
|
2115 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_data 1000
|
|
2116
|
|
2117 Lisp_Object
|
1204
|
2118 make_magic_data (void)
|
934
|
2119 {
|
|
2120 Lisp_Magic_Data *d;
|
|
2121
|
3017
|
2122 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (magic_data, Lisp_Magic_Data, d, &lrecord_magic_data);
|
|
2123 zero_lrecord (d);
|
934
|
2124
|
1204
|
2125 return wrap_magic_data (d);
|
934
|
2126 }
|
|
2127
|
|
2128 DECLARE_FIXED_TYPE_ALLOC (magic_eval_data, Lisp_Magic_Eval_Data);
|
|
2129 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_eval_data 1000
|
|
2130
|
|
2131 Lisp_Object
|
1204
|
2132 make_magic_eval_data (void)
|
934
|
2133 {
|
|
2134 Lisp_Magic_Eval_Data *d;
|
|
2135
|
3017
|
2136 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (magic_eval_data, Lisp_Magic_Eval_Data, d, &lrecord_magic_eval_data);
|
|
2137 zero_lrecord (d);
|
1204
|
2138 d->object = Qnil;
|
|
2139
|
|
2140 return wrap_magic_eval_data (d);
|
934
|
2141 }
|
|
2142
|
|
2143 DECLARE_FIXED_TYPE_ALLOC (eval_data, Lisp_Eval_Data);
|
|
2144 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_eval_data 1000
|
|
2145
|
|
2146 Lisp_Object
|
1204
|
2147 make_eval_data (void)
|
934
|
2148 {
|
|
2149 Lisp_Eval_Data *d;
|
|
2150
|
3017
|
2151 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (eval_data, Lisp_Eval_Data, d, &lrecord_eval_data);
|
|
2152 zero_lrecord (d);
|
1204
|
2153 d->function = Qnil;
|
|
2154 d->object = Qnil;
|
|
2155
|
|
2156 return wrap_eval_data (d);
|
934
|
2157 }
|
|
2158
|
|
2159 DECLARE_FIXED_TYPE_ALLOC (misc_user_data, Lisp_Misc_User_Data);
|
|
2160 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_misc_user_data 1000
|
|
2161
|
|
2162 Lisp_Object
|
1204
|
2163 make_misc_user_data (void)
|
934
|
2164 {
|
|
2165 Lisp_Misc_User_Data *d;
|
|
2166
|
3017
|
2167 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (misc_user_data, Lisp_Misc_User_Data, d, &lrecord_misc_user_data);
|
|
2168 zero_lrecord (d);
|
1204
|
2169 d->function = Qnil;
|
|
2170 d->object = Qnil;
|
|
2171
|
|
2172 return wrap_misc_user_data (d);
|
934
|
2173 }
|
1204
|
2174
|
|
2175 #endif /* EVENT_DATA_AS_OBJECTS */
|
428
|
2176
|
|
2177 /************************************************************************/
|
|
2178 /* Marker allocation */
|
|
2179 /************************************************************************/
|
|
2180
|
440
|
2181 DECLARE_FIXED_TYPE_ALLOC (marker, Lisp_Marker);
|
428
|
2182 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000
|
|
2183
|
|
2184 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /*
|
|
2185 Return a new marker which does not point at any place.
|
|
2186 */
|
|
2187 ())
|
|
2188 {
|
440
|
2189 Lisp_Marker *p;
|
|
2190
|
3017
|
2191 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (marker, Lisp_Marker, p, &lrecord_marker);
|
428
|
2192 p->buffer = 0;
|
665
|
2193 p->membpos = 0;
|
428
|
2194 marker_next (p) = 0;
|
|
2195 marker_prev (p) = 0;
|
|
2196 p->insertion_type = 0;
|
793
|
2197 return wrap_marker (p);
|
428
|
2198 }
|
|
2199
|
|
2200 Lisp_Object
|
|
2201 noseeum_make_marker (void)
|
|
2202 {
|
440
|
2203 Lisp_Marker *p;
|
|
2204
|
3017
|
2205 NOSEEUM_ALLOCATE_FIXED_TYPE_AND_SET_IMPL (marker, Lisp_Marker, p,
|
|
2206 &lrecord_marker);
|
428
|
2207 p->buffer = 0;
|
665
|
2208 p->membpos = 0;
|
428
|
2209 marker_next (p) = 0;
|
|
2210 marker_prev (p) = 0;
|
|
2211 p->insertion_type = 0;
|
793
|
2212 return wrap_marker (p);
|
428
|
2213 }
|
|
2214
|
|
2215
|
|
2216 /************************************************************************/
|
|
2217 /* String allocation */
|
|
2218 /************************************************************************/
|
|
2219
|
|
2220 /* The data for "short" strings generally resides inside of structs of type
|
|
2221 string_chars_block. The Lisp_String structure is allocated just like any
|
1204
|
2222 other basic lrecord, and these are freelisted when they get garbage
|
|
2223 collected. The data for short strings get compacted, but the data for
|
|
2224 large strings do not.
|
428
|
2225
|
|
2226 Previously Lisp_String structures were relocated, but this caused a lot
|
|
2227 of bus-errors because the C code didn't include enough GCPRO's for
|
|
2228 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so
|
|
2229 that the reference would get relocated).
|
|
2230
|
|
2231 This new method makes things somewhat bigger, but it is MUCH safer. */
|
|
2232
|
438
|
2233 DECLARE_FIXED_TYPE_ALLOC (string, Lisp_String);
|
428
|
2234 /* strings are used and freed quite often */
|
|
2235 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */
|
|
2236 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000
|
|
2237
|
|
2238 static Lisp_Object
|
|
2239 mark_string (Lisp_Object obj)
|
|
2240 {
|
793
|
2241 if (CONSP (XSTRING_PLIST (obj)) && EXTENT_INFOP (XCAR (XSTRING_PLIST (obj))))
|
|
2242 flush_cached_extent_info (XCAR (XSTRING_PLIST (obj)));
|
|
2243 return XSTRING_PLIST (obj);
|
428
|
2244 }
|
|
2245
|
|
2246 static int
|
2286
|
2247 string_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth))
|
428
|
2248 {
|
|
2249 Bytecount len;
|
|
2250 return (((len = XSTRING_LENGTH (obj1)) == XSTRING_LENGTH (obj2)) &&
|
|
2251 !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len));
|
|
2252 }
|
|
2253
|
1204
|
2254 static const struct memory_description string_description[] = {
|
3092
|
2255 #ifdef NEW_GC
|
|
2256 { XD_LISP_OBJECT, offsetof (Lisp_String, data_object) },
|
|
2257 #else /* not NEW_GC */
|
793
|
2258 { XD_BYTECOUNT, offsetof (Lisp_String, size_) },
|
|
2259 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data_), XD_INDIRECT(0, 1) },
|
3092
|
2260 #endif /* not NEW_GC */
|
440
|
2261 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) },
|
428
|
2262 { XD_END }
|
|
2263 };
|
|
2264
|
442
|
2265 /* We store the string's extent info as the first element of the string's
|
|
2266 property list; and the string's MODIFF as the first or second element
|
|
2267 of the string's property list (depending on whether the extent info
|
|
2268 is present), but only if the string has been modified. This is ugly
|
|
2269 but it reduces the memory allocated for the string in the vast
|
|
2270 majority of cases, where the string is never modified and has no
|
|
2271 extent info.
|
|
2272
|
|
2273 #### This means you can't use an int as a key in a string's plist. */
|
|
2274
|
|
2275 static Lisp_Object *
|
|
2276 string_plist_ptr (Lisp_Object string)
|
|
2277 {
|
793
|
2278 Lisp_Object *ptr = &XSTRING_PLIST (string);
|
442
|
2279
|
|
2280 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr)))
|
|
2281 ptr = &XCDR (*ptr);
|
|
2282 if (CONSP (*ptr) && INTP (XCAR (*ptr)))
|
|
2283 ptr = &XCDR (*ptr);
|
|
2284 return ptr;
|
|
2285 }
|
|
2286
|
|
2287 static Lisp_Object
|
|
2288 string_getprop (Lisp_Object string, Lisp_Object property)
|
|
2289 {
|
|
2290 return external_plist_get (string_plist_ptr (string), property, 0, ERROR_ME);
|
|
2291 }
|
|
2292
|
|
2293 static int
|
|
2294 string_putprop (Lisp_Object string, Lisp_Object property, Lisp_Object value)
|
|
2295 {
|
|
2296 external_plist_put (string_plist_ptr (string), property, value, 0, ERROR_ME);
|
|
2297 return 1;
|
|
2298 }
|
|
2299
|
|
2300 static int
|
|
2301 string_remprop (Lisp_Object string, Lisp_Object property)
|
|
2302 {
|
|
2303 return external_remprop (string_plist_ptr (string), property, 0, ERROR_ME);
|
|
2304 }
|
|
2305
|
|
2306 static Lisp_Object
|
|
2307 string_plist (Lisp_Object string)
|
|
2308 {
|
|
2309 return *string_plist_ptr (string);
|
|
2310 }
|
|
2311
|
3263
|
2312 #ifndef NEW_GC
|
442
|
2313 /* No `finalize', or `hash' methods.
|
|
2314 internal_hash() already knows how to hash strings and finalization
|
|
2315 is done with the ADDITIONAL_FREE_string macro, which is the
|
|
2316 standard way to do finalization when using
|
|
2317 SWEEP_FIXED_TYPE_BLOCK(). */
|
2720
|
2318
|
934
|
2319 DEFINE_BASIC_LRECORD_IMPLEMENTATION_WITH_PROPS ("string", string,
|
|
2320 1, /*dumpable-flag*/
|
|
2321 mark_string, print_string,
|
|
2322 0, string_equal, 0,
|
|
2323 string_description,
|
|
2324 string_getprop,
|
|
2325 string_putprop,
|
|
2326 string_remprop,
|
|
2327 string_plist,
|
|
2328 Lisp_String);
|
3263
|
2329 #endif /* not NEW_GC */
|
2720
|
2330
|
3092
|
2331 #ifdef NEW_GC
|
|
2332 #define STRING_FULLSIZE(size) \
|
|
2333 ALIGN_SIZE (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_String_Direct_Data, Lisp_Object, data, (size) + 1), sizeof (Lisp_Object *));
|
|
2334 #else /* not NEW_GC */
|
428
|
2335 /* String blocks contain this many useful bytes. */
|
|
2336 #define STRING_CHARS_BLOCK_SIZE \
|
814
|
2337 ((Bytecount) (8192 - MALLOC_OVERHEAD - \
|
|
2338 ((2 * sizeof (struct string_chars_block *)) \
|
|
2339 + sizeof (EMACS_INT))))
|
428
|
2340 /* Block header for small strings. */
|
|
2341 struct string_chars_block
|
|
2342 {
|
|
2343 EMACS_INT pos;
|
|
2344 struct string_chars_block *next;
|
|
2345 struct string_chars_block *prev;
|
|
2346 /* Contents of string_chars_block->string_chars are interleaved
|
|
2347 string_chars structures (see below) and the actual string data */
|
|
2348 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE];
|
|
2349 };
|
|
2350
|
|
2351 static struct string_chars_block *first_string_chars_block;
|
|
2352 static struct string_chars_block *current_string_chars_block;
|
|
2353
|
|
2354 /* If SIZE is the length of a string, this returns how many bytes
|
|
2355 * the string occupies in string_chars_block->string_chars
|
|
2356 * (including alignment padding).
|
|
2357 */
|
438
|
2358 #define STRING_FULLSIZE(size) \
|
826
|
2359 ALIGN_FOR_TYPE (((size) + 1 + sizeof (Lisp_String *)), Lisp_String *)
|
428
|
2360
|
|
2361 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE)
|
|
2362 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size)))
|
|
2363
|
454
|
2364 #define STRING_CHARS_FREE_P(ptr) ((ptr)->string == NULL)
|
|
2365 #define MARK_STRING_CHARS_AS_FREE(ptr) ((void) ((ptr)->string = NULL))
|
3092
|
2366 #endif /* not NEW_GC */
|
454
|
2367
|
3263
|
2368 #ifdef NEW_GC
|
3092
|
2369 DEFINE_LRECORD_IMPLEMENTATION_WITH_PROPS ("string", string,
|
|
2370 1, /*dumpable-flag*/
|
|
2371 mark_string, print_string,
|
|
2372 0,
|
|
2373 string_equal, 0,
|
|
2374 string_description,
|
|
2375 string_getprop,
|
|
2376 string_putprop,
|
|
2377 string_remprop,
|
|
2378 string_plist,
|
|
2379 Lisp_String);
|
|
2380
|
|
2381
|
|
2382 static const struct memory_description string_direct_data_description[] = {
|
|
2383 { XD_BYTECOUNT, offsetof (Lisp_String_Indirect_Data, size) },
|
|
2384 { XD_END }
|
|
2385 };
|
|
2386
|
|
2387 static Bytecount
|
|
2388 size_string_direct_data (const void *lheader)
|
|
2389 {
|
|
2390 return STRING_FULLSIZE (((Lisp_String_Direct_Data *) lheader)->size);
|
|
2391 }
|
|
2392
|
|
2393
|
|
2394 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("string-direct-data",
|
|
2395 string_direct_data,
|
|
2396 1, /*dumpable-flag*/
|
|
2397 0, 0, 0, 0, 0,
|
|
2398 string_direct_data_description,
|
|
2399 size_string_direct_data,
|
|
2400 Lisp_String_Direct_Data);
|
|
2401
|
|
2402
|
|
2403 static const struct memory_description string_indirect_data_description[] = {
|
|
2404 { XD_BYTECOUNT, offsetof (Lisp_String_Indirect_Data, size) },
|
|
2405 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String_Indirect_Data, data),
|
|
2406 XD_INDIRECT(0, 1) },
|
|
2407 { XD_END }
|
|
2408 };
|
|
2409
|
|
2410 DEFINE_LRECORD_IMPLEMENTATION ("string-indirect-data",
|
|
2411 string_indirect_data,
|
|
2412 1, /*dumpable-flag*/
|
|
2413 0, 0, 0, 0, 0,
|
|
2414 string_indirect_data_description,
|
|
2415 Lisp_String_Indirect_Data);
|
|
2416 #endif /* NEW_GC */
|
2720
|
2417
|
3092
|
2418 #ifndef NEW_GC
|
428
|
2419 struct string_chars
|
|
2420 {
|
438
|
2421 Lisp_String *string;
|
428
|
2422 unsigned char chars[1];
|
|
2423 };
|
|
2424
|
|
2425 struct unused_string_chars
|
|
2426 {
|
438
|
2427 Lisp_String *string;
|
428
|
2428 EMACS_INT fullsize;
|
|
2429 };
|
|
2430
|
|
2431 static void
|
|
2432 init_string_chars_alloc (void)
|
|
2433 {
|
|
2434 first_string_chars_block = xnew (struct string_chars_block);
|
|
2435 first_string_chars_block->prev = 0;
|
|
2436 first_string_chars_block->next = 0;
|
|
2437 first_string_chars_block->pos = 0;
|
|
2438 current_string_chars_block = first_string_chars_block;
|
|
2439 }
|
|
2440
|
1550
|
2441 static Ibyte *
|
|
2442 allocate_big_string_chars (Bytecount length)
|
|
2443 {
|
|
2444 Ibyte *p = xnew_array (Ibyte, length);
|
|
2445 INCREMENT_CONS_COUNTER (length, "string chars");
|
|
2446 return p;
|
|
2447 }
|
|
2448
|
428
|
2449 static struct string_chars *
|
793
|
2450 allocate_string_chars_struct (Lisp_Object string_it_goes_with,
|
814
|
2451 Bytecount fullsize)
|
428
|
2452 {
|
|
2453 struct string_chars *s_chars;
|
|
2454
|
438
|
2455 if (fullsize <=
|
|
2456 (countof (current_string_chars_block->string_chars)
|
|
2457 - current_string_chars_block->pos))
|
428
|
2458 {
|
|
2459 /* This string can fit in the current string chars block */
|
|
2460 s_chars = (struct string_chars *)
|
|
2461 (current_string_chars_block->string_chars
|
|
2462 + current_string_chars_block->pos);
|
|
2463 current_string_chars_block->pos += fullsize;
|
|
2464 }
|
|
2465 else
|
|
2466 {
|
|
2467 /* Make a new current string chars block */
|
|
2468 struct string_chars_block *new_scb = xnew (struct string_chars_block);
|
|
2469
|
|
2470 current_string_chars_block->next = new_scb;
|
|
2471 new_scb->prev = current_string_chars_block;
|
|
2472 new_scb->next = 0;
|
|
2473 current_string_chars_block = new_scb;
|
|
2474 new_scb->pos = fullsize;
|
|
2475 s_chars = (struct string_chars *)
|
|
2476 current_string_chars_block->string_chars;
|
|
2477 }
|
|
2478
|
793
|
2479 s_chars->string = XSTRING (string_it_goes_with);
|
428
|
2480
|
|
2481 INCREMENT_CONS_COUNTER (fullsize, "string chars");
|
|
2482
|
|
2483 return s_chars;
|
|
2484 }
|
3092
|
2485 #endif /* not NEW_GC */
|
428
|
2486
|
771
|
2487 #ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN
|
|
2488 void
|
|
2489 sledgehammer_check_ascii_begin (Lisp_Object str)
|
|
2490 {
|
|
2491 Bytecount i;
|
|
2492
|
|
2493 for (i = 0; i < XSTRING_LENGTH (str); i++)
|
|
2494 {
|
826
|
2495 if (!byte_ascii_p (string_byte (str, i)))
|
771
|
2496 break;
|
|
2497 }
|
|
2498
|
|
2499 assert (i == (Bytecount) XSTRING_ASCII_BEGIN (str) ||
|
|
2500 (i > MAX_STRING_ASCII_BEGIN &&
|
|
2501 (Bytecount) XSTRING_ASCII_BEGIN (str) ==
|
|
2502 (Bytecount) MAX_STRING_ASCII_BEGIN));
|
|
2503 }
|
|
2504 #endif
|
|
2505
|
|
2506 /* You do NOT want to be calling this! (And if you do, you must call
|
851
|
2507 XSET_STRING_ASCII_BEGIN() after modifying the string.) Use ALLOCA ()
|
771
|
2508 instead and then call make_string() like the rest of the world. */
|
|
2509
|
428
|
2510 Lisp_Object
|
|
2511 make_uninit_string (Bytecount length)
|
|
2512 {
|
438
|
2513 Lisp_String *s;
|
814
|
2514 Bytecount fullsize = STRING_FULLSIZE (length);
|
428
|
2515
|
438
|
2516 assert (length >= 0 && fullsize > 0);
|
428
|
2517
|
3263
|
2518 #ifdef NEW_GC
|
2720
|
2519 s = alloc_lrecord_type (Lisp_String, &lrecord_string);
|
3263
|
2520 #else /* not NEW_GC */
|
428
|
2521 /* Allocate the string header */
|
438
|
2522 ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
|
793
|
2523 xzero (*s);
|
771
|
2524 set_lheader_implementation (&s->u.lheader, &lrecord_string);
|
3263
|
2525 #endif /* not NEW_GC */
|
2720
|
2526
|
3063
|
2527 /* The above allocations set the UID field, which overlaps with the
|
|
2528 ascii-length field, to some non-zero value. We need to zero it. */
|
|
2529 XSET_STRING_ASCII_BEGIN (wrap_string (s), 0);
|
|
2530
|
3092
|
2531 #ifdef NEW_GC
|
3304
|
2532 set_lispstringp_direct (s);
|
3092
|
2533 STRING_DATA_OBJECT (s) =
|
|
2534 wrap_string_direct_data (alloc_lrecord (fullsize,
|
|
2535 &lrecord_string_direct_data));
|
|
2536 #else /* not NEW_GC */
|
826
|
2537 set_lispstringp_data (s, BIG_STRING_FULLSIZE_P (fullsize)
|
2720
|
2538 ? allocate_big_string_chars (length + 1)
|
|
2539 : allocate_string_chars_struct (wrap_string (s),
|
|
2540 fullsize)->chars);
|
3092
|
2541 #endif /* not NEW_GC */
|
438
|
2542
|
826
|
2543 set_lispstringp_length (s, length);
|
428
|
2544 s->plist = Qnil;
|
793
|
2545 set_string_byte (wrap_string (s), length, 0);
|
|
2546
|
|
2547 return wrap_string (s);
|
428
|
2548 }
|
|
2549
|
|
2550 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
2551 static void verify_string_chars_integrity (void);
|
|
2552 #endif
|
|
2553
|
|
2554 /* Resize the string S so that DELTA bytes can be inserted starting
|
|
2555 at POS. If DELTA < 0, it means deletion starting at POS. If
|
|
2556 POS < 0, resize the string but don't copy any characters. Use
|
|
2557 this if you're planning on completely overwriting the string.
|
|
2558 */
|
|
2559
|
|
2560 void
|
793
|
2561 resize_string (Lisp_Object s, Bytecount pos, Bytecount delta)
|
428
|
2562 {
|
3092
|
2563 #ifdef NEW_GC
|
|
2564 Bytecount newfullsize, len;
|
|
2565 #else /* not NEW_GC */
|
438
|
2566 Bytecount oldfullsize, newfullsize;
|
3092
|
2567 #endif /* not NEW_GC */
|
428
|
2568 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
2569 verify_string_chars_integrity ();
|
|
2570 #endif
|
800
|
2571 #ifdef ERROR_CHECK_TEXT
|
428
|
2572 if (pos >= 0)
|
|
2573 {
|
793
|
2574 assert (pos <= XSTRING_LENGTH (s));
|
428
|
2575 if (delta < 0)
|
793
|
2576 assert (pos + (-delta) <= XSTRING_LENGTH (s));
|
428
|
2577 }
|
|
2578 else
|
|
2579 {
|
|
2580 if (delta < 0)
|
793
|
2581 assert ((-delta) <= XSTRING_LENGTH (s));
|
428
|
2582 }
|
800
|
2583 #endif /* ERROR_CHECK_TEXT */
|
428
|
2584
|
|
2585 if (delta == 0)
|
|
2586 /* simplest case: no size change. */
|
|
2587 return;
|
438
|
2588
|
|
2589 if (pos >= 0 && delta < 0)
|
|
2590 /* If DELTA < 0, the functions below will delete the characters
|
|
2591 before POS. We want to delete characters *after* POS, however,
|
|
2592 so convert this to the appropriate form. */
|
|
2593 pos += -delta;
|
|
2594
|
3092
|
2595 #ifdef NEW_GC
|
|
2596 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta);
|
|
2597
|
|
2598 len = XSTRING_LENGTH (s) + 1 - pos;
|
|
2599
|
|
2600 if (delta < 0 && pos >= 0)
|
|
2601 memmove (XSTRING_DATA (s) + pos + delta,
|
|
2602 XSTRING_DATA (s) + pos, len);
|
|
2603
|
|
2604 XSTRING_DATA_OBJECT (s) =
|
|
2605 wrap_string_direct_data (mc_realloc (XPNTR (XSTRING_DATA_OBJECT (s)),
|
|
2606 newfullsize));
|
|
2607 if (delta > 0 && pos >= 0)
|
|
2608 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos,
|
|
2609 len);
|
|
2610
|
3263
|
2611 #else /* not NEW_GC */
|
793
|
2612 oldfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s));
|
|
2613 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta);
|
438
|
2614
|
|
2615 if (BIG_STRING_FULLSIZE_P (oldfullsize))
|
428
|
2616 {
|
438
|
2617 if (BIG_STRING_FULLSIZE_P (newfullsize))
|
428
|
2618 {
|
440
|
2619 /* Both strings are big. We can just realloc().
|
|
2620 But careful! If the string is shrinking, we have to
|
|
2621 memmove() _before_ realloc(), and if growing, we have to
|
|
2622 memmove() _after_ realloc() - otherwise the access is
|
|
2623 illegal, and we might crash. */
|
793
|
2624 Bytecount len = XSTRING_LENGTH (s) + 1 - pos;
|
440
|
2625
|
|
2626 if (delta < 0 && pos >= 0)
|
793
|
2627 memmove (XSTRING_DATA (s) + pos + delta,
|
|
2628 XSTRING_DATA (s) + pos, len);
|
|
2629 XSET_STRING_DATA
|
867
|
2630 (s, (Ibyte *) xrealloc (XSTRING_DATA (s),
|
793
|
2631 XSTRING_LENGTH (s) + delta + 1));
|
440
|
2632 if (delta > 0 && pos >= 0)
|
793
|
2633 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos,
|
|
2634 len);
|
1550
|
2635 /* Bump the cons counter.
|
|
2636 Conservative; Martin let the increment be delta. */
|
|
2637 INCREMENT_CONS_COUNTER (newfullsize, "string chars");
|
428
|
2638 }
|
438
|
2639 else /* String has been demoted from BIG_STRING. */
|
428
|
2640 {
|
867
|
2641 Ibyte *new_data =
|
438
|
2642 allocate_string_chars_struct (s, newfullsize)->chars;
|
867
|
2643 Ibyte *old_data = XSTRING_DATA (s);
|
438
|
2644
|
|
2645 if (pos >= 0)
|
|
2646 {
|
|
2647 memcpy (new_data, old_data, pos);
|
|
2648 memcpy (new_data + pos + delta, old_data + pos,
|
793
|
2649 XSTRING_LENGTH (s) + 1 - pos);
|
438
|
2650 }
|
793
|
2651 XSET_STRING_DATA (s, new_data);
|
1726
|
2652 xfree (old_data, Ibyte *);
|
438
|
2653 }
|
|
2654 }
|
|
2655 else /* old string is small */
|
|
2656 {
|
|
2657 if (oldfullsize == newfullsize)
|
|
2658 {
|
|
2659 /* special case; size change but the necessary
|
|
2660 allocation size won't change (up or down; code
|
|
2661 somewhere depends on there not being any unused
|
|
2662 allocation space, modulo any alignment
|
|
2663 constraints). */
|
428
|
2664 if (pos >= 0)
|
|
2665 {
|
867
|
2666 Ibyte *addroff = pos + XSTRING_DATA (s);
|
428
|
2667
|
|
2668 memmove (addroff + delta, addroff,
|
|
2669 /* +1 due to zero-termination. */
|
793
|
2670 XSTRING_LENGTH (s) + 1 - pos);
|
428
|
2671 }
|
|
2672 }
|
|
2673 else
|
|
2674 {
|
867
|
2675 Ibyte *old_data = XSTRING_DATA (s);
|
|
2676 Ibyte *new_data =
|
438
|
2677 BIG_STRING_FULLSIZE_P (newfullsize)
|
1550
|
2678 ? allocate_big_string_chars (XSTRING_LENGTH (s) + delta + 1)
|
438
|
2679 : allocate_string_chars_struct (s, newfullsize)->chars;
|
|
2680
|
428
|
2681 if (pos >= 0)
|
|
2682 {
|
438
|
2683 memcpy (new_data, old_data, pos);
|
|
2684 memcpy (new_data + pos + delta, old_data + pos,
|
793
|
2685 XSTRING_LENGTH (s) + 1 - pos);
|
428
|
2686 }
|
793
|
2687 XSET_STRING_DATA (s, new_data);
|
438
|
2688
|
|
2689 {
|
|
2690 /* We need to mark this chunk of the string_chars_block
|
|
2691 as unused so that compact_string_chars() doesn't
|
|
2692 freak. */
|
|
2693 struct string_chars *old_s_chars = (struct string_chars *)
|
|
2694 ((char *) old_data - offsetof (struct string_chars, chars));
|
|
2695 /* Sanity check to make sure we aren't hosed by strange
|
|
2696 alignment/padding. */
|
793
|
2697 assert (old_s_chars->string == XSTRING (s));
|
454
|
2698 MARK_STRING_CHARS_AS_FREE (old_s_chars);
|
438
|
2699 ((struct unused_string_chars *) old_s_chars)->fullsize =
|
|
2700 oldfullsize;
|
|
2701 }
|
428
|
2702 }
|
438
|
2703 }
|
3092
|
2704 #endif /* not NEW_GC */
|
438
|
2705
|
793
|
2706 XSET_STRING_LENGTH (s, XSTRING_LENGTH (s) + delta);
|
438
|
2707 /* If pos < 0, the string won't be zero-terminated.
|
|
2708 Terminate now just to make sure. */
|
793
|
2709 XSTRING_DATA (s)[XSTRING_LENGTH (s)] = '\0';
|
438
|
2710
|
|
2711 if (pos >= 0)
|
793
|
2712 /* We also have to adjust all of the extent indices after the
|
|
2713 place we did the change. We say "pos - 1" because
|
|
2714 adjust_extents() is exclusive of the starting position
|
|
2715 passed to it. */
|
|
2716 adjust_extents (s, pos - 1, XSTRING_LENGTH (s), delta);
|
428
|
2717
|
|
2718 #ifdef VERIFY_STRING_CHARS_INTEGRITY
|
|
2719 verify_string_chars_integrity ();
|
|
2720 #endif
|
|
2721 }
|
|
2722
|
|
2723 #ifdef MULE
|
|
2724
|
771
|
2725 /* WARNING: If you modify an existing string, you must call
|
|
2726 CHECK_LISP_WRITEABLE() before and bump_string_modiff() afterwards. */
|
428
|
2727 void
|
867
|
2728 set_string_char (Lisp_Object s, Charcount i, Ichar c)
|
428
|
2729 {
|
867
|
2730 Ibyte newstr[MAX_ICHAR_LEN];
|
771
|
2731 Bytecount bytoff = string_index_char_to_byte (s, i);
|
867
|
2732 Bytecount oldlen = itext_ichar_len (XSTRING_DATA (s) + bytoff);
|
|
2733 Bytecount newlen = set_itext_ichar (newstr, c);
|
428
|
2734
|
793
|
2735 sledgehammer_check_ascii_begin (s);
|
428
|
2736 if (oldlen != newlen)
|
|
2737 resize_string (s, bytoff, newlen - oldlen);
|
793
|
2738 /* Remember, XSTRING_DATA (s) might have changed so we can't cache it. */
|
|
2739 memcpy (XSTRING_DATA (s) + bytoff, newstr, newlen);
|
771
|
2740 if (oldlen != newlen)
|
|
2741 {
|
793
|
2742 if (newlen > 1 && i <= (Charcount) XSTRING_ASCII_BEGIN (s))
|
771
|
2743 /* Everything starting with the new char is no longer part of
|
|
2744 ascii_begin */
|
793
|
2745 XSET_STRING_ASCII_BEGIN (s, i);
|
|
2746 else if (newlen == 1 && i == (Charcount) XSTRING_ASCII_BEGIN (s))
|
771
|
2747 /* We've extended ascii_begin, and we have to figure out how much by */
|
|
2748 {
|
|
2749 Bytecount j;
|
814
|
2750 for (j = (Bytecount) i + 1; j < XSTRING_LENGTH (s); j++)
|
771
|
2751 {
|
826
|
2752 if (!byte_ascii_p (XSTRING_DATA (s)[j]))
|
771
|
2753 break;
|
|
2754 }
|
814
|
2755 XSET_STRING_ASCII_BEGIN (s, min (j, (Bytecount) MAX_STRING_ASCII_BEGIN));
|
771
|
2756 }
|
|
2757 }
|
793
|
2758 sledgehammer_check_ascii_begin (s);
|
428
|
2759 }
|
|
2760
|
|
2761 #endif /* MULE */
|
|
2762
|
|
2763 DEFUN ("make-string", Fmake_string, 2, 2, 0, /*
|
444
|
2764 Return a new string consisting of LENGTH copies of CHARACTER.
|
|
2765 LENGTH must be a non-negative integer.
|
428
|
2766 */
|
444
|
2767 (length, character))
|
428
|
2768 {
|
|
2769 CHECK_NATNUM (length);
|
444
|
2770 CHECK_CHAR_COERCE_INT (character);
|
428
|
2771 {
|
867
|
2772 Ibyte init_str[MAX_ICHAR_LEN];
|
|
2773 int len = set_itext_ichar (init_str, XCHAR (character));
|
428
|
2774 Lisp_Object val = make_uninit_string (len * XINT (length));
|
|
2775
|
|
2776 if (len == 1)
|
771
|
2777 {
|
|
2778 /* Optimize the single-byte case */
|
|
2779 memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val));
|
793
|
2780 XSET_STRING_ASCII_BEGIN (val, min (MAX_STRING_ASCII_BEGIN,
|
|
2781 len * XINT (length)));
|
771
|
2782 }
|
428
|
2783 else
|
|
2784 {
|
647
|
2785 EMACS_INT i;
|
867
|
2786 Ibyte *ptr = XSTRING_DATA (val);
|
428
|
2787
|
|
2788 for (i = XINT (length); i; i--)
|
|
2789 {
|
867
|
2790 Ibyte *init_ptr = init_str;
|
428
|
2791 switch (len)
|
|
2792 {
|
|
2793 case 4: *ptr++ = *init_ptr++;
|
|
2794 case 3: *ptr++ = *init_ptr++;
|
|
2795 case 2: *ptr++ = *init_ptr++;
|
|
2796 case 1: *ptr++ = *init_ptr++;
|
|
2797 }
|
|
2798 }
|
|
2799 }
|
771
|
2800 sledgehammer_check_ascii_begin (val);
|
428
|
2801 return val;
|
|
2802 }
|
|
2803 }
|
|
2804
|
|
2805 DEFUN ("string", Fstring, 0, MANY, 0, /*
|
|
2806 Concatenate all the argument characters and make the result a string.
|
|
2807 */
|
|
2808 (int nargs, Lisp_Object *args))
|
|
2809 {
|
2367
|
2810 Ibyte *storage = alloca_ibytes (nargs * MAX_ICHAR_LEN);
|
867
|
2811 Ibyte *p = storage;
|
428
|
2812
|
|
2813 for (; nargs; nargs--, args++)
|
|
2814 {
|
|
2815 Lisp_Object lisp_char = *args;
|
|
2816 CHECK_CHAR_COERCE_INT (lisp_char);
|
867
|
2817 p += set_itext_ichar (p, XCHAR (lisp_char));
|
428
|
2818 }
|
|
2819 return make_string (storage, p - storage);
|
|
2820 }
|
|
2821
|
771
|
2822 /* Initialize the ascii_begin member of a string to the correct value. */
|
|
2823
|
|
2824 void
|
|
2825 init_string_ascii_begin (Lisp_Object string)
|
|
2826 {
|
|
2827 #ifdef MULE
|
|
2828 int i;
|
|
2829 Bytecount length = XSTRING_LENGTH (string);
|
867
|
2830 Ibyte *contents = XSTRING_DATA (string);
|
771
|
2831
|
|
2832 for (i = 0; i < length; i++)
|
|
2833 {
|
826
|
2834 if (!byte_ascii_p (contents[i]))
|
771
|
2835 break;
|
|
2836 }
|
793
|
2837 XSET_STRING_ASCII_BEGIN (string, min (i, MAX_STRING_ASCII_BEGIN));
|
771
|
2838 #else
|
793
|
2839 XSET_STRING_ASCII_BEGIN (string, min (XSTRING_LENGTH (string),
|
|
2840 MAX_STRING_ASCII_BEGIN));
|
771
|
2841 #endif
|
|
2842 sledgehammer_check_ascii_begin (string);
|
|
2843 }
|
428
|
2844
|
|
2845 /* Take some raw memory, which MUST already be in internal format,
|
|
2846 and package it up into a Lisp string. */
|
|
2847 Lisp_Object
|
867
|
2848 make_string (const Ibyte *contents, Bytecount length)
|
428
|
2849 {
|
|
2850 Lisp_Object val;
|
|
2851
|
|
2852 /* Make sure we find out about bad make_string's when they happen */
|
800
|
2853 #if defined (ERROR_CHECK_TEXT) && defined (MULE)
|
428
|
2854 bytecount_to_charcount (contents, length); /* Just for the assertions */
|
|
2855 #endif
|
|
2856
|
|
2857 val = make_uninit_string (length);
|
|
2858 memcpy (XSTRING_DATA (val), contents, length);
|
771
|
2859 init_string_ascii_begin (val);
|
|
2860 sledgehammer_check_ascii_begin (val);
|
428
|
2861 return val;
|
|
2862 }
|
|
2863
|
|
2864 /* Take some raw memory, encoded in some external data format,
|
|
2865 and convert it into a Lisp string. */
|
|
2866 Lisp_Object
|
442
|
2867 make_ext_string (const Extbyte *contents, EMACS_INT length,
|
440
|
2868 Lisp_Object coding_system)
|
428
|
2869 {
|
440
|
2870 Lisp_Object string;
|
|
2871 TO_INTERNAL_FORMAT (DATA, (contents, length),
|
|
2872 LISP_STRING, string,
|
|
2873 coding_system);
|
|
2874 return string;
|
428
|
2875 }
|
|
2876
|
|
2877 Lisp_Object
|
867
|
2878 build_intstring (const Ibyte *str)
|
771
|
2879 {
|
|
2880 /* Some strlen's crash and burn if passed null. */
|
814
|
2881 return make_string (str, (str ? qxestrlen (str) : (Bytecount) 0));
|
771
|
2882 }
|
|
2883
|
|
2884 Lisp_Object
|
867
|
2885 build_string (const CIbyte *str)
|
428
|
2886 {
|
|
2887 /* Some strlen's crash and burn if passed null. */
|
867
|
2888 return make_string ((const Ibyte *) str, (str ? strlen (str) : 0));
|
428
|
2889 }
|
|
2890
|
|
2891 Lisp_Object
|
593
|
2892 build_ext_string (const Extbyte *str, Lisp_Object coding_system)
|
428
|
2893 {
|
|
2894 /* Some strlen's crash and burn if passed null. */
|
2367
|
2895 return make_ext_string ((const Extbyte *) str,
|
|
2896 (str ? dfc_external_data_len (str, coding_system) :
|
|
2897 0),
|
440
|
2898 coding_system);
|
428
|
2899 }
|
|
2900
|
|
2901 Lisp_Object
|
867
|
2902 build_msg_intstring (const Ibyte *str)
|
428
|
2903 {
|
771
|
2904 return build_intstring (GETTEXT (str));
|
|
2905 }
|
|
2906
|
|
2907 Lisp_Object
|
867
|
2908 build_msg_string (const CIbyte *str)
|
771
|
2909 {
|
|
2910 return build_string (CGETTEXT (str));
|
428
|
2911 }
|
|
2912
|
|
2913 Lisp_Object
|
867
|
2914 make_string_nocopy (const Ibyte *contents, Bytecount length)
|
428
|
2915 {
|
438
|
2916 Lisp_String *s;
|
428
|
2917 Lisp_Object val;
|
|
2918
|
|
2919 /* Make sure we find out about bad make_string_nocopy's when they happen */
|
800
|
2920 #if defined (ERROR_CHECK_TEXT) && defined (MULE)
|
428
|
2921 bytecount_to_charcount (contents, length); /* Just for the assertions */
|
|
2922 #endif
|
|
2923
|
3263
|
2924 #ifdef NEW_GC
|
2720
|
2925 s = alloc_lrecord_type (Lisp_String, &lrecord_string);
|
|
2926 mcpro (wrap_pointer_1 (s)); /* otherwise nocopy_strings get
|
|
2927 collected and static data is tried to
|
|
2928 be freed. */
|
3263
|
2929 #else /* not NEW_GC */
|
428
|
2930 /* Allocate the string header */
|
438
|
2931 ALLOCATE_FIXED_TYPE (string, Lisp_String, s);
|
771
|
2932 set_lheader_implementation (&s->u.lheader, &lrecord_string);
|
|
2933 SET_C_READONLY_RECORD_HEADER (&s->u.lheader);
|
3263
|
2934 #endif /* not NEW_GC */
|
3063
|
2935 /* Don't need to XSET_STRING_ASCII_BEGIN() here because it happens in
|
|
2936 init_string_ascii_begin(). */
|
428
|
2937 s->plist = Qnil;
|
3092
|
2938 #ifdef NEW_GC
|
|
2939 set_lispstringp_indirect (s);
|
|
2940 STRING_DATA_OBJECT (s) =
|
|
2941 wrap_string_indirect_data
|
|
2942 (alloc_lrecord_type (Lisp_String_Indirect_Data,
|
|
2943 &lrecord_string_indirect_data));
|
|
2944 XSTRING_INDIRECT_DATA_DATA (STRING_DATA_OBJECT (s)) = (Ibyte *) contents;
|
|
2945 XSTRING_INDIRECT_DATA_SIZE (STRING_DATA_OBJECT (s)) = length;
|
|
2946 #else /* not NEW_GC */
|
867
|
2947 set_lispstringp_data (s, (Ibyte *) contents);
|
826
|
2948 set_lispstringp_length (s, length);
|
3092
|
2949 #endif /* not NEW_GC */
|
793
|
2950 val = wrap_string (s);
|
771
|
2951 init_string_ascii_begin (val);
|
|
2952 sledgehammer_check_ascii_begin (val);
|
|
2953
|
428
|
2954 return val;
|
|
2955 }
|
|
2956
|
|
2957
|
3263
|
2958 #ifndef NEW_GC
|
428
|
2959 /************************************************************************/
|
|
2960 /* lcrecord lists */
|
|
2961 /************************************************************************/
|
|
2962
|
|
2963 /* Lcrecord lists are used to manage the allocation of particular
|
3024
|
2964 sorts of lcrecords, to avoid calling BASIC_ALLOC_LCRECORD() (and thus
|
428
|
2965 malloc() and garbage-collection junk) as much as possible.
|
|
2966 It is similar to the Blocktype class.
|
|
2967
|
1204
|
2968 See detailed comment in lcrecord.h.
|
|
2969 */
|
|
2970
|
|
2971 const struct memory_description free_description[] = {
|
2551
|
2972 { XD_LISP_OBJECT, offsetof (struct free_lcrecord_header, chain), 0, { 0 },
|
1204
|
2973 XD_FLAG_FREE_LISP_OBJECT },
|
|
2974 { XD_END }
|
|
2975 };
|
|
2976
|
|
2977 DEFINE_LRECORD_IMPLEMENTATION ("free", free,
|
|
2978 0, /*dumpable-flag*/
|
|
2979 0, internal_object_printer,
|
|
2980 0, 0, 0, free_description,
|
|
2981 struct free_lcrecord_header);
|
|
2982
|
|
2983 const struct memory_description lcrecord_list_description[] = {
|
2551
|
2984 { XD_LISP_OBJECT, offsetof (struct lcrecord_list, free), 0, { 0 },
|
1204
|
2985 XD_FLAG_FREE_LISP_OBJECT },
|
|
2986 { XD_END }
|
|
2987 };
|
428
|
2988
|
|
2989 static Lisp_Object
|
|
2990 mark_lcrecord_list (Lisp_Object obj)
|
|
2991 {
|
|
2992 struct lcrecord_list *list = XLCRECORD_LIST (obj);
|
|
2993 Lisp_Object chain = list->free;
|
|
2994
|
|
2995 while (!NILP (chain))
|
|
2996 {
|
|
2997 struct lrecord_header *lheader = XRECORD_LHEADER (chain);
|
|
2998 struct free_lcrecord_header *free_header =
|
|
2999 (struct free_lcrecord_header *) lheader;
|
|
3000
|
442
|
3001 gc_checking_assert
|
|
3002 (/* There should be no other pointers to the free list. */
|
|
3003 ! MARKED_RECORD_HEADER_P (lheader)
|
|
3004 &&
|
|
3005 /* Only lcrecords should be here. */
|
1204
|
3006 ! list->implementation->basic_p
|
442
|
3007 &&
|
|
3008 /* Only free lcrecords should be here. */
|
|
3009 free_header->lcheader.free
|
|
3010 &&
|
|
3011 /* The type of the lcrecord must be right. */
|
1204
|
3012 lheader->type == lrecord_type_free
|
442
|
3013 &&
|
|
3014 /* So must the size. */
|
1204
|
3015 (list->implementation->static_size == 0 ||
|
|
3016 list->implementation->static_size == list->size)
|
442
|
3017 );
|
428
|
3018
|
|
3019 MARK_RECORD_HEADER (lheader);
|
|
3020 chain = free_header->chain;
|
|
3021 }
|
|
3022
|
|
3023 return Qnil;
|
|
3024 }
|
|
3025
|
934
|
3026 DEFINE_LRECORD_IMPLEMENTATION ("lcrecord-list", lcrecord_list,
|
|
3027 0, /*dumpable-flag*/
|
|
3028 mark_lcrecord_list, internal_object_printer,
|
1204
|
3029 0, 0, 0, lcrecord_list_description,
|
|
3030 struct lcrecord_list);
|
934
|
3031
|
428
|
3032 Lisp_Object
|
665
|
3033 make_lcrecord_list (Elemcount size,
|
442
|
3034 const struct lrecord_implementation *implementation)
|
428
|
3035 {
|
3024
|
3036 /* Don't use old_alloc_lcrecord_type() avoid infinite recursion
|
1204
|
3037 allocating this, */
|
|
3038 struct lcrecord_list *p = (struct lcrecord_list *)
|
3024
|
3039 old_basic_alloc_lcrecord (sizeof (struct lcrecord_list),
|
|
3040 &lrecord_lcrecord_list);
|
428
|
3041
|
|
3042 p->implementation = implementation;
|
|
3043 p->size = size;
|
|
3044 p->free = Qnil;
|
793
|
3045 return wrap_lcrecord_list (p);
|
428
|
3046 }
|
|
3047
|
|
3048 Lisp_Object
|
1204
|
3049 alloc_managed_lcrecord (Lisp_Object lcrecord_list)
|
428
|
3050 {
|
|
3051 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
|
|
3052 if (!NILP (list->free))
|
|
3053 {
|
|
3054 Lisp_Object val = list->free;
|
|
3055 struct free_lcrecord_header *free_header =
|
|
3056 (struct free_lcrecord_header *) XPNTR (val);
|
1204
|
3057 struct lrecord_header *lheader = &free_header->lcheader.lheader;
|
428
|
3058
|
|
3059 #ifdef ERROR_CHECK_GC
|
1204
|
3060 /* Major overkill here. */
|
428
|
3061 /* There should be no other pointers to the free list. */
|
442
|
3062 assert (! MARKED_RECORD_HEADER_P (lheader));
|
428
|
3063 /* Only free lcrecords should be here. */
|
|
3064 assert (free_header->lcheader.free);
|
1204
|
3065 assert (lheader->type == lrecord_type_free);
|
|
3066 /* Only lcrecords should be here. */
|
|
3067 assert (! (list->implementation->basic_p));
|
|
3068 #if 0 /* Not used anymore, now that we set the type of the header to
|
|
3069 lrecord_type_free. */
|
428
|
3070 /* The type of the lcrecord must be right. */
|
442
|
3071 assert (LHEADER_IMPLEMENTATION (lheader) == list->implementation);
|
1204
|
3072 #endif /* 0 */
|
428
|
3073 /* So must the size. */
|
1204
|
3074 assert (list->implementation->static_size == 0 ||
|
|
3075 list->implementation->static_size == list->size);
|
428
|
3076 #endif /* ERROR_CHECK_GC */
|
442
|
3077
|
428
|
3078 list->free = free_header->chain;
|
|
3079 free_header->lcheader.free = 0;
|
1204
|
3080 /* Put back the correct type, as we set it to lrecord_type_free. */
|
|
3081 lheader->type = list->implementation->lrecord_type_index;
|
3024
|
3082 old_zero_sized_lcrecord (free_header, list->size);
|
428
|
3083 return val;
|
|
3084 }
|
|
3085 else
|
3024
|
3086 return wrap_pointer_1 (old_basic_alloc_lcrecord (list->size,
|
|
3087 list->implementation));
|
428
|
3088 }
|
|
3089
|
771
|
3090 /* "Free" a Lisp object LCRECORD by placing it on its associated free list
|
1204
|
3091 LCRECORD_LIST; next time alloc_managed_lcrecord() is called with the
|
771
|
3092 same LCRECORD_LIST as its parameter, it will return an object from the
|
|
3093 free list, which may be this one. Be VERY VERY SURE there are no
|
|
3094 pointers to this object hanging around anywhere where they might be
|
|
3095 used!
|
|
3096
|
|
3097 The first thing this does before making any global state change is to
|
|
3098 call the finalize method of the object, if it exists. */
|
|
3099
|
428
|
3100 void
|
|
3101 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord)
|
|
3102 {
|
|
3103 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list);
|
|
3104 struct free_lcrecord_header *free_header =
|
|
3105 (struct free_lcrecord_header *) XPNTR (lcrecord);
|
442
|
3106 struct lrecord_header *lheader = &free_header->lcheader.lheader;
|
|
3107 const struct lrecord_implementation *implementation
|
428
|
3108 = LHEADER_IMPLEMENTATION (lheader);
|
|
3109
|
771
|
3110 /* Finalizer methods may try to free objects within them, which typically
|
|
3111 won't be marked and thus are scheduled for demolition. Putting them
|
|
3112 on the free list would be very bad, as we'd have xfree()d memory in
|
|
3113 the list. Even if for some reason the objects are still live
|
|
3114 (generally a logic error!), we still will have problems putting such
|
|
3115 an object on the free list right now (e.g. we'd have to avoid calling
|
|
3116 the finalizer twice, etc.). So basically, those finalizers should not
|
|
3117 be freeing any objects if during GC. Abort now to catch those
|
|
3118 problems. */
|
|
3119 gc_checking_assert (!gc_in_progress);
|
|
3120
|
428
|
3121 /* Make sure the size is correct. This will catch, for example,
|
|
3122 putting a window configuration on the wrong free list. */
|
1204
|
3123 gc_checking_assert (detagged_lisp_object_size (lheader) == list->size);
|
771
|
3124 /* Make sure the object isn't already freed. */
|
|
3125 gc_checking_assert (!free_header->lcheader.free);
|
2367
|
3126 /* Freeing stuff in dumped memory is bad. If you trip this, you
|
|
3127 may need to check for this before freeing. */
|
|
3128 gc_checking_assert (!OBJECT_DUMPED_P (lcrecord));
|
771
|
3129
|
428
|
3130 if (implementation->finalizer)
|
|
3131 implementation->finalizer (lheader, 0);
|
1204
|
3132 /* Yes, there are two ways to indicate freeness -- the type is
|
|
3133 lrecord_type_free or the ->free flag is set. We used to do only the
|
|
3134 latter; now we do the former as well for KKCC purposes. Probably
|
|
3135 safer in any case, as we will lose quicker this way than keeping
|
|
3136 around an lrecord of apparently correct type but bogus junk in it. */
|
|
3137 MARK_LRECORD_AS_FREE (lheader);
|
428
|
3138 free_header->chain = list->free;
|
|
3139 free_header->lcheader.free = 1;
|
|
3140 list->free = lcrecord;
|
|
3141 }
|
|
3142
|
771
|
3143 static Lisp_Object all_lcrecord_lists[countof (lrecord_implementations_table)];
|
|
3144
|
|
3145 void *
|
|
3146 alloc_automanaged_lcrecord (Bytecount size,
|
|
3147 const struct lrecord_implementation *imp)
|
|
3148 {
|
|
3149 if (EQ (all_lcrecord_lists[imp->lrecord_type_index], Qzero))
|
|
3150 all_lcrecord_lists[imp->lrecord_type_index] =
|
|
3151 make_lcrecord_list (size, imp);
|
|
3152
|
1204
|
3153 return XPNTR (alloc_managed_lcrecord
|
771
|
3154 (all_lcrecord_lists[imp->lrecord_type_index]));
|
|
3155 }
|
|
3156
|
|
3157 void
|
3024
|
3158 old_free_lcrecord (Lisp_Object rec)
|
771
|
3159 {
|
|
3160 int type = XRECORD_LHEADER (rec)->type;
|
|
3161
|
|
3162 assert (!EQ (all_lcrecord_lists[type], Qzero));
|
|
3163
|
|
3164 free_managed_lcrecord (all_lcrecord_lists[type], rec);
|
|
3165 }
|
3263
|
3166 #endif /* not NEW_GC */
|
428
|
3167
|
|
3168
|
|
3169 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /*
|
|
3170 Kept for compatibility, returns its argument.
|
|
3171 Old:
|
|
3172 Make a copy of OBJECT in pure storage.
|
|
3173 Recursively copies contents of vectors and cons cells.
|
|
3174 Does not copy symbols.
|
|
3175 */
|
444
|
3176 (object))
|
428
|
3177 {
|
444
|
3178 return object;
|
428
|
3179 }
|
|
3180
|
|
3181
|
|
3182 /************************************************************************/
|
|
3183 /* Garbage Collection */
|
|
3184 /************************************************************************/
|
|
3185
|
442
|
3186 /* All the built-in lisp object types are enumerated in `enum lrecord_type'.
|
|
3187 Additional ones may be defined by a module (none yet). We leave some
|
|
3188 room in `lrecord_implementations_table' for such new lisp object types. */
|
647
|
3189 const struct lrecord_implementation *lrecord_implementations_table[(int)lrecord_type_last_built_in_type + MODULE_DEFINABLE_TYPE_COUNT];
|
|
3190 int lrecord_type_count = lrecord_type_last_built_in_type;
|
1676
|
3191 #ifndef USE_KKCC
|
442
|
3192 /* Object marker functions are in the lrecord_implementation structure.
|
|
3193 But copying them to a parallel array is much more cache-friendly.
|
|
3194 This hack speeds up (garbage-collect) by about 5%. */
|
|
3195 Lisp_Object (*lrecord_markers[countof (lrecord_implementations_table)]) (Lisp_Object);
|
1676
|
3196 #endif /* not USE_KKCC */
|
428
|
3197
|
|
3198 struct gcpro *gcprolist;
|
|
3199
|
771
|
3200 /* We want the staticpro list relocated, but not the pointers found
|
|
3201 therein, because they refer to locations in the global data segment, not
|
|
3202 in the heap; we only dump heap objects. Hence we use a trivial
|
|
3203 description, as for pointerless objects. (Note that the data segment
|
|
3204 objects, which are global variables like Qfoo or Vbar, themselves are
|
|
3205 pointers to heap objects. Each needs to be described to pdump as a
|
|
3206 "root pointer"; this happens in the call to staticpro(). */
|
1204
|
3207 static const struct memory_description staticpro_description_1[] = {
|
452
|
3208 { XD_END }
|
|
3209 };
|
|
3210
|
1204
|
3211 static const struct sized_memory_description staticpro_description = {
|
452
|
3212 sizeof (Lisp_Object *),
|
|
3213 staticpro_description_1
|
|
3214 };
|
|
3215
|
1204
|
3216 static const struct memory_description staticpros_description_1[] = {
|
452
|
3217 XD_DYNARR_DESC (Lisp_Object_ptr_dynarr, &staticpro_description),
|
|
3218 { XD_END }
|
|
3219 };
|
|
3220
|
1204
|
3221 static const struct sized_memory_description staticpros_description = {
|
452
|
3222 sizeof (Lisp_Object_ptr_dynarr),
|
|
3223 staticpros_description_1
|
|
3224 };
|
|
3225
|
771
|
3226 #ifdef DEBUG_XEMACS
|
|
3227
|
1204
|
3228 static const struct memory_description staticpro_one_name_description_1[] = {
|
2367
|
3229 { XD_ASCII_STRING, 0 },
|
771
|
3230 { XD_END }
|
|
3231 };
|
|
3232
|
1204
|
3233 static const struct sized_memory_description staticpro_one_name_description = {
|
771
|
3234 sizeof (char *),
|
|
3235 staticpro_one_name_description_1
|
|
3236 };
|
|
3237
|
1204
|
3238 static const struct memory_description staticpro_names_description_1[] = {
|
771
|
3239 XD_DYNARR_DESC (char_ptr_dynarr, &staticpro_one_name_description),
|
|
3240 { XD_END }
|
|
3241 };
|
|
3242
|
1204
|
3243
|
|
3244 extern const struct sized_memory_description staticpro_names_description;
|
|
3245
|
|
3246 const struct sized_memory_description staticpro_names_description = {
|
771
|
3247 sizeof (char_ptr_dynarr),
|
|
3248 staticpro_names_description_1
|
|
3249 };
|
|
3250
|
|
3251 /* Help debug crashes gc-marking a staticpro'ed object. */
|
|
3252
|
|
3253 Lisp_Object_ptr_dynarr *staticpros;
|
|
3254 char_ptr_dynarr *staticpro_names;
|
|
3255
|
|
3256 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
|
|
3257 garbage collection, and for dumping. */
|
|
3258 void
|
|
3259 staticpro_1 (Lisp_Object *varaddress, char *varname)
|
|
3260 {
|
|
3261 Dynarr_add (staticpros, varaddress);
|
|
3262 Dynarr_add (staticpro_names, varname);
|
1204
|
3263 dump_add_root_lisp_object (varaddress);
|
771
|
3264 }
|
|
3265
|
|
3266
|
|
3267 Lisp_Object_ptr_dynarr *staticpros_nodump;
|
|
3268 char_ptr_dynarr *staticpro_nodump_names;
|
|
3269
|
|
3270 /* Mark the Lisp_Object at heap VARADDRESS as a root object for
|
|
3271 garbage collection, but not for dumping. (See below.) */
|
|
3272 void
|
|
3273 staticpro_nodump_1 (Lisp_Object *varaddress, char *varname)
|
|
3274 {
|
|
3275 Dynarr_add (staticpros_nodump, varaddress);
|
|
3276 Dynarr_add (staticpro_nodump_names, varname);
|
|
3277 }
|
|
3278
|
996
|
3279 #ifdef HAVE_SHLIB
|
|
3280 /* Stop treating the Lisp_Object at non-heap VARADDRESS as a root object
|
|
3281 for garbage collection, but not for dumping. */
|
|
3282 void
|
|
3283 unstaticpro_nodump_1 (Lisp_Object *varaddress, char *varname)
|
|
3284 {
|
|
3285 Dynarr_delete_object (staticpros, varaddress);
|
|
3286 Dynarr_delete_object (staticpro_names, varname);
|
|
3287 }
|
|
3288 #endif
|
|
3289
|
771
|
3290 #else /* not DEBUG_XEMACS */
|
|
3291
|
452
|
3292 Lisp_Object_ptr_dynarr *staticpros;
|
|
3293
|
|
3294 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
|
|
3295 garbage collection, and for dumping. */
|
428
|
3296 void
|
|
3297 staticpro (Lisp_Object *varaddress)
|
|
3298 {
|
452
|
3299 Dynarr_add (staticpros, varaddress);
|
1204
|
3300 dump_add_root_lisp_object (varaddress);
|
428
|
3301 }
|
|
3302
|
442
|
3303
|
452
|
3304 Lisp_Object_ptr_dynarr *staticpros_nodump;
|
|
3305
|
771
|
3306 /* Mark the Lisp_Object at heap VARADDRESS as a root object for garbage
|
|
3307 collection, but not for dumping. This is used for objects where the
|
|
3308 only sure pointer is in the heap (rather than in the global data
|
|
3309 segment, as must be the case for pdump root pointers), but not inside of
|
|
3310 another Lisp object (where it will be marked as a result of that Lisp
|
|
3311 object's mark method). The call to staticpro_nodump() must occur *BOTH*
|
|
3312 at initialization time and at "reinitialization" time (startup, after
|
|
3313 pdump load.) (For example, this is the case with the predicate symbols
|
|
3314 for specifier and coding system types. The pointer to this symbol is
|
|
3315 inside of a methods structure, which is allocated on the heap. The
|
|
3316 methods structure will be written out to the pdump data file, and may be
|
|
3317 reloaded at a different address.)
|
|
3318
|
|
3319 #### The necessity for reinitialization is a bug in pdump. Pdump should
|
|
3320 automatically regenerate the staticpro()s for these symbols when it
|
|
3321 loads the data in. */
|
|
3322
|
428
|
3323 void
|
|
3324 staticpro_nodump (Lisp_Object *varaddress)
|
|
3325 {
|
452
|
3326 Dynarr_add (staticpros_nodump, varaddress);
|
428
|
3327 }
|
|
3328
|
996
|
3329 #ifdef HAVE_SHLIB
|
|
3330 /* Unmark the Lisp_Object at non-heap VARADDRESS as a root object for
|
|
3331 garbage collection, but not for dumping. */
|
|
3332 void
|
|
3333 unstaticpro_nodump (Lisp_Object *varaddress)
|
|
3334 {
|
|
3335 Dynarr_delete_object (staticpros, varaddress);
|
|
3336 }
|
|
3337 #endif
|
|
3338
|
771
|
3339 #endif /* not DEBUG_XEMACS */
|
|
3340
|
2720
|
3341
|
|
3342
|
|
3343
|
|
3344
|
3263
|
3345 #ifdef NEW_GC
|
2720
|
3346 static const struct memory_description mcpro_description_1[] = {
|
|
3347 { XD_END }
|
|
3348 };
|
|
3349
|
|
3350 static const struct sized_memory_description mcpro_description = {
|
|
3351 sizeof (Lisp_Object *),
|
|
3352 mcpro_description_1
|
|
3353 };
|
|
3354
|
|
3355 static const struct memory_description mcpros_description_1[] = {
|
|
3356 XD_DYNARR_DESC (Lisp_Object_dynarr, &mcpro_description),
|
|
3357 { XD_END }
|
|
3358 };
|
|
3359
|
|
3360 static const struct sized_memory_description mcpros_description = {
|
|
3361 sizeof (Lisp_Object_dynarr),
|
|
3362 mcpros_description_1
|
|
3363 };
|
|
3364
|
|
3365 #ifdef DEBUG_XEMACS
|
|
3366
|
|
3367 static const struct memory_description mcpro_one_name_description_1[] = {
|
|
3368 { XD_ASCII_STRING, 0 },
|
|
3369 { XD_END }
|
|
3370 };
|
|
3371
|
|
3372 static const struct sized_memory_description mcpro_one_name_description = {
|
|
3373 sizeof (char *),
|
|
3374 mcpro_one_name_description_1
|
|
3375 };
|
|
3376
|
|
3377 static const struct memory_description mcpro_names_description_1[] = {
|
|
3378 XD_DYNARR_DESC (char_ptr_dynarr, &mcpro_one_name_description),
|
|
3379 { XD_END }
|
|
3380 };
|
|
3381
|
|
3382 extern const struct sized_memory_description mcpro_names_description;
|
|
3383
|
|
3384 const struct sized_memory_description mcpro_names_description = {
|
|
3385 sizeof (char_ptr_dynarr),
|
|
3386 mcpro_names_description_1
|
|
3387 };
|
|
3388
|
|
3389 /* Help debug crashes gc-marking a mcpro'ed object. */
|
|
3390
|
|
3391 Lisp_Object_dynarr *mcpros;
|
|
3392 char_ptr_dynarr *mcpro_names;
|
|
3393
|
|
3394 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
|
|
3395 garbage collection, and for dumping. */
|
|
3396 void
|
|
3397 mcpro_1 (Lisp_Object varaddress, char *varname)
|
|
3398 {
|
|
3399 Dynarr_add (mcpros, varaddress);
|
|
3400 Dynarr_add (mcpro_names, varname);
|
|
3401 }
|
|
3402
|
|
3403 #else /* not DEBUG_XEMACS */
|
|
3404
|
|
3405 Lisp_Object_dynarr *mcpros;
|
|
3406
|
|
3407 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for
|
|
3408 garbage collection, and for dumping. */
|
|
3409 void
|
|
3410 mcpro (Lisp_Object varaddress)
|
|
3411 {
|
|
3412 Dynarr_add (mcpros, varaddress);
|
|
3413 }
|
|
3414
|
|
3415 #endif /* not DEBUG_XEMACS */
|
3263
|
3416 #endif /* NEW_GC */
|
|
3417
|
|
3418
|
|
3419 #ifndef NEW_GC
|
428
|
3420 static int gc_count_num_short_string_in_use;
|
647
|
3421 static Bytecount gc_count_string_total_size;
|
|
3422 static Bytecount gc_count_short_string_total_size;
|
428
|
3423
|
|
3424 /* static int gc_count_total_records_used, gc_count_records_total_size; */
|
|
3425
|
|
3426
|
|
3427 /* stats on lcrecords in use - kinda kludgy */
|
|
3428
|
|
3429 static struct
|
|
3430 {
|
|
3431 int instances_in_use;
|
|
3432 int bytes_in_use;
|
|
3433 int instances_freed;
|
|
3434 int bytes_freed;
|
|
3435 int instances_on_free_list;
|
707
|
3436 } lcrecord_stats [countof (lrecord_implementations_table)
|
|
3437 + MODULE_DEFINABLE_TYPE_COUNT];
|
428
|
3438
|
|
3439 static void
|
442
|
3440 tick_lcrecord_stats (const struct lrecord_header *h, int free_p)
|
428
|
3441 {
|
647
|
3442 int type_index = h->type;
|
428
|
3443
|
3024
|
3444 if (((struct old_lcrecord_header *) h)->free)
|
428
|
3445 {
|
442
|
3446 gc_checking_assert (!free_p);
|
428
|
3447 lcrecord_stats[type_index].instances_on_free_list++;
|
|
3448 }
|
|
3449 else
|
|
3450 {
|
1204
|
3451 Bytecount sz = detagged_lisp_object_size (h);
|
|
3452
|
428
|
3453 if (free_p)
|
|
3454 {
|
|
3455 lcrecord_stats[type_index].instances_freed++;
|
|
3456 lcrecord_stats[type_index].bytes_freed += sz;
|
|
3457 }
|
|
3458 else
|
|
3459 {
|
|
3460 lcrecord_stats[type_index].instances_in_use++;
|
|
3461 lcrecord_stats[type_index].bytes_in_use += sz;
|
|
3462 }
|
|
3463 }
|
|
3464 }
|
3263
|
3465 #endif /* not NEW_GC */
|
428
|
3466
|
|
3467
|
3263
|
3468 #ifndef NEW_GC
|
428
|
3469 /* Free all unmarked records */
|
|
3470 static void
|
3024
|
3471 sweep_lcrecords_1 (struct old_lcrecord_header **prev, int *used)
|
|
3472 {
|
|
3473 struct old_lcrecord_header *header;
|
428
|
3474 int num_used = 0;
|
|
3475 /* int total_size = 0; */
|
|
3476
|
|
3477 xzero (lcrecord_stats); /* Reset all statistics to 0. */
|
|
3478
|
|
3479 /* First go through and call all the finalize methods.
|
|
3480 Then go through and free the objects. There used to
|
|
3481 be only one loop here, with the call to the finalizer
|
|
3482 occurring directly before the xfree() below. That
|
|
3483 is marginally faster but much less safe -- if the
|
|
3484 finalize method for an object needs to reference any
|
|
3485 other objects contained within it (and many do),
|
|
3486 we could easily be screwed by having already freed that
|
|
3487 other object. */
|
|
3488
|
|
3489 for (header = *prev; header; header = header->next)
|
|
3490 {
|
|
3491 struct lrecord_header *h = &(header->lheader);
|
442
|
3492
|
|
3493 GC_CHECK_LHEADER_INVARIANTS (h);
|
|
3494
|
|
3495 if (! MARKED_RECORD_HEADER_P (h) && ! header->free)
|
428
|
3496 {
|
|
3497 if (LHEADER_IMPLEMENTATION (h)->finalizer)
|
|
3498 LHEADER_IMPLEMENTATION (h)->finalizer (h, 0);
|
|
3499 }
|
|
3500 }
|
|
3501
|
|
3502 for (header = *prev; header; )
|
|
3503 {
|
|
3504 struct lrecord_header *h = &(header->lheader);
|
442
|
3505 if (MARKED_RECORD_HEADER_P (h))
|
428
|
3506 {
|
442
|
3507 if (! C_READONLY_RECORD_HEADER_P (h))
|
428
|
3508 UNMARK_RECORD_HEADER (h);
|
|
3509 num_used++;
|
|
3510 /* total_size += n->implementation->size_in_bytes (h);*/
|
440
|
3511 /* #### May modify header->next on a C_READONLY lcrecord */
|
428
|
3512 prev = &(header->next);
|
|
3513 header = *prev;
|
|
3514 tick_lcrecord_stats (h, 0);
|
|
3515 }
|
|
3516 else
|
|
3517 {
|
3024
|
3518 struct old_lcrecord_header *next = header->next;
|
428
|
3519 *prev = next;
|
|
3520 tick_lcrecord_stats (h, 1);
|
|
3521 /* used to call finalizer right here. */
|
3024
|
3522 xfree (header, struct old_lcrecord_header *);
|
428
|
3523 header = next;
|
|
3524 }
|
|
3525 }
|
|
3526 *used = num_used;
|
|
3527 /* *total = total_size; */
|
|
3528 }
|
|
3529
|
|
3530 /* And the Lord said: Thou shalt use the `c-backslash-region' command
|
|
3531 to make macros prettier. */
|
|
3532
|
|
3533 #ifdef ERROR_CHECK_GC
|
|
3534
|
771
|
3535 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \
|
428
|
3536 do { \
|
|
3537 struct typename##_block *SFTB_current; \
|
|
3538 int SFTB_limit; \
|
|
3539 int num_free = 0, num_used = 0; \
|
|
3540 \
|
444
|
3541 for (SFTB_current = current_##typename##_block, \
|
428
|
3542 SFTB_limit = current_##typename##_block_index; \
|
|
3543 SFTB_current; \
|
|
3544 ) \
|
|
3545 { \
|
|
3546 int SFTB_iii; \
|
|
3547 \
|
|
3548 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \
|
|
3549 { \
|
|
3550 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \
|
|
3551 \
|
454
|
3552 if (LRECORD_FREE_P (SFTB_victim)) \
|
428
|
3553 { \
|
|
3554 num_free++; \
|
|
3555 } \
|
|
3556 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \
|
|
3557 { \
|
|
3558 num_used++; \
|
|
3559 } \
|
442
|
3560 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \
|
428
|
3561 { \
|
|
3562 num_free++; \
|
|
3563 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \
|
|
3564 } \
|
|
3565 else \
|
|
3566 { \
|
|
3567 num_used++; \
|
|
3568 UNMARK_##typename (SFTB_victim); \
|
|
3569 } \
|
|
3570 } \
|
|
3571 SFTB_current = SFTB_current->prev; \
|
|
3572 SFTB_limit = countof (current_##typename##_block->block); \
|
|
3573 } \
|
|
3574 \
|
|
3575 gc_count_num_##typename##_in_use = num_used; \
|
|
3576 gc_count_num_##typename##_freelist = num_free; \
|
|
3577 } while (0)
|
|
3578
|
|
3579 #else /* !ERROR_CHECK_GC */
|
|
3580
|
771
|
3581 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \
|
|
3582 do { \
|
|
3583 struct typename##_block *SFTB_current; \
|
|
3584 struct typename##_block **SFTB_prev; \
|
|
3585 int SFTB_limit; \
|
|
3586 int num_free = 0, num_used = 0; \
|
|
3587 \
|
|
3588 typename##_free_list = 0; \
|
|
3589 \
|
|
3590 for (SFTB_prev = ¤t_##typename##_block, \
|
|
3591 SFTB_current = current_##typename##_block, \
|
|
3592 SFTB_limit = current_##typename##_block_index; \
|
|
3593 SFTB_current; \
|
|
3594 ) \
|
|
3595 { \
|
|
3596 int SFTB_iii; \
|
|
3597 int SFTB_empty = 1; \
|
|
3598 Lisp_Free *SFTB_old_free_list = typename##_free_list; \
|
|
3599 \
|
|
3600 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \
|
|
3601 { \
|
|
3602 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \
|
|
3603 \
|
|
3604 if (LRECORD_FREE_P (SFTB_victim)) \
|
|
3605 { \
|
|
3606 num_free++; \
|
|
3607 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, SFTB_victim); \
|
|
3608 } \
|
|
3609 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \
|
|
3610 { \
|
|
3611 SFTB_empty = 0; \
|
|
3612 num_used++; \
|
|
3613 } \
|
|
3614 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \
|
|
3615 { \
|
|
3616 num_free++; \
|
|
3617 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \
|
|
3618 } \
|
|
3619 else \
|
|
3620 { \
|
|
3621 SFTB_empty = 0; \
|
|
3622 num_used++; \
|
|
3623 UNMARK_##typename (SFTB_victim); \
|
|
3624 } \
|
|
3625 } \
|
|
3626 if (!SFTB_empty) \
|
|
3627 { \
|
|
3628 SFTB_prev = &(SFTB_current->prev); \
|
|
3629 SFTB_current = SFTB_current->prev; \
|
|
3630 } \
|
|
3631 else if (SFTB_current == current_##typename##_block \
|
|
3632 && !SFTB_current->prev) \
|
|
3633 { \
|
|
3634 /* No real point in freeing sole allocation block */ \
|
|
3635 break; \
|
|
3636 } \
|
|
3637 else \
|
|
3638 { \
|
|
3639 struct typename##_block *SFTB_victim_block = SFTB_current; \
|
|
3640 if (SFTB_victim_block == current_##typename##_block) \
|
|
3641 current_##typename##_block_index \
|
|
3642 = countof (current_##typename##_block->block); \
|
|
3643 SFTB_current = SFTB_current->prev; \
|
|
3644 { \
|
|
3645 *SFTB_prev = SFTB_current; \
|
1726
|
3646 xfree (SFTB_victim_block, struct typename##_block *); \
|
771
|
3647 /* Restore free list to what it was before victim was swept */ \
|
|
3648 typename##_free_list = SFTB_old_free_list; \
|
|
3649 num_free -= SFTB_limit; \
|
|
3650 } \
|
|
3651 } \
|
|
3652 SFTB_limit = countof (current_##typename##_block->block); \
|
|
3653 } \
|
|
3654 \
|
|
3655 gc_count_num_##typename##_in_use = num_used; \
|
|
3656 gc_count_num_##typename##_freelist = num_free; \
|
428
|
3657 } while (0)
|
|
3658
|
|
3659 #endif /* !ERROR_CHECK_GC */
|
|
3660
|
771
|
3661 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \
|
|
3662 SWEEP_FIXED_TYPE_BLOCK_1 (typename, obj_type, lheader)
|
|
3663
|
3263
|
3664 #endif /* not NEW_GC */
|
2720
|
3665
|
428
|
3666
|
3263
|
3667 #ifndef NEW_GC
|
428
|
3668 static void
|
|
3669 sweep_conses (void)
|
|
3670 {
|
|
3671 #define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3672 #define ADDITIONAL_FREE_cons(ptr)
|
|
3673
|
440
|
3674 SWEEP_FIXED_TYPE_BLOCK (cons, Lisp_Cons);
|
428
|
3675 }
|
3263
|
3676 #endif /* not NEW_GC */
|
428
|
3677
|
|
3678 /* Explicitly free a cons cell. */
|
|
3679 void
|
853
|
3680 free_cons (Lisp_Object cons)
|
428
|
3681 {
|
3263
|
3682 #ifndef NEW_GC /* to avoid compiler warning */
|
853
|
3683 Lisp_Cons *ptr = XCONS (cons);
|
3263
|
3684 #endif /* not NEW_GC */
|
853
|
3685
|
428
|
3686 #ifdef ERROR_CHECK_GC
|
3263
|
3687 #ifdef NEW_GC
|
2720
|
3688 Lisp_Cons *ptr = XCONS (cons);
|
3263
|
3689 #endif /* NEW_GC */
|
428
|
3690 /* If the CAR is not an int, then it will be a pointer, which will
|
|
3691 always be four-byte aligned. If this cons cell has already been
|
|
3692 placed on the free list, however, its car will probably contain
|
|
3693 a chain pointer to the next cons on the list, which has cleverly
|
|
3694 had all its 0's and 1's inverted. This allows for a quick
|
1204
|
3695 check to make sure we're not freeing something already freed.
|
|
3696
|
|
3697 NOTE: This check may not be necessary. Freeing an object sets its
|
|
3698 type to lrecord_type_free, which will trip up the XCONS() above -- as
|
|
3699 well as a check in FREE_FIXED_TYPE(). */
|
853
|
3700 if (POINTER_TYPE_P (XTYPE (cons_car (ptr))))
|
|
3701 ASSERT_VALID_POINTER (XPNTR (cons_car (ptr)));
|
428
|
3702 #endif /* ERROR_CHECK_GC */
|
|
3703
|
3263
|
3704 #ifdef NEW_GC
|
2720
|
3705 free_lrecord (cons);
|
3263
|
3706 #else /* not NEW_GC */
|
440
|
3707 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, Lisp_Cons, ptr);
|
3263
|
3708 #endif /* not NEW_GC */
|
428
|
3709 }
|
|
3710
|
|
3711 /* explicitly free a list. You **must make sure** that you have
|
|
3712 created all the cons cells that make up this list and that there
|
|
3713 are no pointers to any of these cons cells anywhere else. If there
|
|
3714 are, you will lose. */
|
|
3715
|
|
3716 void
|
|
3717 free_list (Lisp_Object list)
|
|
3718 {
|
|
3719 Lisp_Object rest, next;
|
|
3720
|
|
3721 for (rest = list; !NILP (rest); rest = next)
|
|
3722 {
|
|
3723 next = XCDR (rest);
|
853
|
3724 free_cons (rest);
|
428
|
3725 }
|
|
3726 }
|
|
3727
|
|
3728 /* explicitly free an alist. You **must make sure** that you have
|
|
3729 created all the cons cells that make up this alist and that there
|
|
3730 are no pointers to any of these cons cells anywhere else. If there
|
|
3731 are, you will lose. */
|
|
3732
|
|
3733 void
|
|
3734 free_alist (Lisp_Object alist)
|
|
3735 {
|
|
3736 Lisp_Object rest, next;
|
|
3737
|
|
3738 for (rest = alist; !NILP (rest); rest = next)
|
|
3739 {
|
|
3740 next = XCDR (rest);
|
853
|
3741 free_cons (XCAR (rest));
|
|
3742 free_cons (rest);
|
428
|
3743 }
|
|
3744 }
|
|
3745
|
3263
|
3746 #ifndef NEW_GC
|
428
|
3747 static void
|
|
3748 sweep_compiled_functions (void)
|
|
3749 {
|
|
3750 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
945
|
3751 #define ADDITIONAL_FREE_compiled_function(ptr) \
|
1726
|
3752 if (ptr->args_in_array) xfree (ptr->args, Lisp_Object *)
|
428
|
3753
|
|
3754 SWEEP_FIXED_TYPE_BLOCK (compiled_function, Lisp_Compiled_Function);
|
|
3755 }
|
|
3756
|
|
3757 static void
|
|
3758 sweep_floats (void)
|
|
3759 {
|
|
3760 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3761 #define ADDITIONAL_FREE_float(ptr)
|
|
3762
|
440
|
3763 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float);
|
428
|
3764 }
|
|
3765
|
1983
|
3766 #ifdef HAVE_BIGNUM
|
|
3767 static void
|
|
3768 sweep_bignums (void)
|
|
3769 {
|
|
3770 #define UNMARK_bignum(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3771 #define ADDITIONAL_FREE_bignum(ptr) bignum_fini (ptr->data)
|
|
3772
|
|
3773 SWEEP_FIXED_TYPE_BLOCK (bignum, Lisp_Bignum);
|
|
3774 }
|
|
3775 #endif /* HAVE_BIGNUM */
|
|
3776
|
|
3777 #ifdef HAVE_RATIO
|
|
3778 static void
|
|
3779 sweep_ratios (void)
|
|
3780 {
|
|
3781 #define UNMARK_ratio(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3782 #define ADDITIONAL_FREE_ratio(ptr) ratio_fini (ptr->data)
|
|
3783
|
|
3784 SWEEP_FIXED_TYPE_BLOCK (ratio, Lisp_Ratio);
|
|
3785 }
|
|
3786 #endif /* HAVE_RATIO */
|
|
3787
|
|
3788 #ifdef HAVE_BIGFLOAT
|
|
3789 static void
|
|
3790 sweep_bigfloats (void)
|
|
3791 {
|
|
3792 #define UNMARK_bigfloat(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3793 #define ADDITIONAL_FREE_bigfloat(ptr) bigfloat_fini (ptr->bf)
|
|
3794
|
|
3795 SWEEP_FIXED_TYPE_BLOCK (bigfloat, Lisp_Bigfloat);
|
|
3796 }
|
|
3797 #endif
|
|
3798
|
428
|
3799 static void
|
|
3800 sweep_symbols (void)
|
|
3801 {
|
|
3802 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3803 #define ADDITIONAL_FREE_symbol(ptr)
|
|
3804
|
440
|
3805 SWEEP_FIXED_TYPE_BLOCK (symbol, Lisp_Symbol);
|
428
|
3806 }
|
|
3807
|
|
3808 static void
|
|
3809 sweep_extents (void)
|
|
3810 {
|
|
3811 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3812 #define ADDITIONAL_FREE_extent(ptr)
|
|
3813
|
|
3814 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent);
|
|
3815 }
|
|
3816
|
|
3817 static void
|
|
3818 sweep_events (void)
|
|
3819 {
|
|
3820 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3821 #define ADDITIONAL_FREE_event(ptr)
|
|
3822
|
440
|
3823 SWEEP_FIXED_TYPE_BLOCK (event, Lisp_Event);
|
428
|
3824 }
|
3263
|
3825 #endif /* not NEW_GC */
|
428
|
3826
|
1204
|
3827 #ifdef EVENT_DATA_AS_OBJECTS
|
934
|
3828
|
3263
|
3829 #ifndef NEW_GC
|
934
|
3830 static void
|
|
3831 sweep_key_data (void)
|
|
3832 {
|
|
3833 #define UNMARK_key_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3834 #define ADDITIONAL_FREE_key_data(ptr)
|
|
3835
|
|
3836 SWEEP_FIXED_TYPE_BLOCK (key_data, Lisp_Key_Data);
|
|
3837 }
|
3263
|
3838 #endif /* not NEW_GC */
|
934
|
3839
|
1204
|
3840 void
|
|
3841 free_key_data (Lisp_Object ptr)
|
|
3842 {
|
3263
|
3843 #ifdef NEW_GC
|
2720
|
3844 free_lrecord (ptr);
|
3263
|
3845 #else /* not NEW_GC */
|
1204
|
3846 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (key_data, Lisp_Key_Data, XKEY_DATA (ptr));
|
3263
|
3847 #endif /* not NEW_GC */
|
2720
|
3848 }
|
|
3849
|
3263
|
3850 #ifndef NEW_GC
|
934
|
3851 static void
|
|
3852 sweep_button_data (void)
|
|
3853 {
|
|
3854 #define UNMARK_button_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3855 #define ADDITIONAL_FREE_button_data(ptr)
|
|
3856
|
|
3857 SWEEP_FIXED_TYPE_BLOCK (button_data, Lisp_Button_Data);
|
|
3858 }
|
3263
|
3859 #endif /* not NEW_GC */
|
934
|
3860
|
1204
|
3861 void
|
|
3862 free_button_data (Lisp_Object ptr)
|
|
3863 {
|
3263
|
3864 #ifdef NEW_GC
|
2720
|
3865 free_lrecord (ptr);
|
3263
|
3866 #else /* not NEW_GC */
|
1204
|
3867 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (button_data, Lisp_Button_Data, XBUTTON_DATA (ptr));
|
3263
|
3868 #endif /* not NEW_GC */
|
2720
|
3869 }
|
|
3870
|
3263
|
3871 #ifndef NEW_GC
|
934
|
3872 static void
|
|
3873 sweep_motion_data (void)
|
|
3874 {
|
|
3875 #define UNMARK_motion_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3876 #define ADDITIONAL_FREE_motion_data(ptr)
|
|
3877
|
|
3878 SWEEP_FIXED_TYPE_BLOCK (motion_data, Lisp_Motion_Data);
|
|
3879 }
|
3263
|
3880 #endif /* not NEW_GC */
|
934
|
3881
|
1204
|
3882 void
|
|
3883 free_motion_data (Lisp_Object ptr)
|
|
3884 {
|
3263
|
3885 #ifdef NEW_GC
|
2720
|
3886 free_lrecord (ptr);
|
3263
|
3887 #else /* not NEW_GC */
|
1204
|
3888 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (motion_data, Lisp_Motion_Data, XMOTION_DATA (ptr));
|
3263
|
3889 #endif /* not NEW_GC */
|
2720
|
3890 }
|
|
3891
|
3263
|
3892 #ifndef NEW_GC
|
934
|
3893 static void
|
|
3894 sweep_process_data (void)
|
|
3895 {
|
|
3896 #define UNMARK_process_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3897 #define ADDITIONAL_FREE_process_data(ptr)
|
|
3898
|
|
3899 SWEEP_FIXED_TYPE_BLOCK (process_data, Lisp_Process_Data);
|
|
3900 }
|
3263
|
3901 #endif /* not NEW_GC */
|
934
|
3902
|
1204
|
3903 void
|
|
3904 free_process_data (Lisp_Object ptr)
|
|
3905 {
|
3263
|
3906 #ifdef NEW_GC
|
2720
|
3907 free_lrecord (ptr);
|
3263
|
3908 #else /* not NEW_GC */
|
1204
|
3909 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (process_data, Lisp_Process_Data, XPROCESS_DATA (ptr));
|
3263
|
3910 #endif /* not NEW_GC */
|
2720
|
3911 }
|
|
3912
|
3263
|
3913 #ifndef NEW_GC
|
934
|
3914 static void
|
|
3915 sweep_timeout_data (void)
|
|
3916 {
|
|
3917 #define UNMARK_timeout_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3918 #define ADDITIONAL_FREE_timeout_data(ptr)
|
|
3919
|
|
3920 SWEEP_FIXED_TYPE_BLOCK (timeout_data, Lisp_Timeout_Data);
|
|
3921 }
|
3263
|
3922 #endif /* not NEW_GC */
|
934
|
3923
|
1204
|
3924 void
|
|
3925 free_timeout_data (Lisp_Object ptr)
|
|
3926 {
|
3263
|
3927 #ifdef NEW_GC
|
2720
|
3928 free_lrecord (ptr);
|
3263
|
3929 #else /* not NEW_GC */
|
1204
|
3930 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (timeout_data, Lisp_Timeout_Data, XTIMEOUT_DATA (ptr));
|
3263
|
3931 #endif /* not NEW_GC */
|
2720
|
3932 }
|
|
3933
|
3263
|
3934 #ifndef NEW_GC
|
934
|
3935 static void
|
|
3936 sweep_magic_data (void)
|
|
3937 {
|
|
3938 #define UNMARK_magic_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3939 #define ADDITIONAL_FREE_magic_data(ptr)
|
|
3940
|
|
3941 SWEEP_FIXED_TYPE_BLOCK (magic_data, Lisp_Magic_Data);
|
|
3942 }
|
3263
|
3943 #endif /* not NEW_GC */
|
934
|
3944
|
1204
|
3945 void
|
|
3946 free_magic_data (Lisp_Object ptr)
|
|
3947 {
|
3263
|
3948 #ifdef NEW_GC
|
2720
|
3949 free_lrecord (ptr);
|
3263
|
3950 #else /* not NEW_GC */
|
1204
|
3951 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (magic_data, Lisp_Magic_Data, XMAGIC_DATA (ptr));
|
3263
|
3952 #endif /* not NEW_GC */
|
2720
|
3953 }
|
|
3954
|
3263
|
3955 #ifndef NEW_GC
|
934
|
3956 static void
|
|
3957 sweep_magic_eval_data (void)
|
|
3958 {
|
|
3959 #define UNMARK_magic_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3960 #define ADDITIONAL_FREE_magic_eval_data(ptr)
|
|
3961
|
|
3962 SWEEP_FIXED_TYPE_BLOCK (magic_eval_data, Lisp_Magic_Eval_Data);
|
|
3963 }
|
3263
|
3964 #endif /* not NEW_GC */
|
934
|
3965
|
1204
|
3966 void
|
|
3967 free_magic_eval_data (Lisp_Object ptr)
|
|
3968 {
|
3263
|
3969 #ifdef NEW_GC
|
2720
|
3970 free_lrecord (ptr);
|
3263
|
3971 #else /* not NEW_GC */
|
1204
|
3972 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (magic_eval_data, Lisp_Magic_Eval_Data, XMAGIC_EVAL_DATA (ptr));
|
3263
|
3973 #endif /* not NEW_GC */
|
2720
|
3974 }
|
|
3975
|
3263
|
3976 #ifndef NEW_GC
|
934
|
3977 static void
|
|
3978 sweep_eval_data (void)
|
|
3979 {
|
|
3980 #define UNMARK_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
3981 #define ADDITIONAL_FREE_eval_data(ptr)
|
|
3982
|
|
3983 SWEEP_FIXED_TYPE_BLOCK (eval_data, Lisp_Eval_Data);
|
|
3984 }
|
3263
|
3985 #endif /* not NEW_GC */
|
934
|
3986
|
1204
|
3987 void
|
|
3988 free_eval_data (Lisp_Object ptr)
|
|
3989 {
|
3263
|
3990 #ifdef NEW_GC
|
2720
|
3991 free_lrecord (ptr);
|
3263
|
3992 #else /* not NEW_GC */
|
1204
|
3993 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (eval_data, Lisp_Eval_Data, XEVAL_DATA (ptr));
|
3263
|
3994 #endif /* not NEW_GC */
|
2720
|
3995 }
|
|
3996
|
3263
|
3997 #ifndef NEW_GC
|
934
|
3998 static void
|
|
3999 sweep_misc_user_data (void)
|
|
4000 {
|
|
4001 #define UNMARK_misc_user_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
4002 #define ADDITIONAL_FREE_misc_user_data(ptr)
|
|
4003
|
|
4004 SWEEP_FIXED_TYPE_BLOCK (misc_user_data, Lisp_Misc_User_Data);
|
|
4005 }
|
3263
|
4006 #endif /* not NEW_GC */
|
934
|
4007
|
1204
|
4008 void
|
|
4009 free_misc_user_data (Lisp_Object ptr)
|
|
4010 {
|
3263
|
4011 #ifdef NEW_GC
|
2720
|
4012 free_lrecord (ptr);
|
3263
|
4013 #else /* not NEW_GC */
|
1204
|
4014 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (misc_user_data, Lisp_Misc_User_Data, XMISC_USER_DATA (ptr));
|
3263
|
4015 #endif /* not NEW_GC */
|
1204
|
4016 }
|
|
4017
|
|
4018 #endif /* EVENT_DATA_AS_OBJECTS */
|
934
|
4019
|
3263
|
4020 #ifndef NEW_GC
|
428
|
4021 static void
|
|
4022 sweep_markers (void)
|
|
4023 {
|
|
4024 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader))
|
|
4025 #define ADDITIONAL_FREE_marker(ptr) \
|
|
4026 do { Lisp_Object tem; \
|
793
|
4027 tem = wrap_marker (ptr); \
|
428
|
4028 unchain_marker (tem); \
|
|
4029 } while (0)
|
|
4030
|
440
|
4031 SWEEP_FIXED_TYPE_BLOCK (marker, Lisp_Marker);
|
428
|
4032 }
|
3263
|
4033 #endif /* not NEW_GC */
|
428
|
4034
|
|
4035 /* Explicitly free a marker. */
|
|
4036 void
|
1204
|
4037 free_marker (Lisp_Object ptr)
|
428
|
4038 {
|
3263
|
4039 #ifdef NEW_GC
|
2720
|
4040 free_lrecord (ptr);
|
3263
|
4041 #else /* not NEW_GC */
|
1204
|
4042 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, Lisp_Marker, XMARKER (ptr));
|
3263
|
4043 #endif /* not NEW_GC */
|
428
|
4044 }
|
|
4045
|
|
4046
|
|
4047 #if defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY)
|
|
4048
|
|
4049 static void
|
|
4050 verify_string_chars_integrity (void)
|
|
4051 {
|
|
4052 struct string_chars_block *sb;
|
|
4053
|
|
4054 /* Scan each existing string block sequentially, string by string. */
|
|
4055 for (sb = first_string_chars_block; sb; sb = sb->next)
|
|
4056 {
|
|
4057 int pos = 0;
|
|
4058 /* POS is the index of the next string in the block. */
|
|
4059 while (pos < sb->pos)
|
|
4060 {
|
|
4061 struct string_chars *s_chars =
|
|
4062 (struct string_chars *) &(sb->string_chars[pos]);
|
438
|
4063 Lisp_String *string;
|
428
|
4064 int size;
|
|
4065 int fullsize;
|
|
4066
|
454
|
4067 /* If the string_chars struct is marked as free (i.e. the
|
|
4068 STRING pointer is NULL) then this is an unused chunk of
|
|
4069 string storage. (See below.) */
|
|
4070
|
|
4071 if (STRING_CHARS_FREE_P (s_chars))
|
428
|
4072 {
|
|
4073 fullsize = ((struct unused_string_chars *) s_chars)->fullsize;
|
|
4074 pos += fullsize;
|
|
4075 continue;
|
|
4076 }
|
|
4077
|
|
4078 string = s_chars->string;
|
|
4079 /* Must be 32-bit aligned. */
|
|
4080 assert ((((int) string) & 3) == 0);
|
|
4081
|
793
|
4082 size = string->size_;
|
428
|
4083 fullsize = STRING_FULLSIZE (size);
|
|
4084
|
|
4085 assert (!BIG_STRING_FULLSIZE_P (fullsize));
|
2720
|
4086 assert (XSTRING_DATA (string) == s_chars->chars);
|
428
|
4087 pos += fullsize;
|
|
4088 }
|
|
4089 assert (pos == sb->pos);
|
|
4090 }
|
|
4091 }
|
|
4092
|
1204
|
4093 #endif /* defined (MULE) && defined (VERIFY_STRING_CHARS_INTEGRITY) */
|
428
|
4094
|
3092
|
4095 #ifndef NEW_GC
|
428
|
4096 /* Compactify string chars, relocating the reference to each --
|
|
4097 free any empty string_chars_block we see. */
|
3092
|
4098 void
|
428
|
4099 compact_string_chars (void)
|
|
4100 {
|
|
4101 struct string_chars_block *to_sb = first_string_chars_block;
|
|
4102 int to_pos = 0;
|
|
4103 struct string_chars_block *from_sb;
|
|
4104
|
|
4105 /* Scan each existing string block sequentially, string by string. */
|
|
4106 for (from_sb = first_string_chars_block; from_sb; from_sb = from_sb->next)
|
|
4107 {
|
|
4108 int from_pos = 0;
|
|
4109 /* FROM_POS is the index of the next string in the block. */
|
|
4110 while (from_pos < from_sb->pos)
|
|
4111 {
|
|
4112 struct string_chars *from_s_chars =
|
|
4113 (struct string_chars *) &(from_sb->string_chars[from_pos]);
|
|
4114 struct string_chars *to_s_chars;
|
438
|
4115 Lisp_String *string;
|
428
|
4116 int size;
|
|
4117 int fullsize;
|
|
4118
|
454
|
4119 /* If the string_chars struct is marked as free (i.e. the
|
|
4120 STRING pointer is NULL) then this is an unused chunk of
|
|
4121 string storage. This happens under Mule when a string's
|
|
4122 size changes in such a way that its fullsize changes.
|
|
4123 (Strings can change size because a different-length
|
|
4124 character can be substituted for another character.)
|
|
4125 In this case, after the bogus string pointer is the
|
|
4126 "fullsize" of this entry, i.e. how many bytes to skip. */
|
|
4127
|
|
4128 if (STRING_CHARS_FREE_P (from_s_chars))
|
428
|
4129 {
|
|
4130 fullsize = ((struct unused_string_chars *) from_s_chars)->fullsize;
|
|
4131 from_pos += fullsize;
|
|
4132 continue;
|
|
4133 }
|
|
4134
|
|
4135 string = from_s_chars->string;
|
1204
|
4136 gc_checking_assert (!(LRECORD_FREE_P (string)));
|
428
|
4137
|
793
|
4138 size = string->size_;
|
428
|
4139 fullsize = STRING_FULLSIZE (size);
|
|
4140
|
442
|
4141 gc_checking_assert (! BIG_STRING_FULLSIZE_P (fullsize));
|
428
|
4142
|
|
4143 /* Just skip it if it isn't marked. */
|
771
|
4144 if (! MARKED_RECORD_HEADER_P (&(string->u.lheader)))
|
428
|
4145 {
|
|
4146 from_pos += fullsize;
|
|
4147 continue;
|
|
4148 }
|
|
4149
|
|
4150 /* If it won't fit in what's left of TO_SB, close TO_SB out
|
|
4151 and go on to the next string_chars_block. We know that TO_SB
|
|
4152 cannot advance past FROM_SB here since FROM_SB is large enough
|
|
4153 to currently contain this string. */
|
|
4154 if ((to_pos + fullsize) > countof (to_sb->string_chars))
|
|
4155 {
|
|
4156 to_sb->pos = to_pos;
|
|
4157 to_sb = to_sb->next;
|
|
4158 to_pos = 0;
|
|
4159 }
|
|
4160
|
|
4161 /* Compute new address of this string
|
|
4162 and update TO_POS for the space being used. */
|
|
4163 to_s_chars = (struct string_chars *) &(to_sb->string_chars[to_pos]);
|
|
4164
|
|
4165 /* Copy the string_chars to the new place. */
|
|
4166 if (from_s_chars != to_s_chars)
|
|
4167 memmove (to_s_chars, from_s_chars, fullsize);
|
|
4168
|
|
4169 /* Relocate FROM_S_CHARS's reference */
|
826
|
4170 set_lispstringp_data (string, &(to_s_chars->chars[0]));
|
428
|
4171
|
|
4172 from_pos += fullsize;
|
|
4173 to_pos += fullsize;
|
|
4174 }
|
|
4175 }
|
|
4176
|
|
4177 /* Set current to the last string chars block still used and
|
|
4178 free any that follow. */
|
|
4179 {
|
|
4180 struct string_chars_block *victim;
|
|
4181
|
|
4182 for (victim = to_sb->next; victim; )
|
|
4183 {
|
|
4184 struct string_chars_block *next = victim->next;
|
1726
|
4185 xfree (victim, struct string_chars_block *);
|
428
|
4186 victim = next;
|
|
4187 }
|
|
4188
|
|
4189 current_string_chars_block = to_sb;
|
|
4190 current_string_chars_block->pos = to_pos;
|
|
4191 current_string_chars_block->next = 0;
|
|
4192 }
|
|
4193 }
|
3092
|
4194 #endif /* not NEW_GC */
|
428
|
4195
|
3263
|
4196 #ifndef NEW_GC
|
428
|
4197 #if 1 /* Hack to debug missing purecopy's */
|
|
4198 static int debug_string_purity;
|
|
4199
|
|
4200 static void
|
793
|
4201 debug_string_purity_print (Lisp_Object p)
|
428
|
4202 {
|
|
4203 Charcount i;
|
826
|
4204 Charcount s = string_char_length (p);
|
442
|
4205 stderr_out ("\"");
|
428
|
4206 for (i = 0; i < s; i++)
|
|
4207 {
|
867
|
4208 Ichar ch = string_ichar (p, i);
|
428
|
4209 if (ch < 32 || ch >= 126)
|
|
4210 stderr_out ("\\%03o", ch);
|
|
4211 else if (ch == '\\' || ch == '\"')
|
|
4212 stderr_out ("\\%c", ch);
|
|
4213 else
|
|
4214 stderr_out ("%c", ch);
|
|
4215 }
|
|
4216 stderr_out ("\"\n");
|
|
4217 }
|
|
4218 #endif /* 1 */
|
3263
|
4219 #endif /* not NEW_GC */
|
|
4220
|
|
4221 #ifndef NEW_GC
|
428
|
4222 static void
|
|
4223 sweep_strings (void)
|
|
4224 {
|
647
|
4225 int num_small_used = 0;
|
|
4226 Bytecount num_small_bytes = 0, num_bytes = 0;
|
428
|
4227 int debug = debug_string_purity;
|
|
4228
|
793
|
4229 #define UNMARK_string(ptr) do { \
|
|
4230 Lisp_String *p = (ptr); \
|
|
4231 Bytecount size = p->size_; \
|
|
4232 UNMARK_RECORD_HEADER (&(p->u.lheader)); \
|
|
4233 num_bytes += size; \
|
|
4234 if (!BIG_STRING_SIZE_P (size)) \
|
|
4235 { \
|
|
4236 num_small_bytes += size; \
|
|
4237 num_small_used++; \
|
|
4238 } \
|
|
4239 if (debug) \
|
|
4240 debug_string_purity_print (wrap_string (p)); \
|
438
|
4241 } while (0)
|
|
4242 #define ADDITIONAL_FREE_string(ptr) do { \
|
793
|
4243 Bytecount size = ptr->size_; \
|
438
|
4244 if (BIG_STRING_SIZE_P (size)) \
|
1726
|
4245 xfree (ptr->data_, Ibyte *); \
|
438
|
4246 } while (0)
|
|
4247
|
771
|
4248 SWEEP_FIXED_TYPE_BLOCK_1 (string, Lisp_String, u.lheader);
|
428
|
4249
|
|
4250 gc_count_num_short_string_in_use = num_small_used;
|
|
4251 gc_count_string_total_size = num_bytes;
|
|
4252 gc_count_short_string_total_size = num_small_bytes;
|
|
4253 }
|
3263
|
4254 #endif /* not NEW_GC */
|
428
|
4255
|
3092
|
4256 #ifndef NEW_GC
|
|
4257 void
|
|
4258 gc_sweep_1 (void)
|
428
|
4259 {
|
|
4260 /* Free all unmarked records. Do this at the very beginning,
|
|
4261 before anything else, so that the finalize methods can safely
|
|
4262 examine items in the objects. sweep_lcrecords_1() makes
|
|
4263 sure to call all the finalize methods *before* freeing anything,
|
|
4264 to complete the safety. */
|
|
4265 {
|
|
4266 int ignored;
|
|
4267 sweep_lcrecords_1 (&all_lcrecords, &ignored);
|
|
4268 }
|
|
4269
|
|
4270 compact_string_chars ();
|
|
4271
|
|
4272 /* Finalize methods below (called through the ADDITIONAL_FREE_foo
|
|
4273 macros) must be *extremely* careful to make sure they're not
|
|
4274 referencing freed objects. The only two existing finalize
|
|
4275 methods (for strings and markers) pass muster -- the string
|
|
4276 finalizer doesn't look at anything but its own specially-
|
|
4277 created block, and the marker finalizer only looks at live
|
|
4278 buffers (which will never be freed) and at the markers before
|
|
4279 and after it in the chain (which, by induction, will never be
|
|
4280 freed because if so, they would have already removed themselves
|
|
4281 from the chain). */
|
|
4282
|
|
4283 /* Put all unmarked strings on free list, free'ing the string chars
|
|
4284 of large unmarked strings */
|
|
4285 sweep_strings ();
|
|
4286
|
|
4287 /* Put all unmarked conses on free list */
|
|
4288 sweep_conses ();
|
|
4289
|
|
4290 /* Free all unmarked compiled-function objects */
|
|
4291 sweep_compiled_functions ();
|
|
4292
|
|
4293 /* Put all unmarked floats on free list */
|
|
4294 sweep_floats ();
|
|
4295
|
1983
|
4296 #ifdef HAVE_BIGNUM
|
|
4297 /* Put all unmarked bignums on free list */
|
|
4298 sweep_bignums ();
|
|
4299 #endif
|
|
4300
|
|
4301 #ifdef HAVE_RATIO
|
|
4302 /* Put all unmarked ratios on free list */
|
|
4303 sweep_ratios ();
|
|
4304 #endif
|
|
4305
|
|
4306 #ifdef HAVE_BIGFLOAT
|
|
4307 /* Put all unmarked bigfloats on free list */
|
|
4308 sweep_bigfloats ();
|
|
4309 #endif
|
|
4310
|
428
|
4311 /* Put all unmarked symbols on free list */
|
|
4312 sweep_symbols ();
|
|
4313
|
|
4314 /* Put all unmarked extents on free list */
|
|
4315 sweep_extents ();
|
|
4316
|
|
4317 /* Put all unmarked markers on free list.
|
|
4318 Dechain each one first from the buffer into which it points. */
|
|
4319 sweep_markers ();
|
|
4320
|
|
4321 sweep_events ();
|
|
4322
|
1204
|
4323 #ifdef EVENT_DATA_AS_OBJECTS
|
934
|
4324 sweep_key_data ();
|
|
4325 sweep_button_data ();
|
|
4326 sweep_motion_data ();
|
|
4327 sweep_process_data ();
|
|
4328 sweep_timeout_data ();
|
|
4329 sweep_magic_data ();
|
|
4330 sweep_magic_eval_data ();
|
|
4331 sweep_eval_data ();
|
|
4332 sweep_misc_user_data ();
|
1204
|
4333 #endif /* EVENT_DATA_AS_OBJECTS */
|
3263
|
4334 #endif /* not NEW_GC */
|
|
4335
|
|
4336 #ifndef NEW_GC
|
428
|
4337 #ifdef PDUMP
|
442
|
4338 pdump_objects_unmark ();
|
428
|
4339 #endif
|
|
4340 }
|
3092
|
4341 #endif /* not NEW_GC */
|
428
|
4342
|
|
4343 /* Clearing for disksave. */
|
|
4344
|
|
4345 void
|
|
4346 disksave_object_finalization (void)
|
|
4347 {
|
|
4348 /* It's important that certain information from the environment not get
|
|
4349 dumped with the executable (pathnames, environment variables, etc.).
|
|
4350 To make it easier to tell when this has happened with strings(1) we
|
|
4351 clear some known-to-be-garbage blocks of memory, so that leftover
|
|
4352 results of old evaluation don't look like potential problems.
|
|
4353 But first we set some notable variables to nil and do one more GC,
|
|
4354 to turn those strings into garbage.
|
440
|
4355 */
|
428
|
4356
|
|
4357 /* Yeah, this list is pretty ad-hoc... */
|
|
4358 Vprocess_environment = Qnil;
|
771
|
4359 env_initted = 0;
|
428
|
4360 Vexec_directory = Qnil;
|
|
4361 Vdata_directory = Qnil;
|
|
4362 Vsite_directory = Qnil;
|
|
4363 Vdoc_directory = Qnil;
|
|
4364 Vexec_path = Qnil;
|
|
4365 Vload_path = Qnil;
|
|
4366 /* Vdump_load_path = Qnil; */
|
|
4367 /* Release hash tables for locate_file */
|
|
4368 Flocate_file_clear_hashing (Qt);
|
771
|
4369 uncache_home_directory ();
|
776
|
4370 zero_out_command_line_status_vars ();
|
872
|
4371 clear_default_devices ();
|
428
|
4372
|
|
4373 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \
|
|
4374 defined(LOADHIST_BUILTIN))
|
|
4375 Vload_history = Qnil;
|
|
4376 #endif
|
|
4377 Vshell_file_name = Qnil;
|
|
4378
|
3092
|
4379 #ifdef NEW_GC
|
|
4380 gc_full ();
|
|
4381 #else /* not NEW_GC */
|
428
|
4382 garbage_collect_1 ();
|
3092
|
4383 #endif /* not NEW_GC */
|
428
|
4384
|
|
4385 /* Run the disksave finalization methods of all live objects. */
|
|
4386 disksave_object_finalization_1 ();
|
|
4387
|
3092
|
4388 #ifndef NEW_GC
|
428
|
4389 /* Zero out the uninitialized (really, unused) part of the containers
|
|
4390 for the live strings. */
|
|
4391 {
|
|
4392 struct string_chars_block *scb;
|
|
4393 for (scb = first_string_chars_block; scb; scb = scb->next)
|
|
4394 {
|
|
4395 int count = sizeof (scb->string_chars) - scb->pos;
|
|
4396
|
|
4397 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE);
|
440
|
4398 if (count != 0)
|
|
4399 {
|
|
4400 /* from the block's fill ptr to the end */
|
|
4401 memset ((scb->string_chars + scb->pos), 0, count);
|
|
4402 }
|
428
|
4403 }
|
|
4404 }
|
3092
|
4405 #endif /* not NEW_GC */
|
428
|
4406
|
|
4407 /* There, that ought to be enough... */
|
|
4408
|
|
4409 }
|
|
4410
|
2994
|
4411 #ifdef ALLOC_TYPE_STATS
|
|
4412
|
2720
|
4413 static Lisp_Object
|
2994
|
4414 gc_plist_hack (const Ascbyte *name, EMACS_INT value, Lisp_Object tail)
|
2720
|
4415 {
|
|
4416 /* C doesn't have local functions (or closures, or GC, or readable syntax,
|
|
4417 or portable numeric datatypes, or bit-vectors, or characters, or
|
|
4418 arrays, or exceptions, or ...) */
|
|
4419 return cons3 (intern (name), make_int (value), tail);
|
|
4420 }
|
2775
|
4421
|
2994
|
4422 static Lisp_Object
|
|
4423 object_memory_usage_stats (int set_total_gc_usage)
|
2720
|
4424 {
|
|
4425 Lisp_Object pl = Qnil;
|
|
4426 int i;
|
2994
|
4427 EMACS_INT tgu_val = 0;
|
|
4428
|
3263
|
4429 #ifdef NEW_GC
|
2775
|
4430
|
2720
|
4431 for (i = 0; i < (countof (lrecord_implementations_table)
|
|
4432 + MODULE_DEFINABLE_TYPE_COUNT); i++)
|
|
4433 {
|
|
4434 if (lrecord_stats[i].instances_in_use != 0)
|
|
4435 {
|
|
4436 char buf [255];
|
|
4437 const char *name = lrecord_implementations_table[i]->name;
|
|
4438 int len = strlen (name);
|
|
4439
|
|
4440 if (lrecord_stats[i].bytes_in_use_including_overhead !=
|
|
4441 lrecord_stats[i].bytes_in_use)
|
|
4442 {
|
|
4443 sprintf (buf, "%s-storage-including-overhead", name);
|
|
4444 pl = gc_plist_hack (buf,
|
|
4445 lrecord_stats[i]
|
|
4446 .bytes_in_use_including_overhead,
|
|
4447 pl);
|
|
4448 }
|
|
4449
|
|
4450 sprintf (buf, "%s-storage", name);
|
|
4451 pl = gc_plist_hack (buf,
|
|
4452 lrecord_stats[i].bytes_in_use,
|
|
4453 pl);
|
2994
|
4454 tgu_val += lrecord_stats[i].bytes_in_use_including_overhead;
|
2720
|
4455
|
|
4456 if (name[len-1] == 's')
|
|
4457 sprintf (buf, "%ses-used", name);
|
|
4458 else
|
|
4459 sprintf (buf, "%ss-used", name);
|
|
4460 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl);
|
|
4461 }
|
|
4462 }
|
2994
|
4463
|
3263
|
4464 #else /* not NEW_GC */
|
428
|
4465
|
|
4466 #define HACK_O_MATIC(type, name, pl) do { \
|
2994
|
4467 EMACS_INT s = 0; \
|
428
|
4468 struct type##_block *x = current_##type##_block; \
|
|
4469 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \
|
2994
|
4470 tgu_val += s; \
|
428
|
4471 (pl) = gc_plist_hack ((name), s, (pl)); \
|
|
4472 } while (0)
|
|
4473
|
442
|
4474 for (i = 0; i < lrecord_type_count; i++)
|
428
|
4475 {
|
|
4476 if (lcrecord_stats[i].bytes_in_use != 0
|
|
4477 || lcrecord_stats[i].bytes_freed != 0
|
|
4478 || lcrecord_stats[i].instances_on_free_list != 0)
|
|
4479 {
|
|
4480 char buf [255];
|
442
|
4481 const char *name = lrecord_implementations_table[i]->name;
|
428
|
4482 int len = strlen (name);
|
|
4483
|
|
4484 sprintf (buf, "%s-storage", name);
|
|
4485 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl);
|
2994
|
4486 tgu_val += lcrecord_stats[i].bytes_in_use;
|
428
|
4487 /* Okay, simple pluralization check for `symbol-value-varalias' */
|
|
4488 if (name[len-1] == 's')
|
|
4489 sprintf (buf, "%ses-freed", name);
|
|
4490 else
|
|
4491 sprintf (buf, "%ss-freed", name);
|
|
4492 if (lcrecord_stats[i].instances_freed != 0)
|
|
4493 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl);
|
|
4494 if (name[len-1] == 's')
|
|
4495 sprintf (buf, "%ses-on-free-list", name);
|
|
4496 else
|
|
4497 sprintf (buf, "%ss-on-free-list", name);
|
|
4498 if (lcrecord_stats[i].instances_on_free_list != 0)
|
|
4499 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list,
|
|
4500 pl);
|
|
4501 if (name[len-1] == 's')
|
|
4502 sprintf (buf, "%ses-used", name);
|
|
4503 else
|
|
4504 sprintf (buf, "%ss-used", name);
|
|
4505 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl);
|
|
4506 }
|
|
4507 }
|
|
4508
|
|
4509 HACK_O_MATIC (extent, "extent-storage", pl);
|
|
4510 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl);
|
|
4511 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl);
|
|
4512 HACK_O_MATIC (event, "event-storage", pl);
|
|
4513 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl);
|
|
4514 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl);
|
|
4515 HACK_O_MATIC (marker, "marker-storage", pl);
|
|
4516 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl);
|
|
4517 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl);
|
|
4518 HACK_O_MATIC (float, "float-storage", pl);
|
|
4519 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl);
|
|
4520 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl);
|
1983
|
4521 #ifdef HAVE_BIGNUM
|
|
4522 HACK_O_MATIC (bignum, "bignum-storage", pl);
|
|
4523 pl = gc_plist_hack ("bignums-free", gc_count_num_bignum_freelist, pl);
|
|
4524 pl = gc_plist_hack ("bignums-used", gc_count_num_bignum_in_use, pl);
|
|
4525 #endif /* HAVE_BIGNUM */
|
|
4526 #ifdef HAVE_RATIO
|
|
4527 HACK_O_MATIC (ratio, "ratio-storage", pl);
|
|
4528 pl = gc_plist_hack ("ratios-free", gc_count_num_ratio_freelist, pl);
|
|
4529 pl = gc_plist_hack ("ratios-used", gc_count_num_ratio_in_use, pl);
|
|
4530 #endif /* HAVE_RATIO */
|
|
4531 #ifdef HAVE_BIGFLOAT
|
|
4532 HACK_O_MATIC (bigfloat, "bigfloat-storage", pl);
|
|
4533 pl = gc_plist_hack ("bigfloats-free", gc_count_num_bigfloat_freelist, pl);
|
|
4534 pl = gc_plist_hack ("bigfloats-used", gc_count_num_bigfloat_in_use, pl);
|
|
4535 #endif /* HAVE_BIGFLOAT */
|
428
|
4536 HACK_O_MATIC (string, "string-header-storage", pl);
|
|
4537 pl = gc_plist_hack ("long-strings-total-length",
|
|
4538 gc_count_string_total_size
|
|
4539 - gc_count_short_string_total_size, pl);
|
|
4540 HACK_O_MATIC (string_chars, "short-string-storage", pl);
|
|
4541 pl = gc_plist_hack ("short-strings-total-length",
|
|
4542 gc_count_short_string_total_size, pl);
|
|
4543 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl);
|
|
4544 pl = gc_plist_hack ("long-strings-used",
|
|
4545 gc_count_num_string_in_use
|
|
4546 - gc_count_num_short_string_in_use, pl);
|
|
4547 pl = gc_plist_hack ("short-strings-used",
|
|
4548 gc_count_num_short_string_in_use, pl);
|
|
4549
|
|
4550 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl);
|
|
4551 pl = gc_plist_hack ("compiled-functions-free",
|
|
4552 gc_count_num_compiled_function_freelist, pl);
|
|
4553 pl = gc_plist_hack ("compiled-functions-used",
|
|
4554 gc_count_num_compiled_function_in_use, pl);
|
|
4555
|
|
4556 HACK_O_MATIC (symbol, "symbol-storage", pl);
|
|
4557 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl);
|
|
4558 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl);
|
|
4559
|
|
4560 HACK_O_MATIC (cons, "cons-storage", pl);
|
|
4561 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl);
|
|
4562 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl);
|
|
4563
|
2994
|
4564 #undef HACK_O_MATIC
|
|
4565
|
3263
|
4566 #endif /* NEW_GC */
|
2994
|
4567
|
|
4568 if (set_total_gc_usage)
|
|
4569 {
|
|
4570 total_gc_usage = tgu_val;
|
|
4571 total_gc_usage_set = 1;
|
|
4572 }
|
|
4573
|
|
4574 return pl;
|
|
4575 }
|
|
4576
|
|
4577 DEFUN("object-memory-usage-stats", Fobject_memory_usage_stats, 0, 0 ,"", /*
|
|
4578 Return statistics about memory usage of Lisp objects.
|
|
4579 */
|
|
4580 ())
|
|
4581 {
|
|
4582 return object_memory_usage_stats (0);
|
|
4583 }
|
|
4584
|
|
4585 #endif /* ALLOC_TYPE_STATS */
|
|
4586
|
|
4587 /* Debugging aids. */
|
|
4588
|
|
4589 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /*
|
|
4590 Reclaim storage for Lisp objects no longer needed.
|
|
4591 Return info on amount of space in use:
|
|
4592 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS)
|
|
4593 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS
|
|
4594 PLIST)
|
|
4595 where `PLIST' is a list of alternating keyword/value pairs providing
|
|
4596 more detailed information.
|
|
4597 Garbage collection happens automatically if you cons more than
|
|
4598 `gc-cons-threshold' bytes of Lisp data since previous garbage collection.
|
|
4599 */
|
|
4600 ())
|
|
4601 {
|
|
4602 /* Record total usage for purposes of determining next GC */
|
3092
|
4603 #ifdef NEW_GC
|
|
4604 gc_full ();
|
|
4605 #else /* not NEW_GC */
|
2994
|
4606 garbage_collect_1 ();
|
3092
|
4607 #endif /* not NEW_GC */
|
2994
|
4608
|
|
4609 /* This will get set to 1, and total_gc_usage computed, as part of the
|
|
4610 call to object_memory_usage_stats() -- if ALLOC_TYPE_STATS is enabled. */
|
|
4611 total_gc_usage_set = 0;
|
|
4612 #ifdef ALLOC_TYPE_STATS
|
428
|
4613 /* The things we do for backwards-compatibility */
|
3263
|
4614 #ifdef NEW_GC
|
2994
|
4615 return
|
|
4616 list6
|
|
4617 (Fcons (make_int (lrecord_stats[lrecord_type_cons].instances_in_use),
|
|
4618 make_int (lrecord_stats[lrecord_type_cons]
|
|
4619 .bytes_in_use_including_overhead)),
|
|
4620 Fcons (make_int (lrecord_stats[lrecord_type_symbol].instances_in_use),
|
|
4621 make_int (lrecord_stats[lrecord_type_symbol]
|
|
4622 .bytes_in_use_including_overhead)),
|
|
4623 Fcons (make_int (lrecord_stats[lrecord_type_marker].instances_in_use),
|
|
4624 make_int (lrecord_stats[lrecord_type_marker]
|
|
4625 .bytes_in_use_including_overhead)),
|
|
4626 make_int (lrecord_stats[lrecord_type_string]
|
|
4627 .bytes_in_use_including_overhead),
|
|
4628 make_int (lrecord_stats[lrecord_type_vector]
|
|
4629 .bytes_in_use_including_overhead),
|
|
4630 object_memory_usage_stats (1));
|
3263
|
4631 #else /* not NEW_GC */
|
428
|
4632 return
|
|
4633 list6 (Fcons (make_int (gc_count_num_cons_in_use),
|
|
4634 make_int (gc_count_num_cons_freelist)),
|
|
4635 Fcons (make_int (gc_count_num_symbol_in_use),
|
|
4636 make_int (gc_count_num_symbol_freelist)),
|
|
4637 Fcons (make_int (gc_count_num_marker_in_use),
|
|
4638 make_int (gc_count_num_marker_freelist)),
|
|
4639 make_int (gc_count_string_total_size),
|
2994
|
4640 make_int (lcrecord_stats[lrecord_type_vector].bytes_in_use +
|
|
4641 lcrecord_stats[lrecord_type_vector].bytes_freed),
|
|
4642 object_memory_usage_stats (1));
|
3263
|
4643 #endif /* not NEW_GC */
|
2994
|
4644 #else /* not ALLOC_TYPE_STATS */
|
|
4645 return Qnil;
|
|
4646 #endif /* ALLOC_TYPE_STATS */
|
|
4647 }
|
428
|
4648
|
|
4649 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /*
|
|
4650 Return the number of bytes consed since the last garbage collection.
|
|
4651 \"Consed\" is a misnomer in that this actually counts allocation
|
|
4652 of all different kinds of objects, not just conses.
|
|
4653
|
|
4654 If this value exceeds `gc-cons-threshold', a garbage collection happens.
|
|
4655 */
|
|
4656 ())
|
|
4657 {
|
|
4658 return make_int (consing_since_gc);
|
|
4659 }
|
|
4660
|
440
|
4661 #if 0
|
444
|
4662 DEFUN ("memory-limit", Fmemory_limit, 0, 0, 0, /*
|
801
|
4663 Return the address of the last byte XEmacs has allocated, divided by 1024.
|
|
4664 This may be helpful in debugging XEmacs's memory usage.
|
428
|
4665 The value is divided by 1024 to make sure it will fit in a lisp integer.
|
|
4666 */
|
|
4667 ())
|
|
4668 {
|
|
4669 return make_int ((EMACS_INT) sbrk (0) / 1024);
|
|
4670 }
|
440
|
4671 #endif
|
428
|
4672
|
2994
|
4673 DEFUN ("total-memory-usage", Ftotal_memory_usage, 0, 0, 0, /*
|
801
|
4674 Return the total number of bytes used by the data segment in XEmacs.
|
|
4675 This may be helpful in debugging XEmacs's memory usage.
|
2994
|
4676 NOTE: This may or may not be accurate! It is hard to determine this
|
|
4677 value in a system-independent fashion. On Windows, for example, the
|
|
4678 returned number tends to be much greater than reality.
|
801
|
4679 */
|
|
4680 ())
|
|
4681 {
|
|
4682 return make_int (total_data_usage ());
|
|
4683 }
|
|
4684
|
2994
|
4685 #ifdef ALLOC_TYPE_STATS
|
|
4686 DEFUN ("object-memory-usage", Fobject_memory_usage, 0, 0, 0, /*
|
|
4687 Return total number of bytes used for object storage in XEmacs.
|
|
4688 This may be helpful in debugging XEmacs's memory usage.
|
|
4689 See also `consing-since-gc' and `object-memory-usage-stats'.
|
|
4690 */
|
|
4691 ())
|
|
4692 {
|
|
4693 return make_int (total_gc_usage + consing_since_gc);
|
|
4694 }
|
|
4695 #endif /* ALLOC_TYPE_STATS */
|
|
4696
|
851
|
4697 void
|
|
4698 recompute_funcall_allocation_flag (void)
|
|
4699 {
|
887
|
4700 funcall_allocation_flag =
|
|
4701 need_to_garbage_collect ||
|
|
4702 need_to_check_c_alloca ||
|
|
4703 need_to_signal_post_gc;
|
851
|
4704 }
|
|
4705
|
428
|
4706
|
|
4707 int
|
|
4708 object_dead_p (Lisp_Object obj)
|
|
4709 {
|
|
4710 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) ||
|
|
4711 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) ||
|
|
4712 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) ||
|
|
4713 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) ||
|
|
4714 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) ||
|
|
4715 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) ||
|
|
4716 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj))));
|
|
4717 }
|
|
4718
|
|
4719 #ifdef MEMORY_USAGE_STATS
|
|
4720
|
|
4721 /* Attempt to determine the actual amount of space that is used for
|
|
4722 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE".
|
|
4723
|
|
4724 It seems that the following holds:
|
|
4725
|
|
4726 1. When using the old allocator (malloc.c):
|
|
4727
|
|
4728 -- blocks are always allocated in chunks of powers of two. For
|
|
4729 each block, there is an overhead of 8 bytes if rcheck is not
|
|
4730 defined, 20 bytes if it is defined. In other words, a
|
|
4731 one-byte allocation needs 8 bytes of overhead for a total of
|
|
4732 9 bytes, and needs to have 16 bytes of memory chunked out for
|
|
4733 it.
|
|
4734
|
|
4735 2. When using the new allocator (gmalloc.c):
|
|
4736
|
|
4737 -- blocks are always allocated in chunks of powers of two up
|
|
4738 to 4096 bytes. Larger blocks are allocated in chunks of
|
|
4739 an integral multiple of 4096 bytes. The minimum block
|
|
4740 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG
|
|
4741 is defined. There is no per-block overhead, but there
|
|
4742 is an overhead of 3*sizeof (size_t) for each 4096 bytes
|
|
4743 allocated.
|
|
4744
|
|
4745 3. When using the system malloc, anything goes, but they are
|
|
4746 generally slower and more space-efficient than the GNU
|
|
4747 allocators. One possibly reasonable assumption to make
|
|
4748 for want of better data is that sizeof (void *), or maybe
|
|
4749 2 * sizeof (void *), is required as overhead and that
|
|
4750 blocks are allocated in the minimum required size except
|
|
4751 that some minimum block size is imposed (e.g. 16 bytes). */
|
|
4752
|
665
|
4753 Bytecount
|
2286
|
4754 malloced_storage_size (void *UNUSED (ptr), Bytecount claimed_size,
|
428
|
4755 struct overhead_stats *stats)
|
|
4756 {
|
665
|
4757 Bytecount orig_claimed_size = claimed_size;
|
428
|
4758
|
|
4759 #ifdef GNU_MALLOC
|
665
|
4760 if (claimed_size < (Bytecount) (2 * sizeof (void *)))
|
428
|
4761 claimed_size = 2 * sizeof (void *);
|
|
4762 # ifdef SUNOS_LOCALTIME_BUG
|
|
4763 if (claimed_size < 16)
|
|
4764 claimed_size = 16;
|
|
4765 # endif
|
|
4766 if (claimed_size < 4096)
|
|
4767 {
|
2260
|
4768 /* fxg: rename log->log2 to supress gcc3 shadow warning */
|
|
4769 int log2 = 1;
|
428
|
4770
|
|
4771 /* compute the log base two, more or less, then use it to compute
|
|
4772 the block size needed. */
|
|
4773 claimed_size--;
|
|
4774 /* It's big, it's heavy, it's wood! */
|
|
4775 while ((claimed_size /= 2) != 0)
|
2260
|
4776 ++log2;
|
428
|
4777 claimed_size = 1;
|
|
4778 /* It's better than bad, it's good! */
|
2260
|
4779 while (log2 > 0)
|
428
|
4780 {
|
|
4781 claimed_size *= 2;
|
2260
|
4782 log2--;
|
428
|
4783 }
|
|
4784 /* We have to come up with some average about the amount of
|
|
4785 blocks used. */
|
665
|
4786 if ((Bytecount) (rand () & 4095) < claimed_size)
|
428
|
4787 claimed_size += 3 * sizeof (void *);
|
|
4788 }
|
|
4789 else
|
|
4790 {
|
|
4791 claimed_size += 4095;
|
|
4792 claimed_size &= ~4095;
|
|
4793 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t);
|
|
4794 }
|
|
4795
|
|
4796 #elif defined (SYSTEM_MALLOC)
|
|
4797
|
|
4798 if (claimed_size < 16)
|
|
4799 claimed_size = 16;
|
|
4800 claimed_size += 2 * sizeof (void *);
|
|
4801
|
|
4802 #else /* old GNU allocator */
|
|
4803
|
|
4804 # ifdef rcheck /* #### may not be defined here */
|
|
4805 claimed_size += 20;
|
|
4806 # else
|
|
4807 claimed_size += 8;
|
|
4808 # endif
|
|
4809 {
|
2260
|
4810 /* fxg: rename log->log2 to supress gcc3 shadow warning */
|
|
4811 int log2 = 1;
|
428
|
4812
|
|
4813 /* compute the log base two, more or less, then use it to compute
|
|
4814 the block size needed. */
|
|
4815 claimed_size--;
|
|
4816 /* It's big, it's heavy, it's wood! */
|
|
4817 while ((claimed_size /= 2) != 0)
|
2260
|
4818 ++log2;
|
428
|
4819 claimed_size = 1;
|
|
4820 /* It's better than bad, it's good! */
|
2260
|
4821 while (log2 > 0)
|
428
|
4822 {
|
|
4823 claimed_size *= 2;
|
2260
|
4824 log2--;
|
428
|
4825 }
|
|
4826 }
|
|
4827
|
|
4828 #endif /* old GNU allocator */
|
|
4829
|
|
4830 if (stats)
|
|
4831 {
|
|
4832 stats->was_requested += orig_claimed_size;
|
|
4833 stats->malloc_overhead += claimed_size - orig_claimed_size;
|
|
4834 }
|
|
4835 return claimed_size;
|
|
4836 }
|
|
4837
|
3263
|
4838 #ifndef NEW_GC
|
665
|
4839 Bytecount
|
|
4840 fixed_type_block_overhead (Bytecount size)
|
428
|
4841 {
|
665
|
4842 Bytecount per_block = TYPE_ALLOC_SIZE (cons, unsigned char);
|
|
4843 Bytecount overhead = 0;
|
|
4844 Bytecount storage_size = malloced_storage_size (0, per_block, 0);
|
428
|
4845 while (size >= per_block)
|
|
4846 {
|
|
4847 size -= per_block;
|
|
4848 overhead += sizeof (void *) + per_block - storage_size;
|
|
4849 }
|
|
4850 if (rand () % per_block < size)
|
|
4851 overhead += sizeof (void *) + per_block - storage_size;
|
|
4852 return overhead;
|
|
4853 }
|
3263
|
4854 #endif /* not NEW_GC */
|
428
|
4855 #endif /* MEMORY_USAGE_STATS */
|
|
4856
|
|
4857
|
|
4858 /* Initialization */
|
771
|
4859 static void
|
1204
|
4860 common_init_alloc_early (void)
|
428
|
4861 {
|
771
|
4862 #ifndef Qzero
|
|
4863 Qzero = make_int (0); /* Only used if Lisp_Object is a union type */
|
|
4864 #endif
|
|
4865
|
|
4866 #ifndef Qnull_pointer
|
|
4867 /* C guarantees that Qnull_pointer will be initialized to all 0 bits,
|
|
4868 so the following is actually a no-op. */
|
793
|
4869 Qnull_pointer = wrap_pointer_1 (0);
|
771
|
4870 #endif
|
|
4871
|
3263
|
4872 #ifndef NEW_GC
|
428
|
4873 breathing_space = 0;
|
|
4874 all_lcrecords = 0;
|
3263
|
4875 #endif /* not NEW_GC */
|
428
|
4876 ignore_malloc_warnings = 1;
|
|
4877 #ifdef DOUG_LEA_MALLOC
|
|
4878 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */
|
|
4879 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */
|
|
4880 #if 0 /* Moved to emacs.c */
|
|
4881 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */
|
|
4882 #endif
|
|
4883 #endif
|
3092
|
4884 #ifndef NEW_GC
|
2720
|
4885 init_string_chars_alloc ();
|
428
|
4886 init_string_alloc ();
|
|
4887 init_string_chars_alloc ();
|
|
4888 init_cons_alloc ();
|
|
4889 init_symbol_alloc ();
|
|
4890 init_compiled_function_alloc ();
|
|
4891 init_float_alloc ();
|
1983
|
4892 #ifdef HAVE_BIGNUM
|
|
4893 init_bignum_alloc ();
|
|
4894 #endif
|
|
4895 #ifdef HAVE_RATIO
|
|
4896 init_ratio_alloc ();
|
|
4897 #endif
|
|
4898 #ifdef HAVE_BIGFLOAT
|
|
4899 init_bigfloat_alloc ();
|
|
4900 #endif
|
428
|
4901 init_marker_alloc ();
|
|
4902 init_extent_alloc ();
|
|
4903 init_event_alloc ();
|
1204
|
4904 #ifdef EVENT_DATA_AS_OBJECTS
|
934
|
4905 init_key_data_alloc ();
|
|
4906 init_button_data_alloc ();
|
|
4907 init_motion_data_alloc ();
|
|
4908 init_process_data_alloc ();
|
|
4909 init_timeout_data_alloc ();
|
|
4910 init_magic_data_alloc ();
|
|
4911 init_magic_eval_data_alloc ();
|
|
4912 init_eval_data_alloc ();
|
|
4913 init_misc_user_data_alloc ();
|
1204
|
4914 #endif /* EVENT_DATA_AS_OBJECTS */
|
3263
|
4915 #endif /* not NEW_GC */
|
428
|
4916
|
|
4917 ignore_malloc_warnings = 0;
|
|
4918
|
452
|
4919 if (staticpros_nodump)
|
|
4920 Dynarr_free (staticpros_nodump);
|
|
4921 staticpros_nodump = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
|
|
4922 Dynarr_resize (staticpros_nodump, 100); /* merely a small optimization */
|
771
|
4923 #ifdef DEBUG_XEMACS
|
|
4924 if (staticpro_nodump_names)
|
|
4925 Dynarr_free (staticpro_nodump_names);
|
|
4926 staticpro_nodump_names = Dynarr_new2 (char_ptr_dynarr, char *);
|
|
4927 Dynarr_resize (staticpro_nodump_names, 100); /* ditto */
|
|
4928 #endif
|
428
|
4929
|
3263
|
4930 #ifdef NEW_GC
|
2720
|
4931 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object);
|
|
4932 Dynarr_resize (mcpros, 1410); /* merely a small optimization */
|
|
4933 dump_add_root_block_ptr (&mcpros, &mcpros_description);
|
|
4934 #ifdef DEBUG_XEMACS
|
|
4935 mcpro_names = Dynarr_new2 (char_ptr_dynarr, char *);
|
|
4936 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */
|
|
4937 dump_add_root_block_ptr (&mcpro_names, &mcpro_names_description);
|
|
4938 #endif
|
3263
|
4939 #endif /* NEW_GC */
|
2720
|
4940
|
428
|
4941 consing_since_gc = 0;
|
851
|
4942 need_to_check_c_alloca = 0;
|
|
4943 funcall_allocation_flag = 0;
|
|
4944 funcall_alloca_count = 0;
|
814
|
4945
|
428
|
4946 lrecord_uid_counter = 259;
|
3263
|
4947 #ifndef NEW_GC
|
428
|
4948 debug_string_purity = 0;
|
3263
|
4949 #endif /* not NEW_GC */
|
428
|
4950
|
800
|
4951 #ifdef ERROR_CHECK_TYPES
|
428
|
4952 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4953 666;
|
|
4954 ERROR_ME_NOT.
|
|
4955 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42;
|
|
4956 ERROR_ME_WARN.
|
|
4957 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4958 3333632;
|
793
|
4959 ERROR_ME_DEBUG_WARN.
|
|
4960 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure =
|
|
4961 8675309;
|
800
|
4962 #endif /* ERROR_CHECK_TYPES */
|
428
|
4963 }
|
|
4964
|
3263
|
4965 #ifndef NEW_GC
|
771
|
4966 static void
|
|
4967 init_lcrecord_lists (void)
|
|
4968 {
|
|
4969 int i;
|
|
4970
|
|
4971 for (i = 0; i < countof (lrecord_implementations_table); i++)
|
|
4972 {
|
|
4973 all_lcrecord_lists[i] = Qzero; /* Qnil not yet set */
|
|
4974 staticpro_nodump (&all_lcrecord_lists[i]);
|
|
4975 }
|
|
4976 }
|
3263
|
4977 #endif /* not NEW_GC */
|
771
|
4978
|
|
4979 void
|
1204
|
4980 init_alloc_early (void)
|
771
|
4981 {
|
1204
|
4982 #if defined (__cplusplus) && defined (ERROR_CHECK_GC)
|
|
4983 static struct gcpro initial_gcpro;
|
|
4984
|
|
4985 initial_gcpro.next = 0;
|
|
4986 initial_gcpro.var = &Qnil;
|
|
4987 initial_gcpro.nvars = 1;
|
|
4988 gcprolist = &initial_gcpro;
|
|
4989 #else
|
|
4990 gcprolist = 0;
|
|
4991 #endif /* defined (__cplusplus) && defined (ERROR_CHECK_GC) */
|
|
4992 }
|
|
4993
|
|
4994 void
|
|
4995 reinit_alloc_early (void)
|
|
4996 {
|
|
4997 common_init_alloc_early ();
|
3263
|
4998 #ifndef NEW_GC
|
771
|
4999 init_lcrecord_lists ();
|
3263
|
5000 #endif /* not NEW_GC */
|
771
|
5001 }
|
|
5002
|
428
|
5003 void
|
|
5004 init_alloc_once_early (void)
|
|
5005 {
|
1204
|
5006 common_init_alloc_early ();
|
428
|
5007
|
442
|
5008 {
|
|
5009 int i;
|
|
5010 for (i = 0; i < countof (lrecord_implementations_table); i++)
|
|
5011 lrecord_implementations_table[i] = 0;
|
|
5012 }
|
|
5013
|
|
5014 INIT_LRECORD_IMPLEMENTATION (cons);
|
|
5015 INIT_LRECORD_IMPLEMENTATION (vector);
|
|
5016 INIT_LRECORD_IMPLEMENTATION (string);
|
3092
|
5017 #ifdef NEW_GC
|
|
5018 INIT_LRECORD_IMPLEMENTATION (string_indirect_data);
|
|
5019 INIT_LRECORD_IMPLEMENTATION (string_direct_data);
|
|
5020 #endif /* NEW_GC */
|
3263
|
5021 #ifndef NEW_GC
|
442
|
5022 INIT_LRECORD_IMPLEMENTATION (lcrecord_list);
|
1204
|
5023 INIT_LRECORD_IMPLEMENTATION (free);
|
3263
|
5024 #endif /* not NEW_GC */
|
428
|
5025
|
452
|
5026 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *);
|
|
5027 Dynarr_resize (staticpros, 1410); /* merely a small optimization */
|
2367
|
5028 dump_add_root_block_ptr (&staticpros, &staticpros_description);
|
771
|
5029 #ifdef DEBUG_XEMACS
|
|
5030 staticpro_names = Dynarr_new2 (char_ptr_dynarr, char *);
|
|
5031 Dynarr_resize (staticpro_names, 1410); /* merely a small optimization */
|
2367
|
5032 dump_add_root_block_ptr (&staticpro_names, &staticpro_names_description);
|
771
|
5033 #endif
|
|
5034
|
3263
|
5035 #ifdef NEW_GC
|
2720
|
5036 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object);
|
|
5037 Dynarr_resize (mcpros, 1410); /* merely a small optimization */
|
|
5038 dump_add_root_block_ptr (&mcpros, &mcpros_description);
|
|
5039 #ifdef DEBUG_XEMACS
|
|
5040 mcpro_names = Dynarr_new2 (char_ptr_dynarr, char *);
|
|
5041 Dynarr_resize (mcpro_names, 1410); /* merely a small optimization */
|
|
5042 dump_add_root_block_ptr (&mcpro_names, &mcpro_names_description);
|
|
5043 #endif
|
3263
|
5044 #else /* not NEW_GC */
|
771
|
5045 init_lcrecord_lists ();
|
3263
|
5046 #endif /* not NEW_GC */
|
428
|
5047 }
|
|
5048
|
|
5049 void
|
|
5050 syms_of_alloc (void)
|
|
5051 {
|
442
|
5052 DEFSYMBOL (Qgarbage_collecting);
|
428
|
5053
|
|
5054 DEFSUBR (Fcons);
|
|
5055 DEFSUBR (Flist);
|
|
5056 DEFSUBR (Fvector);
|
|
5057 DEFSUBR (Fbit_vector);
|
|
5058 DEFSUBR (Fmake_byte_code);
|
|
5059 DEFSUBR (Fmake_list);
|
|
5060 DEFSUBR (Fmake_vector);
|
|
5061 DEFSUBR (Fmake_bit_vector);
|
|
5062 DEFSUBR (Fmake_string);
|
|
5063 DEFSUBR (Fstring);
|
|
5064 DEFSUBR (Fmake_symbol);
|
|
5065 DEFSUBR (Fmake_marker);
|
|
5066 DEFSUBR (Fpurecopy);
|
2994
|
5067 #ifdef ALLOC_TYPE_STATS
|
|
5068 DEFSUBR (Fobject_memory_usage_stats);
|
|
5069 DEFSUBR (Fobject_memory_usage);
|
|
5070 #endif /* ALLOC_TYPE_STATS */
|
428
|
5071 DEFSUBR (Fgarbage_collect);
|
440
|
5072 #if 0
|
428
|
5073 DEFSUBR (Fmemory_limit);
|
440
|
5074 #endif
|
2994
|
5075 DEFSUBR (Ftotal_memory_usage);
|
428
|
5076 DEFSUBR (Fconsing_since_gc);
|
|
5077 }
|
|
5078
|
|
5079 void
|
|
5080 vars_of_alloc (void)
|
|
5081 {
|
|
5082 #ifdef DEBUG_XEMACS
|
|
5083 DEFVAR_INT ("debug-allocation", &debug_allocation /*
|
|
5084 If non-zero, print out information to stderr about all objects allocated.
|
|
5085 See also `debug-allocation-backtrace-length'.
|
|
5086 */ );
|
|
5087 debug_allocation = 0;
|
|
5088
|
|
5089 DEFVAR_INT ("debug-allocation-backtrace-length",
|
|
5090 &debug_allocation_backtrace_length /*
|
|
5091 Length (in stack frames) of short backtrace printed out by `debug-allocation'.
|
|
5092 */ );
|
|
5093 debug_allocation_backtrace_length = 2;
|
|
5094 #endif
|
|
5095
|
|
5096 DEFVAR_BOOL ("purify-flag", &purify_flag /*
|
|
5097 Non-nil means loading Lisp code in order to dump an executable.
|
|
5098 This means that certain objects should be allocated in readonly space.
|
|
5099 */ );
|
|
5100 }
|