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