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