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