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