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