Mercurial > hg > xemacs-beta
annotate src/alloc.c @ 5125:b5df3737028a ben-lisp-object
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Feb 2010 01:58:04 -0600 |
parents | 623d57b7fbe8 2ade80e8c640 |
children | 2a462149bd6a |
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) |
1188 | |
1189 /* Like FREE_FIXED_TYPE() but used when we are explicitly | |
1190 freeing a structure through free_cons(), free_marker(), etc. | |
1191 rather than through the normal process of sweeping. | |
1192 We attempt to undo the changes made to the allocation counters | |
1193 as a result of this structure being allocated. This is not | |
1194 completely necessary but helps keep things saner: e.g. this way, | |
1195 repeatedly allocating and freeing a cons will not result in | |
1196 the consing-since-gc counter advancing, which would cause a GC | |
1204 | 1197 and somewhat defeat the purpose of explicitly freeing. |
1198 | |
1199 We also disable this mechanism entirely when ALLOC_NO_POOLS is | |
1200 set, which is used for Purify and the like. */ | |
1201 | |
1202 #ifndef ALLOC_NO_POOLS | |
428 | 1203 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr) \ |
1204 do { FREE_FIXED_TYPE (type, structtype, ptr); \ | |
1205 DECREMENT_CONS_COUNTER (sizeof (structtype)); \ | |
1206 gc_count_num_##type##_freelist++; \ | |
1207 } while (0) | |
1204 | 1208 #else |
1209 #define FREE_FIXED_TYPE_WHEN_NOT_IN_GC(type, structtype, ptr) | |
1210 #endif | |
3263 | 1211 #endif /* NEW_GC */ |
1212 | |
1213 #ifdef NEW_GC | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1214 #define ALLOCATE_FIXED_TYPE_AND_SET_IMPL(type, lisp_type, var, lrec_ptr)\ |
3017 | 1215 do { \ |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1216 (var) = (lisp_type *) XPNTR (ALLOC_LISP_OBJECT (type)); \ |
3017 | 1217 } while (0) |
1218 #define NOSEEUM_ALLOCATE_FIXED_TYPE_AND_SET_IMPL(type, lisp_type, var, \ | |
1219 lrec_ptr) \ | |
1220 do { \ | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1221 (var) = (lisp_type *) XPNTR (noseeum_alloc_lrecord (lrec_ptr)); \ |
3017 | 1222 } while (0) |
3263 | 1223 #else /* not NEW_GC */ |
3017 | 1224 #define ALLOCATE_FIXED_TYPE_AND_SET_IMPL(type, lisp_type, var, lrec_ptr) \ |
1225 do \ | |
1226 { \ | |
1227 ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
1228 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
1229 } while (0) | |
1230 #define NOSEEUM_ALLOCATE_FIXED_TYPE_AND_SET_IMPL(type, lisp_type, var, \ | |
1231 lrec_ptr) \ | |
1232 do \ | |
1233 { \ | |
1234 NOSEEUM_ALLOCATE_FIXED_TYPE (type, lisp_type, var); \ | |
1235 set_lheader_implementation (&(var)->lheader, lrec_ptr); \ | |
1236 } while (0) | |
3263 | 1237 #endif /* not NEW_GC */ |
3017 | 1238 |
428 | 1239 |
1240 | |
1241 /************************************************************************/ | |
1242 /* Cons allocation */ | |
1243 /************************************************************************/ | |
1244 | |
440 | 1245 DECLARE_FIXED_TYPE_ALLOC (cons, Lisp_Cons); |
428 | 1246 /* conses are used and freed so often that we set this really high */ |
1247 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 20000 */ | |
1248 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_cons 2000 | |
1249 | |
1250 static Lisp_Object | |
1251 mark_cons (Lisp_Object obj) | |
1252 { | |
1253 if (NILP (XCDR (obj))) | |
1254 return XCAR (obj); | |
1255 | |
1256 mark_object (XCAR (obj)); | |
1257 return XCDR (obj); | |
1258 } | |
1259 | |
1260 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
|
1261 cons_equal (Lisp_Object ob1, Lisp_Object ob2, int depth, int foldcase) |
428 | 1262 { |
442 | 1263 depth++; |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
1264 while (internal_equal_0 (XCAR (ob1), XCAR (ob2), depth, foldcase)) |
428 | 1265 { |
1266 ob1 = XCDR (ob1); | |
1267 ob2 = XCDR (ob2); | |
1268 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
|
1269 return internal_equal_0 (ob1, ob2, depth, foldcase); |
428 | 1270 } |
1271 return 0; | |
1272 } | |
1273 | |
1204 | 1274 static const struct memory_description cons_description[] = { |
853 | 1275 { XD_LISP_OBJECT, offsetof (Lisp_Cons, car_) }, |
1276 { XD_LISP_OBJECT, offsetof (Lisp_Cons, cdr_) }, | |
428 | 1277 { XD_END } |
1278 }; | |
1279 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1280 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
|
1281 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
|
1282 /* |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1283 * No `hash' method needed. |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1284 * internal_hash knows how to |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1285 * handle conses. |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1286 */ |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1287 0, cons_description, Lisp_Cons); |
428 | 1288 |
1289 DEFUN ("cons", Fcons, 2, 2, 0, /* | |
3355 | 1290 Create a new cons cell, give it CAR and CDR as components, and return it. |
1291 | |
1292 A cons cell is a Lisp object (an area in memory) made up of two pointers | |
1293 called the CAR and the CDR. Each of these pointers can point to any other | |
1294 Lisp object. The common Lisp data type, the list, is a specially-structured | |
1295 series of cons cells. | |
1296 | |
1297 The pointers are accessed from Lisp with `car' and `cdr', and mutated with | |
1298 `setcar' and `setcdr' respectively. For historical reasons, the aliases | |
1299 `rplaca' and `rplacd' (for `setcar' and `setcdr') are supported. | |
428 | 1300 */ |
1301 (car, cdr)) | |
1302 { | |
1303 /* This cannot GC. */ | |
1304 Lisp_Object val; | |
440 | 1305 Lisp_Cons *c; |
1306 | |
3017 | 1307 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (cons, Lisp_Cons, c, &lrecord_cons); |
793 | 1308 val = wrap_cons (c); |
853 | 1309 XSETCAR (val, car); |
1310 XSETCDR (val, cdr); | |
428 | 1311 return val; |
1312 } | |
1313 | |
1314 /* This is identical to Fcons() but it used for conses that we're | |
1315 going to free later, and is useful when trying to track down | |
1316 "real" consing. */ | |
1317 Lisp_Object | |
1318 noseeum_cons (Lisp_Object car, Lisp_Object cdr) | |
1319 { | |
1320 Lisp_Object val; | |
440 | 1321 Lisp_Cons *c; |
1322 | |
3017 | 1323 NOSEEUM_ALLOCATE_FIXED_TYPE_AND_SET_IMPL (cons, Lisp_Cons, c, &lrecord_cons); |
793 | 1324 val = wrap_cons (c); |
428 | 1325 XCAR (val) = car; |
1326 XCDR (val) = cdr; | |
1327 return val; | |
1328 } | |
1329 | |
1330 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
|
1331 Return a newly created list with specified ARGS as elements. |
428 | 1332 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
|
1333 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1334 arguments: (&rest ARGS) |
428 | 1335 */ |
1336 (int nargs, Lisp_Object *args)) | |
1337 { | |
1338 Lisp_Object val = Qnil; | |
1339 Lisp_Object *argp = args + nargs; | |
1340 | |
1341 while (argp > args) | |
1342 val = Fcons (*--argp, val); | |
1343 return val; | |
1344 } | |
1345 | |
1346 Lisp_Object | |
1347 list1 (Lisp_Object obj0) | |
1348 { | |
1349 /* This cannot GC. */ | |
1350 return Fcons (obj0, Qnil); | |
1351 } | |
1352 | |
1353 Lisp_Object | |
1354 list2 (Lisp_Object obj0, Lisp_Object obj1) | |
1355 { | |
1356 /* This cannot GC. */ | |
1357 return Fcons (obj0, Fcons (obj1, Qnil)); | |
1358 } | |
1359 | |
1360 Lisp_Object | |
1361 list3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1362 { | |
1363 /* This cannot GC. */ | |
1364 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Qnil))); | |
1365 } | |
1366 | |
1367 Lisp_Object | |
1368 cons3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1369 { | |
1370 /* This cannot GC. */ | |
1371 return Fcons (obj0, Fcons (obj1, obj2)); | |
1372 } | |
1373 | |
1374 Lisp_Object | |
1375 acons (Lisp_Object key, Lisp_Object value, Lisp_Object alist) | |
1376 { | |
1377 return Fcons (Fcons (key, value), alist); | |
1378 } | |
1379 | |
1380 Lisp_Object | |
1381 list4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3) | |
1382 { | |
1383 /* This cannot GC. */ | |
1384 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Qnil)))); | |
1385 } | |
1386 | |
1387 Lisp_Object | |
1388 list5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
1389 Lisp_Object obj4) | |
1390 { | |
1391 /* This cannot GC. */ | |
1392 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Qnil))))); | |
1393 } | |
1394 | |
1395 Lisp_Object | |
1396 list6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, Lisp_Object obj3, | |
1397 Lisp_Object obj4, Lisp_Object obj5) | |
1398 { | |
1399 /* This cannot GC. */ | |
1400 return Fcons (obj0, Fcons (obj1, Fcons (obj2, Fcons (obj3, Fcons (obj4, Fcons (obj5, Qnil)))))); | |
1401 } | |
1402 | |
1403 DEFUN ("make-list", Fmake_list, 2, 2, 0, /* | |
444 | 1404 Return a new list of length LENGTH, with each element being OBJECT. |
428 | 1405 */ |
444 | 1406 (length, object)) |
428 | 1407 { |
1408 CHECK_NATNUM (length); | |
1409 | |
1410 { | |
1411 Lisp_Object val = Qnil; | |
647 | 1412 EMACS_INT size = XINT (length); |
428 | 1413 |
1414 while (size--) | |
444 | 1415 val = Fcons (object, val); |
428 | 1416 return val; |
1417 } | |
1418 } | |
1419 | |
1420 | |
1421 /************************************************************************/ | |
1422 /* Float allocation */ | |
1423 /************************************************************************/ | |
1424 | |
1983 | 1425 /*** With enhanced number support, these are short floats */ |
1426 | |
440 | 1427 DECLARE_FIXED_TYPE_ALLOC (float, Lisp_Float); |
428 | 1428 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_float 1000 |
1429 | |
1430 Lisp_Object | |
1431 make_float (double float_value) | |
1432 { | |
440 | 1433 Lisp_Float *f; |
1434 | |
3017 | 1435 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (float, Lisp_Float, f, &lrecord_float); |
440 | 1436 |
1437 /* Avoid dump-time `uninitialized memory read' purify warnings. */ | |
1438 if (sizeof (struct lrecord_header) + sizeof (double) != sizeof (*f)) | |
3017 | 1439 zero_lrecord (f); |
1440 | |
428 | 1441 float_data (f) = float_value; |
793 | 1442 return wrap_float (f); |
428 | 1443 } |
1444 | |
1445 | |
1446 /************************************************************************/ | |
1983 | 1447 /* Enhanced number allocation */ |
1448 /************************************************************************/ | |
1449 | |
1450 /*** Bignum ***/ | |
1451 #ifdef HAVE_BIGNUM | |
1452 DECLARE_FIXED_TYPE_ALLOC (bignum, Lisp_Bignum); | |
1453 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bignum 250 | |
1454 | |
1455 /* WARNING: This function returns a bignum even if its argument fits into a | |
1456 fixnum. See Fcanonicalize_number(). */ | |
1457 Lisp_Object | |
1458 make_bignum (long bignum_value) | |
1459 { | |
1460 Lisp_Bignum *b; | |
1461 | |
3017 | 1462 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bignum, Lisp_Bignum, b, &lrecord_bignum); |
1983 | 1463 bignum_init (bignum_data (b)); |
1464 bignum_set_long (bignum_data (b), bignum_value); | |
1465 return wrap_bignum (b); | |
1466 } | |
1467 | |
1468 /* WARNING: This function returns a bignum even if its argument fits into a | |
1469 fixnum. See Fcanonicalize_number(). */ | |
1470 Lisp_Object | |
1471 make_bignum_bg (bignum bg) | |
1472 { | |
1473 Lisp_Bignum *b; | |
1474 | |
3017 | 1475 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bignum, Lisp_Bignum, b, &lrecord_bignum); |
1983 | 1476 bignum_init (bignum_data (b)); |
1477 bignum_set (bignum_data (b), bg); | |
1478 return wrap_bignum (b); | |
1479 } | |
1480 #endif /* HAVE_BIGNUM */ | |
1481 | |
1482 /*** Ratio ***/ | |
1483 #ifdef HAVE_RATIO | |
1484 DECLARE_FIXED_TYPE_ALLOC (ratio, Lisp_Ratio); | |
1485 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_ratio 250 | |
1486 | |
1487 Lisp_Object | |
1488 make_ratio (long numerator, unsigned long denominator) | |
1489 { | |
1490 Lisp_Ratio *r; | |
1491 | |
3017 | 1492 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1493 ratio_init (ratio_data (r)); |
1494 ratio_set_long_ulong (ratio_data (r), numerator, denominator); | |
1495 ratio_canonicalize (ratio_data (r)); | |
1496 return wrap_ratio (r); | |
1497 } | |
1498 | |
1499 Lisp_Object | |
1500 make_ratio_bg (bignum numerator, bignum denominator) | |
1501 { | |
1502 Lisp_Ratio *r; | |
1503 | |
3017 | 1504 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1505 ratio_init (ratio_data (r)); |
1506 ratio_set_bignum_bignum (ratio_data (r), numerator, denominator); | |
1507 ratio_canonicalize (ratio_data (r)); | |
1508 return wrap_ratio (r); | |
1509 } | |
1510 | |
1511 Lisp_Object | |
1512 make_ratio_rt (ratio rat) | |
1513 { | |
1514 Lisp_Ratio *r; | |
1515 | |
3017 | 1516 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (ratio, Lisp_Ratio, r, &lrecord_ratio); |
1983 | 1517 ratio_init (ratio_data (r)); |
1518 ratio_set (ratio_data (r), rat); | |
1519 return wrap_ratio (r); | |
1520 } | |
1521 #endif /* HAVE_RATIO */ | |
1522 | |
1523 /*** Bigfloat ***/ | |
1524 #ifdef HAVE_BIGFLOAT | |
1525 DECLARE_FIXED_TYPE_ALLOC (bigfloat, Lisp_Bigfloat); | |
1526 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_bigfloat 250 | |
1527 | |
1528 /* This function creates a bigfloat with the default precision if the | |
1529 PRECISION argument is zero. */ | |
1530 Lisp_Object | |
1531 make_bigfloat (double float_value, unsigned long precision) | |
1532 { | |
1533 Lisp_Bigfloat *f; | |
1534 | |
3017 | 1535 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
1983 | 1536 if (precision == 0UL) |
1537 bigfloat_init (bigfloat_data (f)); | |
1538 else | |
1539 bigfloat_init_prec (bigfloat_data (f), precision); | |
1540 bigfloat_set_double (bigfloat_data (f), float_value); | |
1541 return wrap_bigfloat (f); | |
1542 } | |
1543 | |
1544 /* This function creates a bigfloat with the precision of its argument */ | |
1545 Lisp_Object | |
1546 make_bigfloat_bf (bigfloat float_value) | |
1547 { | |
1548 Lisp_Bigfloat *f; | |
1549 | |
3017 | 1550 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (bigfloat, Lisp_Bigfloat, f, &lrecord_bigfloat); |
1983 | 1551 bigfloat_init_prec (bigfloat_data (f), bigfloat_get_prec (float_value)); |
1552 bigfloat_set (bigfloat_data (f), float_value); | |
1553 return wrap_bigfloat (f); | |
1554 } | |
1555 #endif /* HAVE_BIGFLOAT */ | |
1556 | |
1557 /************************************************************************/ | |
428 | 1558 /* Vector allocation */ |
1559 /************************************************************************/ | |
1560 | |
1561 static Lisp_Object | |
1562 mark_vector (Lisp_Object obj) | |
1563 { | |
1564 Lisp_Vector *ptr = XVECTOR (obj); | |
1565 int len = vector_length (ptr); | |
1566 int i; | |
1567 | |
1568 for (i = 0; i < len - 1; i++) | |
1569 mark_object (ptr->contents[i]); | |
1570 return (len > 0) ? ptr->contents[len - 1] : Qnil; | |
1571 } | |
1572 | |
665 | 1573 static Bytecount |
442 | 1574 size_vector (const void *lheader) |
428 | 1575 { |
456 | 1576 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, contents, |
442 | 1577 ((Lisp_Vector *) lheader)->size); |
428 | 1578 } |
1579 | |
1580 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
|
1581 vector_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase) |
428 | 1582 { |
1583 int len = XVECTOR_LENGTH (obj1); | |
1584 if (len != XVECTOR_LENGTH (obj2)) | |
1585 return 0; | |
1586 | |
1587 { | |
1588 Lisp_Object *ptr1 = XVECTOR_DATA (obj1); | |
1589 Lisp_Object *ptr2 = XVECTOR_DATA (obj2); | |
1590 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
|
1591 if (!internal_equal_0 (*ptr1++, *ptr2++, depth + 1, foldcase)) |
428 | 1592 return 0; |
1593 } | |
1594 return 1; | |
1595 } | |
1596 | |
665 | 1597 static Hashcode |
442 | 1598 vector_hash (Lisp_Object obj, int depth) |
1599 { | |
1600 return HASH2 (XVECTOR_LENGTH (obj), | |
1601 internal_array_hash (XVECTOR_DATA (obj), | |
1602 XVECTOR_LENGTH (obj), | |
1603 depth + 1)); | |
1604 } | |
1605 | |
1204 | 1606 static const struct memory_description vector_description[] = { |
440 | 1607 { XD_LONG, offsetof (Lisp_Vector, size) }, |
1608 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Vector, contents), XD_INDIRECT(0, 0) }, | |
428 | 1609 { XD_END } |
1610 }; | |
1611 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1612 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
|
1613 mark_vector, print_vector, 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1614 vector_equal, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1615 vector_hash, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1616 vector_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
1617 size_vector, Lisp_Vector); |
428 | 1618 /* #### should allocate `small' vectors from a frob-block */ |
1619 static Lisp_Vector * | |
665 | 1620 make_vector_internal (Elemcount sizei) |
428 | 1621 { |
1204 | 1622 /* no `next' field; we use lcrecords */ |
665 | 1623 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Vector, Lisp_Object, |
1204 | 1624 contents, sizei); |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1625 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
|
1626 Lisp_Vector *p = XVECTOR (obj); |
428 | 1627 |
1628 p->size = sizei; | |
1629 return p; | |
1630 } | |
1631 | |
1632 Lisp_Object | |
665 | 1633 make_vector (Elemcount length, Lisp_Object object) |
428 | 1634 { |
1635 Lisp_Vector *vecp = make_vector_internal (length); | |
1636 Lisp_Object *p = vector_data (vecp); | |
1637 | |
1638 while (length--) | |
444 | 1639 *p++ = object; |
428 | 1640 |
793 | 1641 return wrap_vector (vecp); |
428 | 1642 } |
1643 | |
1644 DEFUN ("make-vector", Fmake_vector, 2, 2, 0, /* | |
444 | 1645 Return a new vector of length LENGTH, with each element being OBJECT. |
428 | 1646 See also the function `vector'. |
1647 */ | |
444 | 1648 (length, object)) |
428 | 1649 { |
1650 CONCHECK_NATNUM (length); | |
444 | 1651 return make_vector (XINT (length), object); |
428 | 1652 } |
1653 | |
1654 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
|
1655 Return a newly created vector with specified ARGS as elements. |
428 | 1656 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
|
1657 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1658 arguments: (&rest ARGS) |
428 | 1659 */ |
1660 (int nargs, Lisp_Object *args)) | |
1661 { | |
1662 Lisp_Vector *vecp = make_vector_internal (nargs); | |
1663 Lisp_Object *p = vector_data (vecp); | |
1664 | |
1665 while (nargs--) | |
1666 *p++ = *args++; | |
1667 | |
793 | 1668 return wrap_vector (vecp); |
428 | 1669 } |
1670 | |
1671 Lisp_Object | |
1672 vector1 (Lisp_Object obj0) | |
1673 { | |
1674 return Fvector (1, &obj0); | |
1675 } | |
1676 | |
1677 Lisp_Object | |
1678 vector2 (Lisp_Object obj0, Lisp_Object obj1) | |
1679 { | |
1680 Lisp_Object args[2]; | |
1681 args[0] = obj0; | |
1682 args[1] = obj1; | |
1683 return Fvector (2, args); | |
1684 } | |
1685 | |
1686 Lisp_Object | |
1687 vector3 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2) | |
1688 { | |
1689 Lisp_Object args[3]; | |
1690 args[0] = obj0; | |
1691 args[1] = obj1; | |
1692 args[2] = obj2; | |
1693 return Fvector (3, args); | |
1694 } | |
1695 | |
1696 #if 0 /* currently unused */ | |
1697 | |
1698 Lisp_Object | |
1699 vector4 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1700 Lisp_Object obj3) | |
1701 { | |
1702 Lisp_Object args[4]; | |
1703 args[0] = obj0; | |
1704 args[1] = obj1; | |
1705 args[2] = obj2; | |
1706 args[3] = obj3; | |
1707 return Fvector (4, args); | |
1708 } | |
1709 | |
1710 Lisp_Object | |
1711 vector5 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1712 Lisp_Object obj3, Lisp_Object obj4) | |
1713 { | |
1714 Lisp_Object args[5]; | |
1715 args[0] = obj0; | |
1716 args[1] = obj1; | |
1717 args[2] = obj2; | |
1718 args[3] = obj3; | |
1719 args[4] = obj4; | |
1720 return Fvector (5, args); | |
1721 } | |
1722 | |
1723 Lisp_Object | |
1724 vector6 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1725 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5) | |
1726 { | |
1727 Lisp_Object args[6]; | |
1728 args[0] = obj0; | |
1729 args[1] = obj1; | |
1730 args[2] = obj2; | |
1731 args[3] = obj3; | |
1732 args[4] = obj4; | |
1733 args[5] = obj5; | |
1734 return Fvector (6, args); | |
1735 } | |
1736 | |
1737 Lisp_Object | |
1738 vector7 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1739 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
1740 Lisp_Object obj6) | |
1741 { | |
1742 Lisp_Object args[7]; | |
1743 args[0] = obj0; | |
1744 args[1] = obj1; | |
1745 args[2] = obj2; | |
1746 args[3] = obj3; | |
1747 args[4] = obj4; | |
1748 args[5] = obj5; | |
1749 args[6] = obj6; | |
1750 return Fvector (7, args); | |
1751 } | |
1752 | |
1753 Lisp_Object | |
1754 vector8 (Lisp_Object obj0, Lisp_Object obj1, Lisp_Object obj2, | |
1755 Lisp_Object obj3, Lisp_Object obj4, Lisp_Object obj5, | |
1756 Lisp_Object obj6, Lisp_Object obj7) | |
1757 { | |
1758 Lisp_Object args[8]; | |
1759 args[0] = obj0; | |
1760 args[1] = obj1; | |
1761 args[2] = obj2; | |
1762 args[3] = obj3; | |
1763 args[4] = obj4; | |
1764 args[5] = obj5; | |
1765 args[6] = obj6; | |
1766 args[7] = obj7; | |
1767 return Fvector (8, args); | |
1768 } | |
1769 #endif /* unused */ | |
1770 | |
1771 /************************************************************************/ | |
1772 /* Bit Vector allocation */ | |
1773 /************************************************************************/ | |
1774 | |
1775 /* #### should allocate `small' bit vectors from a frob-block */ | |
440 | 1776 static Lisp_Bit_Vector * |
665 | 1777 make_bit_vector_internal (Elemcount sizei) |
428 | 1778 { |
1204 | 1779 /* no `next' field; we use lcrecords */ |
665 | 1780 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (sizei); |
1781 Bytecount sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Bit_Vector, | |
1204 | 1782 unsigned long, |
1783 bits, num_longs); | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
1784 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
|
1785 Lisp_Bit_Vector *p = XBIT_VECTOR (obj); |
428 | 1786 |
1787 bit_vector_length (p) = sizei; | |
1788 return p; | |
1789 } | |
1790 | |
1791 Lisp_Object | |
665 | 1792 make_bit_vector (Elemcount length, Lisp_Object bit) |
428 | 1793 { |
440 | 1794 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
665 | 1795 Elemcount num_longs = BIT_VECTOR_LONG_STORAGE (length); |
428 | 1796 |
444 | 1797 CHECK_BIT (bit); |
1798 | |
1799 if (ZEROP (bit)) | |
428 | 1800 memset (p->bits, 0, num_longs * sizeof (long)); |
1801 else | |
1802 { | |
665 | 1803 Elemcount bits_in_last = length & (LONGBITS_POWER_OF_2 - 1); |
428 | 1804 memset (p->bits, ~0, num_longs * sizeof (long)); |
1805 /* But we have to make sure that the unused bits in the | |
1806 last long are 0, so that equal/hash is easy. */ | |
1807 if (bits_in_last) | |
1808 p->bits[num_longs - 1] &= (1 << bits_in_last) - 1; | |
1809 } | |
1810 | |
793 | 1811 return wrap_bit_vector (p); |
428 | 1812 } |
1813 | |
1814 Lisp_Object | |
665 | 1815 make_bit_vector_from_byte_vector (unsigned char *bytevec, Elemcount length) |
428 | 1816 { |
665 | 1817 Elemcount i; |
428 | 1818 Lisp_Bit_Vector *p = make_bit_vector_internal (length); |
1819 | |
1820 for (i = 0; i < length; i++) | |
1821 set_bit_vector_bit (p, i, bytevec[i]); | |
1822 | |
793 | 1823 return wrap_bit_vector (p); |
428 | 1824 } |
1825 | |
1826 DEFUN ("make-bit-vector", Fmake_bit_vector, 2, 2, 0, /* | |
444 | 1827 Return a new bit vector of length LENGTH. with each bit set to BIT. |
1828 BIT must be one of the integers 0 or 1. See also the function `bit-vector'. | |
428 | 1829 */ |
444 | 1830 (length, bit)) |
428 | 1831 { |
1832 CONCHECK_NATNUM (length); | |
1833 | |
444 | 1834 return make_bit_vector (XINT (length), bit); |
428 | 1835 } |
1836 | |
1837 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
|
1838 Return a newly created bit vector with specified ARGS as elements. |
428 | 1839 Any number of arguments, even zero arguments, are allowed. |
444 | 1840 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
|
1841 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1842 arguments: (&rest ARGS) |
428 | 1843 */ |
1844 (int nargs, Lisp_Object *args)) | |
1845 { | |
1846 int i; | |
1847 Lisp_Bit_Vector *p = make_bit_vector_internal (nargs); | |
1848 | |
1849 for (i = 0; i < nargs; i++) | |
1850 { | |
1851 CHECK_BIT (args[i]); | |
1852 set_bit_vector_bit (p, i, !ZEROP (args[i])); | |
1853 } | |
1854 | |
793 | 1855 return wrap_bit_vector (p); |
428 | 1856 } |
1857 | |
1858 | |
1859 /************************************************************************/ | |
1860 /* Compiled-function allocation */ | |
1861 /************************************************************************/ | |
1862 | |
1863 DECLARE_FIXED_TYPE_ALLOC (compiled_function, Lisp_Compiled_Function); | |
1864 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_compiled_function 1000 | |
1865 | |
1866 static Lisp_Object | |
1867 make_compiled_function (void) | |
1868 { | |
1869 Lisp_Compiled_Function *f; | |
1870 | |
3017 | 1871 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (compiled_function, Lisp_Compiled_Function, |
1872 f, &lrecord_compiled_function); | |
428 | 1873 |
1874 f->stack_depth = 0; | |
1875 f->specpdl_depth = 0; | |
1876 f->flags.documentationp = 0; | |
1877 f->flags.interactivep = 0; | |
1878 f->flags.domainp = 0; /* I18N3 */ | |
1879 f->instructions = Qzero; | |
1880 f->constants = Qzero; | |
1881 f->arglist = Qnil; | |
3092 | 1882 #ifdef NEW_GC |
1883 f->arguments = Qnil; | |
1884 #else /* not NEW_GC */ | |
1739 | 1885 f->args = NULL; |
3092 | 1886 #endif /* not NEW_GC */ |
1739 | 1887 f->max_args = f->min_args = f->args_in_array = 0; |
428 | 1888 f->doc_and_interactive = Qnil; |
1889 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
1890 f->annotated = Qnil; | |
1891 #endif | |
793 | 1892 return wrap_compiled_function (f); |
428 | 1893 } |
1894 | |
1895 DEFUN ("make-byte-code", Fmake_byte_code, 4, MANY, 0, /* | |
1896 Return a new compiled-function object. | |
1897 Note that, unlike all other emacs-lisp functions, calling this with five | |
1898 arguments is NOT the same as calling it with six arguments, the last of | |
1899 which is nil. If the INTERACTIVE arg is specified as nil, then that means | |
1900 that this function was defined with `(interactive)'. If the arg is not | |
1901 specified, then that means the function is not interactive. | |
1902 This is terrible behavior which is retained for compatibility with old | |
1903 `.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
|
1904 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
1905 arguments: (ARGLIST INSTRUCTIONS CONSTANTS STACK-DEPTH &optional DOC-STRING INTERACTIVE) |
428 | 1906 */ |
1907 (int nargs, Lisp_Object *args)) | |
1908 { | |
1909 /* In a non-insane world this function would have this arglist... | |
1910 (arglist instructions constants stack_depth &optional doc_string interactive) | |
1911 */ | |
1912 Lisp_Object fun = make_compiled_function (); | |
1913 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun); | |
1914 | |
1915 Lisp_Object arglist = args[0]; | |
1916 Lisp_Object instructions = args[1]; | |
1917 Lisp_Object constants = args[2]; | |
1918 Lisp_Object stack_depth = args[3]; | |
1919 Lisp_Object doc_string = (nargs > 4) ? args[4] : Qnil; | |
1920 Lisp_Object interactive = (nargs > 5) ? args[5] : Qunbound; | |
1921 | |
1922 if (nargs < 4 || nargs > 6) | |
1923 return Fsignal (Qwrong_number_of_arguments, | |
1924 list2 (intern ("make-byte-code"), make_int (nargs))); | |
1925 | |
1926 /* Check for valid formal parameter list now, to allow us to use | |
1927 SPECBIND_FAST_UNSAFE() later in funcall_compiled_function(). */ | |
1928 { | |
814 | 1929 EXTERNAL_LIST_LOOP_2 (symbol, arglist) |
428 | 1930 { |
1931 CHECK_SYMBOL (symbol); | |
1932 if (EQ (symbol, Qt) || | |
1933 EQ (symbol, Qnil) || | |
1934 SYMBOL_IS_KEYWORD (symbol)) | |
563 | 1935 invalid_constant_2 |
428 | 1936 ("Invalid constant symbol in formal parameter list", |
1937 symbol, arglist); | |
1938 } | |
1939 } | |
1940 f->arglist = arglist; | |
1941 | |
1942 /* `instructions' is a string or a cons (string . int) for a | |
1943 lazy-loaded function. */ | |
1944 if (CONSP (instructions)) | |
1945 { | |
1946 CHECK_STRING (XCAR (instructions)); | |
1947 CHECK_INT (XCDR (instructions)); | |
1948 } | |
1949 else | |
1950 { | |
1951 CHECK_STRING (instructions); | |
1952 } | |
1953 f->instructions = instructions; | |
1954 | |
1955 if (!NILP (constants)) | |
1956 CHECK_VECTOR (constants); | |
1957 f->constants = constants; | |
1958 | |
1959 CHECK_NATNUM (stack_depth); | |
442 | 1960 f->stack_depth = (unsigned short) XINT (stack_depth); |
428 | 1961 |
1962 #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
|
1963 f->annotated = Vload_file_name_internal; |
428 | 1964 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ |
1965 | |
1966 /* doc_string may be nil, string, int, or a cons (string . int). | |
1967 interactive may be list or string (or unbound). */ | |
1968 f->doc_and_interactive = Qunbound; | |
1969 #ifdef I18N3 | |
1970 if ((f->flags.domainp = !NILP (Vfile_domain)) != 0) | |
1971 f->doc_and_interactive = Vfile_domain; | |
1972 #endif | |
1973 if ((f->flags.interactivep = !UNBOUNDP (interactive)) != 0) | |
1974 { | |
1975 f->doc_and_interactive | |
1976 = (UNBOUNDP (f->doc_and_interactive) ? interactive : | |
1977 Fcons (interactive, f->doc_and_interactive)); | |
1978 } | |
1979 if ((f->flags.documentationp = !NILP (doc_string)) != 0) | |
1980 { | |
1981 f->doc_and_interactive | |
1982 = (UNBOUNDP (f->doc_and_interactive) ? doc_string : | |
1983 Fcons (doc_string, f->doc_and_interactive)); | |
1984 } | |
1985 if (UNBOUNDP (f->doc_and_interactive)) | |
1986 f->doc_and_interactive = Qnil; | |
1987 | |
1988 return fun; | |
1989 } | |
1990 | |
1991 | |
1992 /************************************************************************/ | |
1993 /* Symbol allocation */ | |
1994 /************************************************************************/ | |
1995 | |
440 | 1996 DECLARE_FIXED_TYPE_ALLOC (symbol, Lisp_Symbol); |
428 | 1997 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_symbol 1000 |
1998 | |
1999 DEFUN ("make-symbol", Fmake_symbol, 1, 1, 0, /* | |
2000 Return a newly allocated uninterned symbol whose name is NAME. | |
2001 Its value and function definition are void, and its property list is nil. | |
2002 */ | |
2003 (name)) | |
2004 { | |
440 | 2005 Lisp_Symbol *p; |
428 | 2006 |
2007 CHECK_STRING (name); | |
2008 | |
3017 | 2009 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (symbol, Lisp_Symbol, p, &lrecord_symbol); |
793 | 2010 p->name = name; |
428 | 2011 p->plist = Qnil; |
2012 p->value = Qunbound; | |
2013 p->function = Qunbound; | |
2014 symbol_next (p) = 0; | |
793 | 2015 return wrap_symbol (p); |
428 | 2016 } |
2017 | |
2018 | |
2019 /************************************************************************/ | |
2020 /* Extent allocation */ | |
2021 /************************************************************************/ | |
2022 | |
2023 DECLARE_FIXED_TYPE_ALLOC (extent, struct extent); | |
2024 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_extent 1000 | |
2025 | |
2026 struct extent * | |
2027 allocate_extent (void) | |
2028 { | |
2029 struct extent *e; | |
2030 | |
3017 | 2031 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (extent, struct extent, e, &lrecord_extent); |
428 | 2032 extent_object (e) = Qnil; |
2033 set_extent_start (e, -1); | |
2034 set_extent_end (e, -1); | |
2035 e->plist = Qnil; | |
2036 | |
2037 xzero (e->flags); | |
2038 | |
2039 extent_face (e) = Qnil; | |
2040 e->flags.end_open = 1; /* default is for endpoints to behave like markers */ | |
2041 e->flags.detachable = 1; | |
2042 | |
2043 return e; | |
2044 } | |
2045 | |
2046 | |
2047 /************************************************************************/ | |
2048 /* Event allocation */ | |
2049 /************************************************************************/ | |
2050 | |
440 | 2051 DECLARE_FIXED_TYPE_ALLOC (event, Lisp_Event); |
428 | 2052 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_event 1000 |
2053 | |
2054 Lisp_Object | |
2055 allocate_event (void) | |
2056 { | |
440 | 2057 Lisp_Event *e; |
2058 | |
3017 | 2059 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (event, Lisp_Event, e, &lrecord_event); |
428 | 2060 |
793 | 2061 return wrap_event (e); |
428 | 2062 } |
2063 | |
1204 | 2064 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 2065 DECLARE_FIXED_TYPE_ALLOC (key_data, Lisp_Key_Data); |
2066 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_key_data 1000 | |
2067 | |
2068 Lisp_Object | |
1204 | 2069 make_key_data (void) |
934 | 2070 { |
2071 Lisp_Key_Data *d; | |
2072 | |
3017 | 2073 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (key_data, Lisp_Key_Data, d, |
2074 &lrecord_key_data); | |
2075 zero_lrecord (d); | |
1204 | 2076 d->keysym = Qnil; |
2077 | |
2078 return wrap_key_data (d); | |
934 | 2079 } |
2080 | |
2081 DECLARE_FIXED_TYPE_ALLOC (button_data, Lisp_Button_Data); | |
2082 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_button_data 1000 | |
2083 | |
2084 Lisp_Object | |
1204 | 2085 make_button_data (void) |
934 | 2086 { |
2087 Lisp_Button_Data *d; | |
2088 | |
3017 | 2089 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (button_data, Lisp_Button_Data, d, &lrecord_button_data); |
2090 zero_lrecord (d); | |
1204 | 2091 return wrap_button_data (d); |
934 | 2092 } |
2093 | |
2094 DECLARE_FIXED_TYPE_ALLOC (motion_data, Lisp_Motion_Data); | |
2095 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_motion_data 1000 | |
2096 | |
2097 Lisp_Object | |
1204 | 2098 make_motion_data (void) |
934 | 2099 { |
2100 Lisp_Motion_Data *d; | |
2101 | |
3017 | 2102 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (motion_data, Lisp_Motion_Data, d, &lrecord_motion_data); |
2103 zero_lrecord (d); | |
934 | 2104 |
1204 | 2105 return wrap_motion_data (d); |
934 | 2106 } |
2107 | |
2108 DECLARE_FIXED_TYPE_ALLOC (process_data, Lisp_Process_Data); | |
2109 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_process_data 1000 | |
2110 | |
2111 Lisp_Object | |
1204 | 2112 make_process_data (void) |
934 | 2113 { |
2114 Lisp_Process_Data *d; | |
2115 | |
3017 | 2116 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (process_data, Lisp_Process_Data, d, &lrecord_process_data); |
2117 zero_lrecord (d); | |
1204 | 2118 d->process = Qnil; |
2119 | |
2120 return wrap_process_data (d); | |
934 | 2121 } |
2122 | |
2123 DECLARE_FIXED_TYPE_ALLOC (timeout_data, Lisp_Timeout_Data); | |
2124 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_timeout_data 1000 | |
2125 | |
2126 Lisp_Object | |
1204 | 2127 make_timeout_data (void) |
934 | 2128 { |
2129 Lisp_Timeout_Data *d; | |
2130 | |
3017 | 2131 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (timeout_data, Lisp_Timeout_Data, d, &lrecord_timeout_data); |
2132 zero_lrecord (d); | |
1204 | 2133 d->function = Qnil; |
2134 d->object = Qnil; | |
2135 | |
2136 return wrap_timeout_data (d); | |
934 | 2137 } |
2138 | |
2139 DECLARE_FIXED_TYPE_ALLOC (magic_data, Lisp_Magic_Data); | |
2140 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_data 1000 | |
2141 | |
2142 Lisp_Object | |
1204 | 2143 make_magic_data (void) |
934 | 2144 { |
2145 Lisp_Magic_Data *d; | |
2146 | |
3017 | 2147 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (magic_data, Lisp_Magic_Data, d, &lrecord_magic_data); |
2148 zero_lrecord (d); | |
934 | 2149 |
1204 | 2150 return wrap_magic_data (d); |
934 | 2151 } |
2152 | |
2153 DECLARE_FIXED_TYPE_ALLOC (magic_eval_data, Lisp_Magic_Eval_Data); | |
2154 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_magic_eval_data 1000 | |
2155 | |
2156 Lisp_Object | |
1204 | 2157 make_magic_eval_data (void) |
934 | 2158 { |
2159 Lisp_Magic_Eval_Data *d; | |
2160 | |
3017 | 2161 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (magic_eval_data, Lisp_Magic_Eval_Data, d, &lrecord_magic_eval_data); |
2162 zero_lrecord (d); | |
1204 | 2163 d->object = Qnil; |
2164 | |
2165 return wrap_magic_eval_data (d); | |
934 | 2166 } |
2167 | |
2168 DECLARE_FIXED_TYPE_ALLOC (eval_data, Lisp_Eval_Data); | |
2169 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_eval_data 1000 | |
2170 | |
2171 Lisp_Object | |
1204 | 2172 make_eval_data (void) |
934 | 2173 { |
2174 Lisp_Eval_Data *d; | |
2175 | |
3017 | 2176 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (eval_data, Lisp_Eval_Data, d, &lrecord_eval_data); |
2177 zero_lrecord (d); | |
1204 | 2178 d->function = Qnil; |
2179 d->object = Qnil; | |
2180 | |
2181 return wrap_eval_data (d); | |
934 | 2182 } |
2183 | |
2184 DECLARE_FIXED_TYPE_ALLOC (misc_user_data, Lisp_Misc_User_Data); | |
2185 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_misc_user_data 1000 | |
2186 | |
2187 Lisp_Object | |
1204 | 2188 make_misc_user_data (void) |
934 | 2189 { |
2190 Lisp_Misc_User_Data *d; | |
2191 | |
3017 | 2192 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (misc_user_data, Lisp_Misc_User_Data, d, &lrecord_misc_user_data); |
2193 zero_lrecord (d); | |
1204 | 2194 d->function = Qnil; |
2195 d->object = Qnil; | |
2196 | |
2197 return wrap_misc_user_data (d); | |
934 | 2198 } |
1204 | 2199 |
2200 #endif /* EVENT_DATA_AS_OBJECTS */ | |
428 | 2201 |
2202 /************************************************************************/ | |
2203 /* Marker allocation */ | |
2204 /************************************************************************/ | |
2205 | |
440 | 2206 DECLARE_FIXED_TYPE_ALLOC (marker, Lisp_Marker); |
428 | 2207 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_marker 1000 |
2208 | |
2209 DEFUN ("make-marker", Fmake_marker, 0, 0, 0, /* | |
2210 Return a new marker which does not point at any place. | |
2211 */ | |
2212 ()) | |
2213 { | |
440 | 2214 Lisp_Marker *p; |
2215 | |
3017 | 2216 ALLOCATE_FIXED_TYPE_AND_SET_IMPL (marker, Lisp_Marker, p, &lrecord_marker); |
428 | 2217 p->buffer = 0; |
665 | 2218 p->membpos = 0; |
428 | 2219 marker_next (p) = 0; |
2220 marker_prev (p) = 0; | |
2221 p->insertion_type = 0; | |
793 | 2222 return wrap_marker (p); |
428 | 2223 } |
2224 | |
2225 Lisp_Object | |
2226 noseeum_make_marker (void) | |
2227 { | |
440 | 2228 Lisp_Marker *p; |
2229 | |
3017 | 2230 NOSEEUM_ALLOCATE_FIXED_TYPE_AND_SET_IMPL (marker, Lisp_Marker, p, |
2231 &lrecord_marker); | |
428 | 2232 p->buffer = 0; |
665 | 2233 p->membpos = 0; |
428 | 2234 marker_next (p) = 0; |
2235 marker_prev (p) = 0; | |
2236 p->insertion_type = 0; | |
793 | 2237 return wrap_marker (p); |
428 | 2238 } |
2239 | |
2240 | |
2241 /************************************************************************/ | |
2242 /* String allocation */ | |
2243 /************************************************************************/ | |
2244 | |
2245 /* The data for "short" strings generally resides inside of structs of type | |
2246 string_chars_block. The Lisp_String structure is allocated just like any | |
1204 | 2247 other basic lrecord, and these are freelisted when they get garbage |
2248 collected. The data for short strings get compacted, but the data for | |
2249 large strings do not. | |
428 | 2250 |
2251 Previously Lisp_String structures were relocated, but this caused a lot | |
2252 of bus-errors because the C code didn't include enough GCPRO's for | |
2253 strings (since EVERY REFERENCE to a short string needed to be GCPRO'd so | |
2254 that the reference would get relocated). | |
2255 | |
2256 This new method makes things somewhat bigger, but it is MUCH safer. */ | |
2257 | |
438 | 2258 DECLARE_FIXED_TYPE_ALLOC (string, Lisp_String); |
428 | 2259 /* strings are used and freed quite often */ |
2260 /* #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 10000 */ | |
2261 #define MINIMUM_ALLOWED_FIXED_TYPE_CELLS_string 1000 | |
2262 | |
2263 static Lisp_Object | |
2264 mark_string (Lisp_Object obj) | |
2265 { | |
793 | 2266 if (CONSP (XSTRING_PLIST (obj)) && EXTENT_INFOP (XCAR (XSTRING_PLIST (obj)))) |
2267 flush_cached_extent_info (XCAR (XSTRING_PLIST (obj))); | |
2268 return XSTRING_PLIST (obj); | |
428 | 2269 } |
2270 | |
2271 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
|
2272 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
|
2273 int foldcase) |
428 | 2274 { |
2275 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
|
2276 if (foldcase) |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2277 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
|
2278 else |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
2279 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
|
2280 !memcmp (XSTRING_DATA (obj1), XSTRING_DATA (obj2), len)); |
428 | 2281 } |
2282 | |
1204 | 2283 static const struct memory_description string_description[] = { |
3092 | 2284 #ifdef NEW_GC |
2285 { XD_LISP_OBJECT, offsetof (Lisp_String, data_object) }, | |
2286 #else /* not NEW_GC */ | |
793 | 2287 { XD_BYTECOUNT, offsetof (Lisp_String, size_) }, |
2288 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String, data_), XD_INDIRECT(0, 1) }, | |
3092 | 2289 #endif /* not NEW_GC */ |
440 | 2290 { XD_LISP_OBJECT, offsetof (Lisp_String, plist) }, |
428 | 2291 { XD_END } |
2292 }; | |
2293 | |
442 | 2294 /* We store the string's extent info as the first element of the string's |
2295 property list; and the string's MODIFF as the first or second element | |
2296 of the string's property list (depending on whether the extent info | |
2297 is present), but only if the string has been modified. This is ugly | |
2298 but it reduces the memory allocated for the string in the vast | |
2299 majority of cases, where the string is never modified and has no | |
2300 extent info. | |
2301 | |
2302 #### This means you can't use an int as a key in a string's plist. */ | |
2303 | |
2304 static Lisp_Object * | |
2305 string_plist_ptr (Lisp_Object string) | |
2306 { | |
793 | 2307 Lisp_Object *ptr = &XSTRING_PLIST (string); |
442 | 2308 |
2309 if (CONSP (*ptr) && EXTENT_INFOP (XCAR (*ptr))) | |
2310 ptr = &XCDR (*ptr); | |
2311 if (CONSP (*ptr) && INTP (XCAR (*ptr))) | |
2312 ptr = &XCDR (*ptr); | |
2313 return ptr; | |
2314 } | |
2315 | |
2316 static Lisp_Object | |
2317 string_getprop (Lisp_Object string, Lisp_Object property) | |
2318 { | |
2319 return external_plist_get (string_plist_ptr (string), property, 0, ERROR_ME); | |
2320 } | |
2321 | |
2322 static int | |
2323 string_putprop (Lisp_Object string, Lisp_Object property, Lisp_Object value) | |
2324 { | |
2325 external_plist_put (string_plist_ptr (string), property, value, 0, ERROR_ME); | |
2326 return 1; | |
2327 } | |
2328 | |
2329 static int | |
2330 string_remprop (Lisp_Object string, Lisp_Object property) | |
2331 { | |
2332 return external_remprop (string_plist_ptr (string), property, 0, ERROR_ME); | |
2333 } | |
2334 | |
2335 static Lisp_Object | |
2336 string_plist (Lisp_Object string) | |
2337 { | |
2338 return *string_plist_ptr (string); | |
2339 } | |
2340 | |
3263 | 2341 #ifndef NEW_GC |
442 | 2342 /* No `finalize', or `hash' methods. |
2343 internal_hash() already knows how to hash strings and finalization | |
2344 is done with the ADDITIONAL_FREE_string macro, which is the | |
2345 standard way to do finalization when using | |
2346 SWEEP_FIXED_TYPE_BLOCK(). */ | |
2720 | 2347 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2348 DEFINE_DUMPABLE_FROB_BLOCK_GENERAL_LISP_OBJECT ("string", string, |
934 | 2349 mark_string, print_string, |
2350 0, string_equal, 0, | |
2351 string_description, | |
2352 string_getprop, | |
2353 string_putprop, | |
2354 string_remprop, | |
2355 string_plist, | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2356 0 /* no disksaver */, |
934 | 2357 Lisp_String); |
3263 | 2358 #endif /* not NEW_GC */ |
2720 | 2359 |
3092 | 2360 #ifdef NEW_GC |
2361 #define STRING_FULLSIZE(size) \ | |
2362 ALIGN_SIZE (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_String_Direct_Data, Lisp_Object, data, (size) + 1), sizeof (Lisp_Object *)); | |
2363 #else /* not NEW_GC */ | |
428 | 2364 /* String blocks contain this many useful bytes. */ |
2365 #define STRING_CHARS_BLOCK_SIZE \ | |
814 | 2366 ((Bytecount) (8192 - MALLOC_OVERHEAD - \ |
2367 ((2 * sizeof (struct string_chars_block *)) \ | |
2368 + sizeof (EMACS_INT)))) | |
428 | 2369 /* Block header for small strings. */ |
2370 struct string_chars_block | |
2371 { | |
2372 EMACS_INT pos; | |
2373 struct string_chars_block *next; | |
2374 struct string_chars_block *prev; | |
2375 /* Contents of string_chars_block->string_chars are interleaved | |
2376 string_chars structures (see below) and the actual string data */ | |
2377 unsigned char string_chars[STRING_CHARS_BLOCK_SIZE]; | |
2378 }; | |
2379 | |
2380 static struct string_chars_block *first_string_chars_block; | |
2381 static struct string_chars_block *current_string_chars_block; | |
2382 | |
2383 /* If SIZE is the length of a string, this returns how many bytes | |
2384 * the string occupies in string_chars_block->string_chars | |
2385 * (including alignment padding). | |
2386 */ | |
438 | 2387 #define STRING_FULLSIZE(size) \ |
826 | 2388 ALIGN_FOR_TYPE (((size) + 1 + sizeof (Lisp_String *)), Lisp_String *) |
428 | 2389 |
2390 #define BIG_STRING_FULLSIZE_P(fullsize) ((fullsize) >= STRING_CHARS_BLOCK_SIZE) | |
2391 #define BIG_STRING_SIZE_P(size) (BIG_STRING_FULLSIZE_P (STRING_FULLSIZE(size))) | |
2392 | |
454 | 2393 #define STRING_CHARS_FREE_P(ptr) ((ptr)->string == NULL) |
2394 #define MARK_STRING_CHARS_AS_FREE(ptr) ((void) ((ptr)->string = NULL)) | |
3092 | 2395 #endif /* not NEW_GC */ |
454 | 2396 |
3263 | 2397 #ifdef NEW_GC |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2398 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
|
2399 mark_string, print_string, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2400 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2401 string_equal, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2402 string_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2403 string_getprop, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2404 string_putprop, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2405 string_remprop, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2406 string_plist, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2407 0 /* no disksaver */, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
2408 Lisp_String); |
3092 | 2409 |
2410 | |
2411 static const struct memory_description string_direct_data_description[] = { | |
3514 | 2412 { XD_BYTECOUNT, offsetof (Lisp_String_Direct_Data, size) }, |
3092 | 2413 { XD_END } |
2414 }; | |
2415 | |
2416 static Bytecount | |
2417 size_string_direct_data (const void *lheader) | |
2418 { | |
2419 return STRING_FULLSIZE (((Lisp_String_Direct_Data *) lheader)->size); | |
2420 } | |
2421 | |
2422 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2423 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
|
2424 string_direct_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2425 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2426 string_direct_data_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2427 size_string_direct_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2428 Lisp_String_Direct_Data); |
3092 | 2429 |
2430 | |
2431 static const struct memory_description string_indirect_data_description[] = { | |
2432 { XD_BYTECOUNT, offsetof (Lisp_String_Indirect_Data, size) }, | |
2433 { XD_OPAQUE_DATA_PTR, offsetof (Lisp_String_Indirect_Data, data), | |
2434 XD_INDIRECT(0, 1) }, | |
2435 { XD_END } | |
2436 }; | |
2437 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2438 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
|
2439 string_indirect_data, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2440 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2441 string_indirect_data_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2442 Lisp_String_Indirect_Data); |
3092 | 2443 #endif /* NEW_GC */ |
2720 | 2444 |
3092 | 2445 #ifndef NEW_GC |
428 | 2446 struct string_chars |
2447 { | |
438 | 2448 Lisp_String *string; |
428 | 2449 unsigned char chars[1]; |
2450 }; | |
2451 | |
2452 struct unused_string_chars | |
2453 { | |
438 | 2454 Lisp_String *string; |
428 | 2455 EMACS_INT fullsize; |
2456 }; | |
2457 | |
2458 static void | |
2459 init_string_chars_alloc (void) | |
2460 { | |
2461 first_string_chars_block = xnew (struct string_chars_block); | |
2462 first_string_chars_block->prev = 0; | |
2463 first_string_chars_block->next = 0; | |
2464 first_string_chars_block->pos = 0; | |
2465 current_string_chars_block = first_string_chars_block; | |
2466 } | |
2467 | |
1550 | 2468 static Ibyte * |
2469 allocate_big_string_chars (Bytecount length) | |
2470 { | |
2471 Ibyte *p = xnew_array (Ibyte, length); | |
2472 INCREMENT_CONS_COUNTER (length, "string chars"); | |
2473 return p; | |
2474 } | |
2475 | |
428 | 2476 static struct string_chars * |
793 | 2477 allocate_string_chars_struct (Lisp_Object string_it_goes_with, |
814 | 2478 Bytecount fullsize) |
428 | 2479 { |
2480 struct string_chars *s_chars; | |
2481 | |
438 | 2482 if (fullsize <= |
2483 (countof (current_string_chars_block->string_chars) | |
2484 - current_string_chars_block->pos)) | |
428 | 2485 { |
2486 /* This string can fit in the current string chars block */ | |
2487 s_chars = (struct string_chars *) | |
2488 (current_string_chars_block->string_chars | |
2489 + current_string_chars_block->pos); | |
2490 current_string_chars_block->pos += fullsize; | |
2491 } | |
2492 else | |
2493 { | |
2494 /* Make a new current string chars block */ | |
2495 struct string_chars_block *new_scb = xnew (struct string_chars_block); | |
2496 | |
2497 current_string_chars_block->next = new_scb; | |
2498 new_scb->prev = current_string_chars_block; | |
2499 new_scb->next = 0; | |
2500 current_string_chars_block = new_scb; | |
2501 new_scb->pos = fullsize; | |
2502 s_chars = (struct string_chars *) | |
2503 current_string_chars_block->string_chars; | |
2504 } | |
2505 | |
793 | 2506 s_chars->string = XSTRING (string_it_goes_with); |
428 | 2507 |
2508 INCREMENT_CONS_COUNTER (fullsize, "string chars"); | |
2509 | |
2510 return s_chars; | |
2511 } | |
3092 | 2512 #endif /* not NEW_GC */ |
428 | 2513 |
771 | 2514 #ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN |
2515 void | |
2516 sledgehammer_check_ascii_begin (Lisp_Object str) | |
2517 { | |
2518 Bytecount i; | |
2519 | |
2520 for (i = 0; i < XSTRING_LENGTH (str); i++) | |
2521 { | |
826 | 2522 if (!byte_ascii_p (string_byte (str, i))) |
771 | 2523 break; |
2524 } | |
2525 | |
2526 assert (i == (Bytecount) XSTRING_ASCII_BEGIN (str) || | |
2527 (i > MAX_STRING_ASCII_BEGIN && | |
2528 (Bytecount) XSTRING_ASCII_BEGIN (str) == | |
2529 (Bytecount) MAX_STRING_ASCII_BEGIN)); | |
2530 } | |
2531 #endif | |
2532 | |
2533 /* You do NOT want to be calling this! (And if you do, you must call | |
851 | 2534 XSET_STRING_ASCII_BEGIN() after modifying the string.) Use ALLOCA () |
771 | 2535 instead and then call make_string() like the rest of the world. */ |
2536 | |
428 | 2537 Lisp_Object |
2538 make_uninit_string (Bytecount length) | |
2539 { | |
438 | 2540 Lisp_String *s; |
814 | 2541 Bytecount fullsize = STRING_FULLSIZE (length); |
428 | 2542 |
438 | 2543 assert (length >= 0 && fullsize > 0); |
428 | 2544 |
3263 | 2545 #ifdef NEW_GC |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
2546 s = XSTRING (ALLOC_LISP_OBJECT (string)); |
3263 | 2547 #else /* not NEW_GC */ |
428 | 2548 /* Allocate the string header */ |
438 | 2549 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
793 | 2550 xzero (*s); |
771 | 2551 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
3263 | 2552 #endif /* not NEW_GC */ |
2720 | 2553 |
3063 | 2554 /* The above allocations set the UID field, which overlaps with the |
2555 ascii-length field, to some non-zero value. We need to zero it. */ | |
2556 XSET_STRING_ASCII_BEGIN (wrap_string (s), 0); | |
2557 | |
3092 | 2558 #ifdef NEW_GC |
3304 | 2559 set_lispstringp_direct (s); |
3092 | 2560 STRING_DATA_OBJECT (s) = |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
2561 alloc_sized_lrecord (fullsize, &lrecord_string_direct_data); |
3092 | 2562 #else /* not NEW_GC */ |
826 | 2563 set_lispstringp_data (s, BIG_STRING_FULLSIZE_P (fullsize) |
2720 | 2564 ? allocate_big_string_chars (length + 1) |
2565 : allocate_string_chars_struct (wrap_string (s), | |
2566 fullsize)->chars); | |
3092 | 2567 #endif /* not NEW_GC */ |
438 | 2568 |
826 | 2569 set_lispstringp_length (s, length); |
428 | 2570 s->plist = Qnil; |
793 | 2571 set_string_byte (wrap_string (s), length, 0); |
2572 | |
2573 return wrap_string (s); | |
428 | 2574 } |
2575 | |
2576 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
2577 static void verify_string_chars_integrity (void); | |
2578 #endif | |
2579 | |
2580 /* Resize the string S so that DELTA bytes can be inserted starting | |
2581 at POS. If DELTA < 0, it means deletion starting at POS. If | |
2582 POS < 0, resize the string but don't copy any characters. Use | |
2583 this if you're planning on completely overwriting the string. | |
2584 */ | |
2585 | |
2586 void | |
793 | 2587 resize_string (Lisp_Object s, Bytecount pos, Bytecount delta) |
428 | 2588 { |
3092 | 2589 #ifdef NEW_GC |
2590 Bytecount newfullsize, len; | |
2591 #else /* not NEW_GC */ | |
438 | 2592 Bytecount oldfullsize, newfullsize; |
3092 | 2593 #endif /* not NEW_GC */ |
428 | 2594 #ifdef VERIFY_STRING_CHARS_INTEGRITY |
2595 verify_string_chars_integrity (); | |
2596 #endif | |
800 | 2597 #ifdef ERROR_CHECK_TEXT |
428 | 2598 if (pos >= 0) |
2599 { | |
793 | 2600 assert (pos <= XSTRING_LENGTH (s)); |
428 | 2601 if (delta < 0) |
793 | 2602 assert (pos + (-delta) <= XSTRING_LENGTH (s)); |
428 | 2603 } |
2604 else | |
2605 { | |
2606 if (delta < 0) | |
793 | 2607 assert ((-delta) <= XSTRING_LENGTH (s)); |
428 | 2608 } |
800 | 2609 #endif /* ERROR_CHECK_TEXT */ |
428 | 2610 |
2611 if (delta == 0) | |
2612 /* simplest case: no size change. */ | |
2613 return; | |
438 | 2614 |
2615 if (pos >= 0 && delta < 0) | |
2616 /* If DELTA < 0, the functions below will delete the characters | |
2617 before POS. We want to delete characters *after* POS, however, | |
2618 so convert this to the appropriate form. */ | |
2619 pos += -delta; | |
2620 | |
3092 | 2621 #ifdef NEW_GC |
2622 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
2623 | |
2624 len = XSTRING_LENGTH (s) + 1 - pos; | |
2625 | |
2626 if (delta < 0 && pos >= 0) | |
2627 memmove (XSTRING_DATA (s) + pos + delta, | |
2628 XSTRING_DATA (s) + pos, len); | |
2629 | |
2630 XSTRING_DATA_OBJECT (s) = | |
2631 wrap_string_direct_data (mc_realloc (XPNTR (XSTRING_DATA_OBJECT (s)), | |
2632 newfullsize)); | |
2633 if (delta > 0 && pos >= 0) | |
2634 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, | |
2635 len); | |
2636 | |
3263 | 2637 #else /* not NEW_GC */ |
793 | 2638 oldfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s)); |
2639 newfullsize = STRING_FULLSIZE (XSTRING_LENGTH (s) + delta); | |
438 | 2640 |
2641 if (BIG_STRING_FULLSIZE_P (oldfullsize)) | |
428 | 2642 { |
438 | 2643 if (BIG_STRING_FULLSIZE_P (newfullsize)) |
428 | 2644 { |
440 | 2645 /* Both strings are big. We can just realloc(). |
2646 But careful! If the string is shrinking, we have to | |
2647 memmove() _before_ realloc(), and if growing, we have to | |
2648 memmove() _after_ realloc() - otherwise the access is | |
2649 illegal, and we might crash. */ | |
793 | 2650 Bytecount len = XSTRING_LENGTH (s) + 1 - pos; |
440 | 2651 |
2652 if (delta < 0 && pos >= 0) | |
793 | 2653 memmove (XSTRING_DATA (s) + pos + delta, |
2654 XSTRING_DATA (s) + pos, len); | |
2655 XSET_STRING_DATA | |
867 | 2656 (s, (Ibyte *) xrealloc (XSTRING_DATA (s), |
793 | 2657 XSTRING_LENGTH (s) + delta + 1)); |
440 | 2658 if (delta > 0 && pos >= 0) |
793 | 2659 memmove (XSTRING_DATA (s) + pos + delta, XSTRING_DATA (s) + pos, |
2660 len); | |
1550 | 2661 /* Bump the cons counter. |
2662 Conservative; Martin let the increment be delta. */ | |
2663 INCREMENT_CONS_COUNTER (newfullsize, "string chars"); | |
428 | 2664 } |
438 | 2665 else /* String has been demoted from BIG_STRING. */ |
428 | 2666 { |
867 | 2667 Ibyte *new_data = |
438 | 2668 allocate_string_chars_struct (s, newfullsize)->chars; |
867 | 2669 Ibyte *old_data = XSTRING_DATA (s); |
438 | 2670 |
2671 if (pos >= 0) | |
2672 { | |
2673 memcpy (new_data, old_data, pos); | |
2674 memcpy (new_data + pos + delta, old_data + pos, | |
793 | 2675 XSTRING_LENGTH (s) + 1 - pos); |
438 | 2676 } |
793 | 2677 XSET_STRING_DATA (s, new_data); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
2678 xfree (old_data); |
438 | 2679 } |
2680 } | |
2681 else /* old string is small */ | |
2682 { | |
2683 if (oldfullsize == newfullsize) | |
2684 { | |
2685 /* special case; size change but the necessary | |
2686 allocation size won't change (up or down; code | |
2687 somewhere depends on there not being any unused | |
2688 allocation space, modulo any alignment | |
2689 constraints). */ | |
428 | 2690 if (pos >= 0) |
2691 { | |
867 | 2692 Ibyte *addroff = pos + XSTRING_DATA (s); |
428 | 2693 |
2694 memmove (addroff + delta, addroff, | |
2695 /* +1 due to zero-termination. */ | |
793 | 2696 XSTRING_LENGTH (s) + 1 - pos); |
428 | 2697 } |
2698 } | |
2699 else | |
2700 { | |
867 | 2701 Ibyte *old_data = XSTRING_DATA (s); |
2702 Ibyte *new_data = | |
438 | 2703 BIG_STRING_FULLSIZE_P (newfullsize) |
1550 | 2704 ? allocate_big_string_chars (XSTRING_LENGTH (s) + delta + 1) |
438 | 2705 : allocate_string_chars_struct (s, newfullsize)->chars; |
2706 | |
428 | 2707 if (pos >= 0) |
2708 { | |
438 | 2709 memcpy (new_data, old_data, pos); |
2710 memcpy (new_data + pos + delta, old_data + pos, | |
793 | 2711 XSTRING_LENGTH (s) + 1 - pos); |
428 | 2712 } |
793 | 2713 XSET_STRING_DATA (s, new_data); |
438 | 2714 |
4776
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2715 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
|
2716 { |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2717 /* 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
|
2718 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
|
2719 freak. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2720 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
|
2721 ((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
|
2722 /* 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
|
2723 alignment/padding. */ |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2724 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
|
2725 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
|
2726 ((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
|
2727 oldfullsize; |
73e8632018ad
Don't attempt to free dumped data, alloc.c:resize_string()
Aidan Kehoe <kehoea@parhasard.net>
parents:
4735
diff
changeset
|
2728 } |
428 | 2729 } |
438 | 2730 } |
3092 | 2731 #endif /* not NEW_GC */ |
438 | 2732 |
793 | 2733 XSET_STRING_LENGTH (s, XSTRING_LENGTH (s) + delta); |
438 | 2734 /* If pos < 0, the string won't be zero-terminated. |
2735 Terminate now just to make sure. */ | |
793 | 2736 XSTRING_DATA (s)[XSTRING_LENGTH (s)] = '\0'; |
438 | 2737 |
2738 if (pos >= 0) | |
793 | 2739 /* We also have to adjust all of the extent indices after the |
2740 place we did the change. We say "pos - 1" because | |
2741 adjust_extents() is exclusive of the starting position | |
2742 passed to it. */ | |
2743 adjust_extents (s, pos - 1, XSTRING_LENGTH (s), delta); | |
428 | 2744 |
2745 #ifdef VERIFY_STRING_CHARS_INTEGRITY | |
2746 verify_string_chars_integrity (); | |
2747 #endif | |
2748 } | |
2749 | |
2750 #ifdef MULE | |
2751 | |
771 | 2752 /* WARNING: If you modify an existing string, you must call |
2753 CHECK_LISP_WRITEABLE() before and bump_string_modiff() afterwards. */ | |
428 | 2754 void |
867 | 2755 set_string_char (Lisp_Object s, Charcount i, Ichar c) |
428 | 2756 { |
867 | 2757 Ibyte newstr[MAX_ICHAR_LEN]; |
771 | 2758 Bytecount bytoff = string_index_char_to_byte (s, i); |
867 | 2759 Bytecount oldlen = itext_ichar_len (XSTRING_DATA (s) + bytoff); |
2760 Bytecount newlen = set_itext_ichar (newstr, c); | |
428 | 2761 |
793 | 2762 sledgehammer_check_ascii_begin (s); |
428 | 2763 if (oldlen != newlen) |
2764 resize_string (s, bytoff, newlen - oldlen); | |
793 | 2765 /* Remember, XSTRING_DATA (s) might have changed so we can't cache it. */ |
2766 memcpy (XSTRING_DATA (s) + bytoff, newstr, newlen); | |
771 | 2767 if (oldlen != newlen) |
2768 { | |
793 | 2769 if (newlen > 1 && i <= (Charcount) XSTRING_ASCII_BEGIN (s)) |
771 | 2770 /* Everything starting with the new char is no longer part of |
2771 ascii_begin */ | |
793 | 2772 XSET_STRING_ASCII_BEGIN (s, i); |
2773 else if (newlen == 1 && i == (Charcount) XSTRING_ASCII_BEGIN (s)) | |
771 | 2774 /* We've extended ascii_begin, and we have to figure out how much by */ |
2775 { | |
2776 Bytecount j; | |
814 | 2777 for (j = (Bytecount) i + 1; j < XSTRING_LENGTH (s); j++) |
771 | 2778 { |
826 | 2779 if (!byte_ascii_p (XSTRING_DATA (s)[j])) |
771 | 2780 break; |
2781 } | |
814 | 2782 XSET_STRING_ASCII_BEGIN (s, min (j, (Bytecount) MAX_STRING_ASCII_BEGIN)); |
771 | 2783 } |
2784 } | |
793 | 2785 sledgehammer_check_ascii_begin (s); |
428 | 2786 } |
2787 | |
2788 #endif /* MULE */ | |
2789 | |
2790 DEFUN ("make-string", Fmake_string, 2, 2, 0, /* | |
444 | 2791 Return a new string consisting of LENGTH copies of CHARACTER. |
2792 LENGTH must be a non-negative integer. | |
428 | 2793 */ |
444 | 2794 (length, character)) |
428 | 2795 { |
2796 CHECK_NATNUM (length); | |
444 | 2797 CHECK_CHAR_COERCE_INT (character); |
428 | 2798 { |
867 | 2799 Ibyte init_str[MAX_ICHAR_LEN]; |
2800 int len = set_itext_ichar (init_str, XCHAR (character)); | |
428 | 2801 Lisp_Object val = make_uninit_string (len * XINT (length)); |
2802 | |
2803 if (len == 1) | |
771 | 2804 { |
2805 /* Optimize the single-byte case */ | |
2806 memset (XSTRING_DATA (val), XCHAR (character), XSTRING_LENGTH (val)); | |
793 | 2807 XSET_STRING_ASCII_BEGIN (val, min (MAX_STRING_ASCII_BEGIN, |
2808 len * XINT (length))); | |
771 | 2809 } |
428 | 2810 else |
2811 { | |
647 | 2812 EMACS_INT i; |
867 | 2813 Ibyte *ptr = XSTRING_DATA (val); |
428 | 2814 |
2815 for (i = XINT (length); i; i--) | |
2816 { | |
867 | 2817 Ibyte *init_ptr = init_str; |
428 | 2818 switch (len) |
2819 { | |
2820 case 4: *ptr++ = *init_ptr++; | |
2821 case 3: *ptr++ = *init_ptr++; | |
2822 case 2: *ptr++ = *init_ptr++; | |
2823 case 1: *ptr++ = *init_ptr++; | |
2824 } | |
2825 } | |
2826 } | |
771 | 2827 sledgehammer_check_ascii_begin (val); |
428 | 2828 return val; |
2829 } | |
2830 } | |
2831 | |
2832 DEFUN ("string", Fstring, 0, MANY, 0, /* | |
2833 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
|
2834 |
80cd90837ac5
Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3514
diff
changeset
|
2835 arguments: (&rest ARGS) |
428 | 2836 */ |
2837 (int nargs, Lisp_Object *args)) | |
2838 { | |
2367 | 2839 Ibyte *storage = alloca_ibytes (nargs * MAX_ICHAR_LEN); |
867 | 2840 Ibyte *p = storage; |
428 | 2841 |
2842 for (; nargs; nargs--, args++) | |
2843 { | |
2844 Lisp_Object lisp_char = *args; | |
2845 CHECK_CHAR_COERCE_INT (lisp_char); | |
867 | 2846 p += set_itext_ichar (p, XCHAR (lisp_char)); |
428 | 2847 } |
2848 return make_string (storage, p - storage); | |
2849 } | |
2850 | |
771 | 2851 /* Initialize the ascii_begin member of a string to the correct value. */ |
2852 | |
2853 void | |
2854 init_string_ascii_begin (Lisp_Object string) | |
2855 { | |
2856 #ifdef MULE | |
2857 int i; | |
2858 Bytecount length = XSTRING_LENGTH (string); | |
867 | 2859 Ibyte *contents = XSTRING_DATA (string); |
771 | 2860 |
2861 for (i = 0; i < length; i++) | |
2862 { | |
826 | 2863 if (!byte_ascii_p (contents[i])) |
771 | 2864 break; |
2865 } | |
793 | 2866 XSET_STRING_ASCII_BEGIN (string, min (i, MAX_STRING_ASCII_BEGIN)); |
771 | 2867 #else |
793 | 2868 XSET_STRING_ASCII_BEGIN (string, min (XSTRING_LENGTH (string), |
2869 MAX_STRING_ASCII_BEGIN)); | |
771 | 2870 #endif |
2871 sledgehammer_check_ascii_begin (string); | |
2872 } | |
428 | 2873 |
2874 /* Take some raw memory, which MUST already be in internal format, | |
2875 and package it up into a Lisp string. */ | |
2876 Lisp_Object | |
867 | 2877 make_string (const Ibyte *contents, Bytecount length) |
428 | 2878 { |
2879 Lisp_Object val; | |
2880 | |
2881 /* Make sure we find out about bad make_string's when they happen */ | |
800 | 2882 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
428 | 2883 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
2884 #endif | |
2885 | |
2886 val = make_uninit_string (length); | |
2887 memcpy (XSTRING_DATA (val), contents, length); | |
771 | 2888 init_string_ascii_begin (val); |
2889 sledgehammer_check_ascii_begin (val); | |
428 | 2890 return val; |
2891 } | |
2892 | |
2893 /* Take some raw memory, encoded in some external data format, | |
2894 and convert it into a Lisp string. */ | |
2895 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2896 make_extstring (const Extbyte *contents, EMACS_INT length, |
440 | 2897 Lisp_Object coding_system) |
428 | 2898 { |
440 | 2899 Lisp_Object string; |
2900 TO_INTERNAL_FORMAT (DATA, (contents, length), | |
2901 LISP_STRING, string, | |
2902 coding_system); | |
2903 return string; | |
428 | 2904 } |
2905 | |
2906 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2907 build_istring (const Ibyte *str) |
771 | 2908 { |
2909 /* Some strlen's crash and burn if passed null. */ | |
814 | 2910 return make_string (str, (str ? qxestrlen (str) : (Bytecount) 0)); |
771 | 2911 } |
2912 | |
2913 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2914 build_cistring (const CIbyte *str) |
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2915 { |
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2916 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
|
2917 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2918 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2919 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2920 build_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2921 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2922 ASSERT_ASCTEXT_ASCII (str); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2923 return build_istring ((const Ibyte *) str); |
428 | 2924 } |
2925 | |
2926 Lisp_Object | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2927 build_extstring (const Extbyte *str, Lisp_Object coding_system) |
428 | 2928 { |
2929 /* 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
|
2930 return make_extstring ((const Extbyte *) str, |
2367 | 2931 (str ? dfc_external_data_len (str, coding_system) : |
2932 0), | |
440 | 2933 coding_system); |
428 | 2934 } |
2935 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2936 /* 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
|
2937 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
|
2938 |
428 | 2939 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2940 build_msg_istring (const Ibyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2941 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2942 return build_istring (IGETTEXT (str)); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2943 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2944 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2945 /* 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
|
2946 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
|
2947 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2948 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2949 build_msg_cistring (const CIbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2950 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2951 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
|
2952 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2953 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2954 /* 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
|
2955 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
|
2956 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
|
2957 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
|
2958 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2959 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2960 build_msg_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2961 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2962 ASSERT_ASCTEXT_ASCII (str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2963 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
|
2964 } |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2965 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2966 /* 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
|
2967 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
|
2968 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
|
2969 translated. |
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 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
|
2972 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
|
2973 properly. */ |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2974 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2975 Lisp_Object |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2976 build_defer_istring (const Ibyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2977 { |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
2978 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
|
2979 /* 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
|
2980 return retval; |
771 | 2981 } |
2982 | |
428 | 2983 Lisp_Object |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2984 build_defer_cistring (const CIbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2985 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2986 return build_defer_istring ((Ibyte *) str); |
771 | 2987 } |
2988 | |
2989 Lisp_Object | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2990 build_defer_ascstring (const Ascbyte *str) |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2991 { |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2992 ASSERT_ASCTEXT_ASCII (str); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
2993 return build_defer_istring ((Ibyte *) str); |
428 | 2994 } |
2995 | |
2996 Lisp_Object | |
867 | 2997 make_string_nocopy (const Ibyte *contents, Bytecount length) |
428 | 2998 { |
438 | 2999 Lisp_String *s; |
428 | 3000 Lisp_Object val; |
3001 | |
3002 /* Make sure we find out about bad make_string_nocopy's when they happen */ | |
800 | 3003 #if defined (ERROR_CHECK_TEXT) && defined (MULE) |
428 | 3004 bytecount_to_charcount (contents, length); /* Just for the assertions */ |
3005 #endif | |
3006 | |
3263 | 3007 #ifdef NEW_GC |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
3008 s = XSTRING (ALLOC_LISP_OBJECT (string)); |
2720 | 3009 mcpro (wrap_pointer_1 (s)); /* otherwise nocopy_strings get |
3010 collected and static data is tried to | |
3011 be freed. */ | |
3263 | 3012 #else /* not NEW_GC */ |
428 | 3013 /* Allocate the string header */ |
438 | 3014 ALLOCATE_FIXED_TYPE (string, Lisp_String, s); |
771 | 3015 set_lheader_implementation (&s->u.lheader, &lrecord_string); |
3016 SET_C_READONLY_RECORD_HEADER (&s->u.lheader); | |
3263 | 3017 #endif /* not NEW_GC */ |
3063 | 3018 /* Don't need to XSET_STRING_ASCII_BEGIN() here because it happens in |
3019 init_string_ascii_begin(). */ | |
428 | 3020 s->plist = Qnil; |
3092 | 3021 #ifdef NEW_GC |
3022 set_lispstringp_indirect (s); | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
3023 STRING_DATA_OBJECT (s) = ALLOC_LISP_OBJECT (string_indirect_data); |
3092 | 3024 XSTRING_INDIRECT_DATA_DATA (STRING_DATA_OBJECT (s)) = (Ibyte *) contents; |
3025 XSTRING_INDIRECT_DATA_SIZE (STRING_DATA_OBJECT (s)) = length; | |
3026 #else /* not NEW_GC */ | |
867 | 3027 set_lispstringp_data (s, (Ibyte *) contents); |
826 | 3028 set_lispstringp_length (s, length); |
3092 | 3029 #endif /* not NEW_GC */ |
793 | 3030 val = wrap_string (s); |
771 | 3031 init_string_ascii_begin (val); |
3032 sledgehammer_check_ascii_begin (val); | |
3033 | |
428 | 3034 return val; |
3035 } | |
3036 | |
3037 | |
3263 | 3038 #ifndef NEW_GC |
428 | 3039 /************************************************************************/ |
3040 /* lcrecord lists */ | |
3041 /************************************************************************/ | |
3042 | |
3043 /* 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
|
3044 sorts of lcrecords, to avoid calling ALLOC_LISP_OBJECT() (and thus |
428 | 3045 malloc() and garbage-collection junk) as much as possible. |
3046 It is similar to the Blocktype class. | |
3047 | |
1204 | 3048 See detailed comment in lcrecord.h. |
3049 */ | |
3050 | |
3051 const struct memory_description free_description[] = { | |
2551 | 3052 { XD_LISP_OBJECT, offsetof (struct free_lcrecord_header, chain), 0, { 0 }, |
1204 | 3053 XD_FLAG_FREE_LISP_OBJECT }, |
3054 { XD_END } | |
3055 }; | |
3056 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3057 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
|
3058 struct free_lcrecord_header); |
1204 | 3059 |
3060 const struct memory_description lcrecord_list_description[] = { | |
2551 | 3061 { XD_LISP_OBJECT, offsetof (struct lcrecord_list, free), 0, { 0 }, |
1204 | 3062 XD_FLAG_FREE_LISP_OBJECT }, |
3063 { XD_END } | |
3064 }; | |
428 | 3065 |
3066 static Lisp_Object | |
3067 mark_lcrecord_list (Lisp_Object obj) | |
3068 { | |
3069 struct lcrecord_list *list = XLCRECORD_LIST (obj); | |
3070 Lisp_Object chain = list->free; | |
3071 | |
3072 while (!NILP (chain)) | |
3073 { | |
3074 struct lrecord_header *lheader = XRECORD_LHEADER (chain); | |
3075 struct free_lcrecord_header *free_header = | |
3076 (struct free_lcrecord_header *) lheader; | |
3077 | |
442 | 3078 gc_checking_assert |
3079 (/* There should be no other pointers to the free list. */ | |
3080 ! MARKED_RECORD_HEADER_P (lheader) | |
3081 && | |
3082 /* Only lcrecords should be here. */ | |
1204 | 3083 ! list->implementation->basic_p |
442 | 3084 && |
3085 /* Only free lcrecords should be here. */ | |
3086 free_header->lcheader.free | |
3087 && | |
3088 /* The type of the lcrecord must be right. */ | |
1204 | 3089 lheader->type == lrecord_type_free |
442 | 3090 && |
3091 /* So must the size. */ | |
1204 | 3092 (list->implementation->static_size == 0 || |
3093 list->implementation->static_size == list->size) | |
442 | 3094 ); |
428 | 3095 |
3096 MARK_RECORD_HEADER (lheader); | |
3097 chain = free_header->chain; | |
3098 } | |
3099 | |
3100 return Qnil; | |
3101 } | |
3102 | |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3103 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
|
3104 mark_lcrecord_list, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3105 lcrecord_list_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
3106 struct lcrecord_list); |
934 | 3107 |
428 | 3108 Lisp_Object |
665 | 3109 make_lcrecord_list (Elemcount size, |
442 | 3110 const struct lrecord_implementation *implementation) |
428 | 3111 { |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3112 /* 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
|
3113 allocating this. */ |
1204 | 3114 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
|
3115 old_alloc_lcrecord (&lrecord_lcrecord_list); |
428 | 3116 |
3117 p->implementation = implementation; | |
3118 p->size = size; | |
3119 p->free = Qnil; | |
793 | 3120 return wrap_lcrecord_list (p); |
428 | 3121 } |
3122 | |
3123 Lisp_Object | |
1204 | 3124 alloc_managed_lcrecord (Lisp_Object lcrecord_list) |
428 | 3125 { |
3126 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
3127 if (!NILP (list->free)) | |
3128 { | |
3129 Lisp_Object val = list->free; | |
3130 struct free_lcrecord_header *free_header = | |
3131 (struct free_lcrecord_header *) XPNTR (val); | |
1204 | 3132 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
428 | 3133 |
3134 #ifdef ERROR_CHECK_GC | |
1204 | 3135 /* Major overkill here. */ |
428 | 3136 /* There should be no other pointers to the free list. */ |
442 | 3137 assert (! MARKED_RECORD_HEADER_P (lheader)); |
428 | 3138 /* Only free lcrecords should be here. */ |
3139 assert (free_header->lcheader.free); | |
1204 | 3140 assert (lheader->type == lrecord_type_free); |
3141 /* Only lcrecords should be here. */ | |
3142 assert (! (list->implementation->basic_p)); | |
3143 #if 0 /* Not used anymore, now that we set the type of the header to | |
3144 lrecord_type_free. */ | |
428 | 3145 /* The type of the lcrecord must be right. */ |
442 | 3146 assert (LHEADER_IMPLEMENTATION (lheader) == list->implementation); |
1204 | 3147 #endif /* 0 */ |
428 | 3148 /* So must the size. */ |
1204 | 3149 assert (list->implementation->static_size == 0 || |
3150 list->implementation->static_size == list->size); | |
428 | 3151 #endif /* ERROR_CHECK_GC */ |
442 | 3152 |
428 | 3153 list->free = free_header->chain; |
3154 free_header->lcheader.free = 0; | |
1204 | 3155 /* Put back the correct type, as we set it to lrecord_type_free. */ |
3156 lheader->type = list->implementation->lrecord_type_index; | |
3024 | 3157 old_zero_sized_lcrecord (free_header, list->size); |
428 | 3158 return val; |
3159 } | |
3160 else | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3161 return wrap_pointer_1 (old_alloc_sized_lcrecord (list->size, |
3024 | 3162 list->implementation)); |
428 | 3163 } |
3164 | |
771 | 3165 /* "Free" a Lisp object LCRECORD by placing it on its associated free list |
1204 | 3166 LCRECORD_LIST; next time alloc_managed_lcrecord() is called with the |
771 | 3167 same LCRECORD_LIST as its parameter, it will return an object from the |
3168 free list, which may be this one. Be VERY VERY SURE there are no | |
3169 pointers to this object hanging around anywhere where they might be | |
3170 used! | |
3171 | |
3172 The first thing this does before making any global state change is to | |
3173 call the finalize method of the object, if it exists. */ | |
3174 | |
428 | 3175 void |
3176 free_managed_lcrecord (Lisp_Object lcrecord_list, Lisp_Object lcrecord) | |
3177 { | |
3178 struct lcrecord_list *list = XLCRECORD_LIST (lcrecord_list); | |
3179 struct free_lcrecord_header *free_header = | |
3180 (struct free_lcrecord_header *) XPNTR (lcrecord); | |
442 | 3181 struct lrecord_header *lheader = &free_header->lcheader.lheader; |
3182 const struct lrecord_implementation *implementation | |
428 | 3183 = LHEADER_IMPLEMENTATION (lheader); |
3184 | |
4880
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3185 /* 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
|
3186 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
|
3187 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
|
3188 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
|
3189 super long-lived afterwards, anyway. */ |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3190 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
|
3191 return; |
ae81a2c00f4f
try harder to avoid crashing when debug-printing
Ben Wing <ben@xemacs.org>
parents:
4803
diff
changeset
|
3192 |
771 | 3193 /* Finalizer methods may try to free objects within them, which typically |
3194 won't be marked and thus are scheduled for demolition. Putting them | |
3195 on the free list would be very bad, as we'd have xfree()d memory in | |
3196 the list. Even if for some reason the objects are still live | |
3197 (generally a logic error!), we still will have problems putting such | |
3198 an object on the free list right now (e.g. we'd have to avoid calling | |
3199 the finalizer twice, etc.). So basically, those finalizers should not | |
3200 be freeing any objects if during GC. Abort now to catch those | |
3201 problems. */ | |
3202 gc_checking_assert (!gc_in_progress); | |
3203 | |
428 | 3204 /* Make sure the size is correct. This will catch, for example, |
3205 putting a window configuration on the wrong free list. */ | |
1204 | 3206 gc_checking_assert (detagged_lisp_object_size (lheader) == list->size); |
771 | 3207 /* Make sure the object isn't already freed. */ |
3208 gc_checking_assert (!free_header->lcheader.free); | |
2367 | 3209 /* Freeing stuff in dumped memory is bad. If you trip this, you |
3210 may need to check for this before freeing. */ | |
3211 gc_checking_assert (!OBJECT_DUMPED_P (lcrecord)); | |
771 | 3212 |
428 | 3213 if (implementation->finalizer) |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3214 implementation->finalizer (lheader); |
1204 | 3215 /* Yes, there are two ways to indicate freeness -- the type is |
3216 lrecord_type_free or the ->free flag is set. We used to do only the | |
3217 latter; now we do the former as well for KKCC purposes. Probably | |
3218 safer in any case, as we will lose quicker this way than keeping | |
3219 around an lrecord of apparently correct type but bogus junk in it. */ | |
3220 MARK_LRECORD_AS_FREE (lheader); | |
428 | 3221 free_header->chain = list->free; |
3222 free_header->lcheader.free = 1; | |
3223 list->free = lcrecord; | |
3224 } | |
3225 | |
771 | 3226 static Lisp_Object all_lcrecord_lists[countof (lrecord_implementations_table)]; |
3227 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3228 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3229 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
|
3230 const struct lrecord_implementation *imp) |
771 | 3231 { |
3232 if (EQ (all_lcrecord_lists[imp->lrecord_type_index], Qzero)) | |
3233 all_lcrecord_lists[imp->lrecord_type_index] = | |
3234 make_lcrecord_list (size, imp); | |
3235 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3236 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
|
3237 } |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3238 |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3239 Lisp_Object |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3240 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
|
3241 { |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
3242 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
|
3243 return alloc_automanaged_sized_lcrecord (imp->static_size, imp); |
771 | 3244 } |
3245 | |
3246 void | |
3024 | 3247 old_free_lcrecord (Lisp_Object rec) |
771 | 3248 { |
3249 int type = XRECORD_LHEADER (rec)->type; | |
3250 | |
3251 assert (!EQ (all_lcrecord_lists[type], Qzero)); | |
3252 | |
3253 free_managed_lcrecord (all_lcrecord_lists[type], rec); | |
3254 } | |
3263 | 3255 #endif /* not NEW_GC */ |
428 | 3256 |
3257 | |
3258 DEFUN ("purecopy", Fpurecopy, 1, 1, 0, /* | |
3259 Kept for compatibility, returns its argument. | |
3260 Old: | |
3261 Make a copy of OBJECT in pure storage. | |
3262 Recursively copies contents of vectors and cons cells. | |
3263 Does not copy symbols. | |
3264 */ | |
444 | 3265 (object)) |
428 | 3266 { |
444 | 3267 return object; |
428 | 3268 } |
3269 | |
3270 | |
3271 /************************************************************************/ | |
3272 /* Garbage Collection */ | |
3273 /************************************************************************/ | |
3274 | |
442 | 3275 /* All the built-in lisp object types are enumerated in `enum lrecord_type'. |
3276 Additional ones may be defined by a module (none yet). We leave some | |
3277 room in `lrecord_implementations_table' for such new lisp object types. */ | |
647 | 3278 const struct lrecord_implementation *lrecord_implementations_table[(int)lrecord_type_last_built_in_type + MODULE_DEFINABLE_TYPE_COUNT]; |
3279 int lrecord_type_count = lrecord_type_last_built_in_type; | |
1676 | 3280 #ifndef USE_KKCC |
442 | 3281 /* Object marker functions are in the lrecord_implementation structure. |
3282 But copying them to a parallel array is much more cache-friendly. | |
3283 This hack speeds up (garbage-collect) by about 5%. */ | |
3284 Lisp_Object (*lrecord_markers[countof (lrecord_implementations_table)]) (Lisp_Object); | |
1676 | 3285 #endif /* not USE_KKCC */ |
428 | 3286 |
3287 struct gcpro *gcprolist; | |
3288 | |
771 | 3289 /* We want the staticpro list relocated, but not the pointers found |
3290 therein, because they refer to locations in the global data segment, not | |
3291 in the heap; we only dump heap objects. Hence we use a trivial | |
3292 description, as for pointerless objects. (Note that the data segment | |
3293 objects, which are global variables like Qfoo or Vbar, themselves are | |
3294 pointers to heap objects. Each needs to be described to pdump as a | |
3295 "root pointer"; this happens in the call to staticpro(). */ | |
1204 | 3296 static const struct memory_description staticpro_description_1[] = { |
452 | 3297 { XD_END } |
3298 }; | |
3299 | |
1204 | 3300 static const struct sized_memory_description staticpro_description = { |
452 | 3301 sizeof (Lisp_Object *), |
3302 staticpro_description_1 | |
3303 }; | |
3304 | |
1204 | 3305 static const struct memory_description staticpros_description_1[] = { |
452 | 3306 XD_DYNARR_DESC (Lisp_Object_ptr_dynarr, &staticpro_description), |
3307 { XD_END } | |
3308 }; | |
3309 | |
1204 | 3310 static const struct sized_memory_description staticpros_description = { |
452 | 3311 sizeof (Lisp_Object_ptr_dynarr), |
3312 staticpros_description_1 | |
3313 }; | |
3314 | |
771 | 3315 #ifdef DEBUG_XEMACS |
3316 | |
3317 /* Help debug crashes gc-marking a staticpro'ed object. */ | |
3318 | |
3319 Lisp_Object_ptr_dynarr *staticpros; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3320 const_Ascbyte_ptr_dynarr *staticpro_names; |
771 | 3321 |
3322 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3323 garbage collection, and for dumping. */ | |
3324 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3325 staticpro_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
771 | 3326 { |
3327 Dynarr_add (staticpros, varaddress); | |
3328 Dynarr_add (staticpro_names, varname); | |
1204 | 3329 dump_add_root_lisp_object (varaddress); |
771 | 3330 } |
3331 | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3332 const Ascbyte *staticpro_name (int count); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3333 |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3334 /* 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
|
3335 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3336 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3337 staticpro_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3338 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3339 return Dynarr_at (staticpro_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3340 } |
771 | 3341 |
3342 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
|
3343 const_Ascbyte_ptr_dynarr *staticpro_nodump_names; |
771 | 3344 |
3345 /* Mark the Lisp_Object at heap VARADDRESS as a root object for | |
3346 garbage collection, but not for dumping. (See below.) */ | |
3347 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3348 staticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
771 | 3349 { |
3350 Dynarr_add (staticpros_nodump, varaddress); | |
3351 Dynarr_add (staticpro_nodump_names, varname); | |
3352 } | |
3353 | |
5016
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3354 const Ascbyte *staticpro_nodump_name (int count); |
2ade80e8c640
enable more warnings and fix them
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
3355 |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3356 /* 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
|
3357 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3358 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3359 staticpro_nodump_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3360 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3361 return Dynarr_at (staticpro_nodump_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3362 } |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3363 |
996 | 3364 #ifdef HAVE_SHLIB |
3365 /* Stop treating the Lisp_Object at non-heap VARADDRESS as a root object | |
3366 for garbage collection, but not for dumping. */ | |
3367 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3368 unstaticpro_nodump_1 (Lisp_Object *varaddress, const Ascbyte *varname) |
996 | 3369 { |
3370 Dynarr_delete_object (staticpros, varaddress); | |
3371 Dynarr_delete_object (staticpro_names, varname); | |
3372 } | |
3373 #endif | |
3374 | |
771 | 3375 #else /* not DEBUG_XEMACS */ |
3376 | |
452 | 3377 Lisp_Object_ptr_dynarr *staticpros; |
3378 | |
3379 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3380 garbage collection, and for dumping. */ | |
428 | 3381 void |
3382 staticpro (Lisp_Object *varaddress) | |
3383 { | |
452 | 3384 Dynarr_add (staticpros, varaddress); |
1204 | 3385 dump_add_root_lisp_object (varaddress); |
428 | 3386 } |
3387 | |
442 | 3388 |
452 | 3389 Lisp_Object_ptr_dynarr *staticpros_nodump; |
3390 | |
771 | 3391 /* Mark the Lisp_Object at heap VARADDRESS as a root object for garbage |
3392 collection, but not for dumping. This is used for objects where the | |
3393 only sure pointer is in the heap (rather than in the global data | |
3394 segment, as must be the case for pdump root pointers), but not inside of | |
3395 another Lisp object (where it will be marked as a result of that Lisp | |
3396 object's mark method). The call to staticpro_nodump() must occur *BOTH* | |
3397 at initialization time and at "reinitialization" time (startup, after | |
3398 pdump load.) (For example, this is the case with the predicate symbols | |
3399 for specifier and coding system types. The pointer to this symbol is | |
3400 inside of a methods structure, which is allocated on the heap. The | |
3401 methods structure will be written out to the pdump data file, and may be | |
3402 reloaded at a different address.) | |
3403 | |
3404 #### The necessity for reinitialization is a bug in pdump. Pdump should | |
3405 automatically regenerate the staticpro()s for these symbols when it | |
3406 loads the data in. */ | |
3407 | |
428 | 3408 void |
3409 staticpro_nodump (Lisp_Object *varaddress) | |
3410 { | |
452 | 3411 Dynarr_add (staticpros_nodump, varaddress); |
428 | 3412 } |
3413 | |
996 | 3414 #ifdef HAVE_SHLIB |
3415 /* Unmark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3416 garbage collection, but not for dumping. */ | |
3417 void | |
3418 unstaticpro_nodump (Lisp_Object *varaddress) | |
3419 { | |
3420 Dynarr_delete_object (staticpros, varaddress); | |
3421 } | |
3422 #endif | |
3423 | |
771 | 3424 #endif /* not DEBUG_XEMACS */ |
3425 | |
2720 | 3426 |
3427 | |
3428 | |
3429 | |
3263 | 3430 #ifdef NEW_GC |
2720 | 3431 static const struct memory_description mcpro_description_1[] = { |
3432 { XD_END } | |
3433 }; | |
3434 | |
3435 static const struct sized_memory_description mcpro_description = { | |
3436 sizeof (Lisp_Object *), | |
3437 mcpro_description_1 | |
3438 }; | |
3439 | |
3440 static const struct memory_description mcpros_description_1[] = { | |
3441 XD_DYNARR_DESC (Lisp_Object_dynarr, &mcpro_description), | |
3442 { XD_END } | |
3443 }; | |
3444 | |
3445 static const struct sized_memory_description mcpros_description = { | |
3446 sizeof (Lisp_Object_dynarr), | |
3447 mcpros_description_1 | |
3448 }; | |
3449 | |
3450 #ifdef DEBUG_XEMACS | |
3451 | |
3452 /* Help debug crashes gc-marking a mcpro'ed object. */ | |
3453 | |
3454 Lisp_Object_dynarr *mcpros; | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3455 const_Ascbyte_ptr_dynarr *mcpro_names; |
2720 | 3456 |
3457 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3458 garbage collection, and for dumping. */ | |
3459 void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3460 mcpro_1 (Lisp_Object varaddress, const Ascbyte *varname) |
2720 | 3461 { |
3462 Dynarr_add (mcpros, varaddress); | |
3463 Dynarr_add (mcpro_names, varname); | |
3464 } | |
3465 | |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3466 /* 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
|
3467 COUNT. */ |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
3468 const Ascbyte * |
4934
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3469 mcpro_name (int count) |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3470 { |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3471 return Dynarr_at (mcpro_names, count); |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3472 } |
714f7c9fabb1
make it easier to debug staticpro crashes.
Ben Wing <ben@xemacs.org>
parents:
4880
diff
changeset
|
3473 |
2720 | 3474 #else /* not DEBUG_XEMACS */ |
3475 | |
3476 Lisp_Object_dynarr *mcpros; | |
3477 | |
3478 /* Mark the Lisp_Object at non-heap VARADDRESS as a root object for | |
3479 garbage collection, and for dumping. */ | |
3480 void | |
3481 mcpro (Lisp_Object varaddress) | |
3482 { | |
3483 Dynarr_add (mcpros, varaddress); | |
3484 } | |
3485 | |
3486 #endif /* not DEBUG_XEMACS */ | |
3263 | 3487 #endif /* NEW_GC */ |
3488 | |
3489 | |
3490 #ifndef NEW_GC | |
428 | 3491 static int gc_count_num_short_string_in_use; |
647 | 3492 static Bytecount gc_count_string_total_size; |
3493 static Bytecount gc_count_short_string_total_size; | |
428 | 3494 |
3495 /* static int gc_count_total_records_used, gc_count_records_total_size; */ | |
3496 | |
3497 | |
3498 /* stats on lcrecords in use - kinda kludgy */ | |
3499 | |
3500 static struct | |
3501 { | |
3502 int instances_in_use; | |
3503 int bytes_in_use; | |
3504 int instances_freed; | |
3505 int bytes_freed; | |
3506 int instances_on_free_list; | |
3461 | 3507 } lcrecord_stats [countof (lrecord_implementations_table)]; |
428 | 3508 |
3509 static void | |
442 | 3510 tick_lcrecord_stats (const struct lrecord_header *h, int free_p) |
428 | 3511 { |
647 | 3512 int type_index = h->type; |
428 | 3513 |
3024 | 3514 if (((struct old_lcrecord_header *) h)->free) |
428 | 3515 { |
442 | 3516 gc_checking_assert (!free_p); |
428 | 3517 lcrecord_stats[type_index].instances_on_free_list++; |
3518 } | |
3519 else | |
3520 { | |
1204 | 3521 Bytecount sz = detagged_lisp_object_size (h); |
3522 | |
428 | 3523 if (free_p) |
3524 { | |
3525 lcrecord_stats[type_index].instances_freed++; | |
3526 lcrecord_stats[type_index].bytes_freed += sz; | |
3527 } | |
3528 else | |
3529 { | |
3530 lcrecord_stats[type_index].instances_in_use++; | |
3531 lcrecord_stats[type_index].bytes_in_use += sz; | |
3532 } | |
3533 } | |
3534 } | |
3263 | 3535 #endif /* not NEW_GC */ |
428 | 3536 |
3537 | |
3263 | 3538 #ifndef NEW_GC |
428 | 3539 /* Free all unmarked records */ |
3540 static void | |
3024 | 3541 sweep_lcrecords_1 (struct old_lcrecord_header **prev, int *used) |
3542 { | |
3543 struct old_lcrecord_header *header; | |
428 | 3544 int num_used = 0; |
3545 /* int total_size = 0; */ | |
3546 | |
3547 xzero (lcrecord_stats); /* Reset all statistics to 0. */ | |
3548 | |
3549 /* First go through and call all the finalize methods. | |
3550 Then go through and free the objects. There used to | |
3551 be only one loop here, with the call to the finalizer | |
3552 occurring directly before the xfree() below. That | |
3553 is marginally faster but much less safe -- if the | |
3554 finalize method for an object needs to reference any | |
3555 other objects contained within it (and many do), | |
3556 we could easily be screwed by having already freed that | |
3557 other object. */ | |
3558 | |
3559 for (header = *prev; header; header = header->next) | |
3560 { | |
3561 struct lrecord_header *h = &(header->lheader); | |
442 | 3562 |
3563 GC_CHECK_LHEADER_INVARIANTS (h); | |
3564 | |
3565 if (! MARKED_RECORD_HEADER_P (h) && ! header->free) | |
428 | 3566 { |
3567 if (LHEADER_IMPLEMENTATION (h)->finalizer) | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
3568 LHEADER_IMPLEMENTATION (h)->finalizer (h); |
428 | 3569 } |
3570 } | |
3571 | |
3572 for (header = *prev; header; ) | |
3573 { | |
3574 struct lrecord_header *h = &(header->lheader); | |
442 | 3575 if (MARKED_RECORD_HEADER_P (h)) |
428 | 3576 { |
442 | 3577 if (! C_READONLY_RECORD_HEADER_P (h)) |
428 | 3578 UNMARK_RECORD_HEADER (h); |
3579 num_used++; | |
3580 /* total_size += n->implementation->size_in_bytes (h);*/ | |
440 | 3581 /* #### May modify header->next on a C_READONLY lcrecord */ |
428 | 3582 prev = &(header->next); |
3583 header = *prev; | |
3584 tick_lcrecord_stats (h, 0); | |
3585 } | |
3586 else | |
3587 { | |
3024 | 3588 struct old_lcrecord_header *next = header->next; |
428 | 3589 *prev = next; |
3590 tick_lcrecord_stats (h, 1); | |
3591 /* used to call finalizer right here. */ | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3592 xfree (header); |
428 | 3593 header = next; |
3594 } | |
3595 } | |
3596 *used = num_used; | |
3597 /* *total = total_size; */ | |
3598 } | |
3599 | |
3600 /* And the Lord said: Thou shalt use the `c-backslash-region' command | |
3601 to make macros prettier. */ | |
3602 | |
3603 #ifdef ERROR_CHECK_GC | |
3604 | |
771 | 3605 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \ |
428 | 3606 do { \ |
3607 struct typename##_block *SFTB_current; \ | |
3608 int SFTB_limit; \ | |
3609 int num_free = 0, num_used = 0; \ | |
3610 \ | |
444 | 3611 for (SFTB_current = current_##typename##_block, \ |
428 | 3612 SFTB_limit = current_##typename##_block_index; \ |
3613 SFTB_current; \ | |
3614 ) \ | |
3615 { \ | |
3616 int SFTB_iii; \ | |
3617 \ | |
3618 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \ | |
3619 { \ | |
3620 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \ | |
3621 \ | |
454 | 3622 if (LRECORD_FREE_P (SFTB_victim)) \ |
428 | 3623 { \ |
3624 num_free++; \ | |
3625 } \ | |
3626 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \ | |
3627 { \ | |
3628 num_used++; \ | |
3629 } \ | |
442 | 3630 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \ |
428 | 3631 { \ |
3632 num_free++; \ | |
3633 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \ | |
3634 } \ | |
3635 else \ | |
3636 { \ | |
3637 num_used++; \ | |
3638 UNMARK_##typename (SFTB_victim); \ | |
3639 } \ | |
3640 } \ | |
3641 SFTB_current = SFTB_current->prev; \ | |
3642 SFTB_limit = countof (current_##typename##_block->block); \ | |
3643 } \ | |
3644 \ | |
3645 gc_count_num_##typename##_in_use = num_used; \ | |
3646 gc_count_num_##typename##_freelist = num_free; \ | |
3647 } while (0) | |
3648 | |
3649 #else /* !ERROR_CHECK_GC */ | |
3650 | |
771 | 3651 #define SWEEP_FIXED_TYPE_BLOCK_1(typename, obj_type, lheader) \ |
3652 do { \ | |
3653 struct typename##_block *SFTB_current; \ | |
3654 struct typename##_block **SFTB_prev; \ | |
3655 int SFTB_limit; \ | |
3656 int num_free = 0, num_used = 0; \ | |
3657 \ | |
3658 typename##_free_list = 0; \ | |
3659 \ | |
3660 for (SFTB_prev = ¤t_##typename##_block, \ | |
3661 SFTB_current = current_##typename##_block, \ | |
3662 SFTB_limit = current_##typename##_block_index; \ | |
3663 SFTB_current; \ | |
3664 ) \ | |
3665 { \ | |
3666 int SFTB_iii; \ | |
3667 int SFTB_empty = 1; \ | |
3668 Lisp_Free *SFTB_old_free_list = typename##_free_list; \ | |
3669 \ | |
3670 for (SFTB_iii = 0; SFTB_iii < SFTB_limit; SFTB_iii++) \ | |
3671 { \ | |
3672 obj_type *SFTB_victim = &(SFTB_current->block[SFTB_iii]); \ | |
3673 \ | |
3674 if (LRECORD_FREE_P (SFTB_victim)) \ | |
3675 { \ | |
3676 num_free++; \ | |
3677 PUT_FIXED_TYPE_ON_FREE_LIST (typename, obj_type, SFTB_victim); \ | |
3678 } \ | |
3679 else if (C_READONLY_RECORD_HEADER_P (&SFTB_victim->lheader)) \ | |
3680 { \ | |
3681 SFTB_empty = 0; \ | |
3682 num_used++; \ | |
3683 } \ | |
3684 else if (! MARKED_RECORD_HEADER_P (&SFTB_victim->lheader)) \ | |
3685 { \ | |
3686 num_free++; \ | |
3687 FREE_FIXED_TYPE (typename, obj_type, SFTB_victim); \ | |
3688 } \ | |
3689 else \ | |
3690 { \ | |
3691 SFTB_empty = 0; \ | |
3692 num_used++; \ | |
3693 UNMARK_##typename (SFTB_victim); \ | |
3694 } \ | |
3695 } \ | |
3696 if (!SFTB_empty) \ | |
3697 { \ | |
3698 SFTB_prev = &(SFTB_current->prev); \ | |
3699 SFTB_current = SFTB_current->prev; \ | |
3700 } \ | |
3701 else if (SFTB_current == current_##typename##_block \ | |
3702 && !SFTB_current->prev) \ | |
3703 { \ | |
3704 /* No real point in freeing sole allocation block */ \ | |
3705 break; \ | |
3706 } \ | |
3707 else \ | |
3708 { \ | |
3709 struct typename##_block *SFTB_victim_block = SFTB_current; \ | |
3710 if (SFTB_victim_block == current_##typename##_block) \ | |
3711 current_##typename##_block_index \ | |
3712 = countof (current_##typename##_block->block); \ | |
3713 SFTB_current = SFTB_current->prev; \ | |
3714 { \ | |
3715 *SFTB_prev = SFTB_current; \ | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3716 xfree (SFTB_victim_block); \ |
771 | 3717 /* Restore free list to what it was before victim was swept */ \ |
3718 typename##_free_list = SFTB_old_free_list; \ | |
3719 num_free -= SFTB_limit; \ | |
3720 } \ | |
3721 } \ | |
3722 SFTB_limit = countof (current_##typename##_block->block); \ | |
3723 } \ | |
3724 \ | |
3725 gc_count_num_##typename##_in_use = num_used; \ | |
3726 gc_count_num_##typename##_freelist = num_free; \ | |
428 | 3727 } while (0) |
3728 | |
3729 #endif /* !ERROR_CHECK_GC */ | |
3730 | |
771 | 3731 #define SWEEP_FIXED_TYPE_BLOCK(typename, obj_type) \ |
3732 SWEEP_FIXED_TYPE_BLOCK_1 (typename, obj_type, lheader) | |
3733 | |
3263 | 3734 #endif /* not NEW_GC */ |
2720 | 3735 |
428 | 3736 |
3263 | 3737 #ifndef NEW_GC |
428 | 3738 static void |
3739 sweep_conses (void) | |
3740 { | |
3741 #define UNMARK_cons(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3742 #define ADDITIONAL_FREE_cons(ptr) | |
3743 | |
440 | 3744 SWEEP_FIXED_TYPE_BLOCK (cons, Lisp_Cons); |
428 | 3745 } |
3263 | 3746 #endif /* not NEW_GC */ |
428 | 3747 |
3748 /* Explicitly free a cons cell. */ | |
3749 void | |
853 | 3750 free_cons (Lisp_Object cons) |
428 | 3751 { |
3263 | 3752 #ifndef NEW_GC /* to avoid compiler warning */ |
853 | 3753 Lisp_Cons *ptr = XCONS (cons); |
3263 | 3754 #endif /* not NEW_GC */ |
853 | 3755 |
428 | 3756 #ifdef ERROR_CHECK_GC |
3263 | 3757 #ifdef NEW_GC |
2720 | 3758 Lisp_Cons *ptr = XCONS (cons); |
3263 | 3759 #endif /* NEW_GC */ |
428 | 3760 /* If the CAR is not an int, then it will be a pointer, which will |
3761 always be four-byte aligned. If this cons cell has already been | |
3762 placed on the free list, however, its car will probably contain | |
3763 a chain pointer to the next cons on the list, which has cleverly | |
3764 had all its 0's and 1's inverted. This allows for a quick | |
1204 | 3765 check to make sure we're not freeing something already freed. |
3766 | |
3767 NOTE: This check may not be necessary. Freeing an object sets its | |
3768 type to lrecord_type_free, which will trip up the XCONS() above -- as | |
3769 well as a check in FREE_FIXED_TYPE(). */ | |
853 | 3770 if (POINTER_TYPE_P (XTYPE (cons_car (ptr)))) |
3771 ASSERT_VALID_POINTER (XPNTR (cons_car (ptr))); | |
428 | 3772 #endif /* ERROR_CHECK_GC */ |
3773 | |
3263 | 3774 #ifdef NEW_GC |
2720 | 3775 free_lrecord (cons); |
3263 | 3776 #else /* not NEW_GC */ |
440 | 3777 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (cons, Lisp_Cons, ptr); |
3263 | 3778 #endif /* not NEW_GC */ |
428 | 3779 } |
3780 | |
3781 /* explicitly free a list. You **must make sure** that you have | |
3782 created all the cons cells that make up this list and that there | |
3783 are no pointers to any of these cons cells anywhere else. If there | |
3784 are, you will lose. */ | |
3785 | |
3786 void | |
3787 free_list (Lisp_Object list) | |
3788 { | |
3789 Lisp_Object rest, next; | |
3790 | |
3791 for (rest = list; !NILP (rest); rest = next) | |
3792 { | |
3793 next = XCDR (rest); | |
853 | 3794 free_cons (rest); |
428 | 3795 } |
3796 } | |
3797 | |
3798 /* explicitly free an alist. You **must make sure** that you have | |
3799 created all the cons cells that make up this alist and that there | |
3800 are no pointers to any of these cons cells anywhere else. If there | |
3801 are, you will lose. */ | |
3802 | |
3803 void | |
3804 free_alist (Lisp_Object alist) | |
3805 { | |
3806 Lisp_Object rest, next; | |
3807 | |
3808 for (rest = alist; !NILP (rest); rest = next) | |
3809 { | |
3810 next = XCDR (rest); | |
853 | 3811 free_cons (XCAR (rest)); |
3812 free_cons (rest); | |
428 | 3813 } |
3814 } | |
3815 | |
3263 | 3816 #ifndef NEW_GC |
428 | 3817 static void |
3818 sweep_compiled_functions (void) | |
3819 { | |
3820 #define UNMARK_compiled_function(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
945 | 3821 #define ADDITIONAL_FREE_compiled_function(ptr) \ |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4969
diff
changeset
|
3822 if (ptr->args_in_array) xfree (ptr->args) |
428 | 3823 |
3824 SWEEP_FIXED_TYPE_BLOCK (compiled_function, Lisp_Compiled_Function); | |
3825 } | |
3826 | |
3827 static void | |
3828 sweep_floats (void) | |
3829 { | |
3830 #define UNMARK_float(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3831 #define ADDITIONAL_FREE_float(ptr) | |
3832 | |
440 | 3833 SWEEP_FIXED_TYPE_BLOCK (float, Lisp_Float); |
428 | 3834 } |
3835 | |
1983 | 3836 #ifdef HAVE_BIGNUM |
3837 static void | |
3838 sweep_bignums (void) | |
3839 { | |
3840 #define UNMARK_bignum(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3841 #define ADDITIONAL_FREE_bignum(ptr) bignum_fini (ptr->data) | |
3842 | |
3843 SWEEP_FIXED_TYPE_BLOCK (bignum, Lisp_Bignum); | |
3844 } | |
3845 #endif /* HAVE_BIGNUM */ | |
3846 | |
3847 #ifdef HAVE_RATIO | |
3848 static void | |
3849 sweep_ratios (void) | |
3850 { | |
3851 #define UNMARK_ratio(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3852 #define ADDITIONAL_FREE_ratio(ptr) ratio_fini (ptr->data) | |
3853 | |
3854 SWEEP_FIXED_TYPE_BLOCK (ratio, Lisp_Ratio); | |
3855 } | |
3856 #endif /* HAVE_RATIO */ | |
3857 | |
3858 #ifdef HAVE_BIGFLOAT | |
3859 static void | |
3860 sweep_bigfloats (void) | |
3861 { | |
3862 #define UNMARK_bigfloat(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3863 #define ADDITIONAL_FREE_bigfloat(ptr) bigfloat_fini (ptr->bf) | |
3864 | |
3865 SWEEP_FIXED_TYPE_BLOCK (bigfloat, Lisp_Bigfloat); | |
3866 } | |
3867 #endif | |
3868 | |
428 | 3869 static void |
3870 sweep_symbols (void) | |
3871 { | |
3872 #define UNMARK_symbol(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3873 #define ADDITIONAL_FREE_symbol(ptr) | |
3874 | |
440 | 3875 SWEEP_FIXED_TYPE_BLOCK (symbol, Lisp_Symbol); |
428 | 3876 } |
3877 | |
3878 static void | |
3879 sweep_extents (void) | |
3880 { | |
3881 #define UNMARK_extent(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3882 #define ADDITIONAL_FREE_extent(ptr) | |
3883 | |
3884 SWEEP_FIXED_TYPE_BLOCK (extent, struct extent); | |
3885 } | |
3886 | |
3887 static void | |
3888 sweep_events (void) | |
3889 { | |
3890 #define UNMARK_event(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3891 #define ADDITIONAL_FREE_event(ptr) | |
3892 | |
440 | 3893 SWEEP_FIXED_TYPE_BLOCK (event, Lisp_Event); |
428 | 3894 } |
3263 | 3895 #endif /* not NEW_GC */ |
428 | 3896 |
1204 | 3897 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 3898 |
3263 | 3899 #ifndef NEW_GC |
934 | 3900 static void |
3901 sweep_key_data (void) | |
3902 { | |
3903 #define UNMARK_key_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3904 #define ADDITIONAL_FREE_key_data(ptr) | |
3905 | |
3906 SWEEP_FIXED_TYPE_BLOCK (key_data, Lisp_Key_Data); | |
3907 } | |
3263 | 3908 #endif /* not NEW_GC */ |
934 | 3909 |
1204 | 3910 void |
3911 free_key_data (Lisp_Object ptr) | |
3912 { | |
3263 | 3913 #ifdef NEW_GC |
2720 | 3914 free_lrecord (ptr); |
3263 | 3915 #else /* not NEW_GC */ |
1204 | 3916 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (key_data, Lisp_Key_Data, XKEY_DATA (ptr)); |
3263 | 3917 #endif /* not NEW_GC */ |
2720 | 3918 } |
3919 | |
3263 | 3920 #ifndef NEW_GC |
934 | 3921 static void |
3922 sweep_button_data (void) | |
3923 { | |
3924 #define UNMARK_button_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3925 #define ADDITIONAL_FREE_button_data(ptr) | |
3926 | |
3927 SWEEP_FIXED_TYPE_BLOCK (button_data, Lisp_Button_Data); | |
3928 } | |
3263 | 3929 #endif /* not NEW_GC */ |
934 | 3930 |
1204 | 3931 void |
3932 free_button_data (Lisp_Object ptr) | |
3933 { | |
3263 | 3934 #ifdef NEW_GC |
2720 | 3935 free_lrecord (ptr); |
3263 | 3936 #else /* not NEW_GC */ |
1204 | 3937 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (button_data, Lisp_Button_Data, XBUTTON_DATA (ptr)); |
3263 | 3938 #endif /* not NEW_GC */ |
2720 | 3939 } |
3940 | |
3263 | 3941 #ifndef NEW_GC |
934 | 3942 static void |
3943 sweep_motion_data (void) | |
3944 { | |
3945 #define UNMARK_motion_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3946 #define ADDITIONAL_FREE_motion_data(ptr) | |
3947 | |
3948 SWEEP_FIXED_TYPE_BLOCK (motion_data, Lisp_Motion_Data); | |
3949 } | |
3263 | 3950 #endif /* not NEW_GC */ |
934 | 3951 |
1204 | 3952 void |
3953 free_motion_data (Lisp_Object ptr) | |
3954 { | |
3263 | 3955 #ifdef NEW_GC |
2720 | 3956 free_lrecord (ptr); |
3263 | 3957 #else /* not NEW_GC */ |
1204 | 3958 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (motion_data, Lisp_Motion_Data, XMOTION_DATA (ptr)); |
3263 | 3959 #endif /* not NEW_GC */ |
2720 | 3960 } |
3961 | |
3263 | 3962 #ifndef NEW_GC |
934 | 3963 static void |
3964 sweep_process_data (void) | |
3965 { | |
3966 #define UNMARK_process_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3967 #define ADDITIONAL_FREE_process_data(ptr) | |
3968 | |
3969 SWEEP_FIXED_TYPE_BLOCK (process_data, Lisp_Process_Data); | |
3970 } | |
3263 | 3971 #endif /* not NEW_GC */ |
934 | 3972 |
1204 | 3973 void |
3974 free_process_data (Lisp_Object ptr) | |
3975 { | |
3263 | 3976 #ifdef NEW_GC |
2720 | 3977 free_lrecord (ptr); |
3263 | 3978 #else /* not NEW_GC */ |
1204 | 3979 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (process_data, Lisp_Process_Data, XPROCESS_DATA (ptr)); |
3263 | 3980 #endif /* not NEW_GC */ |
2720 | 3981 } |
3982 | |
3263 | 3983 #ifndef NEW_GC |
934 | 3984 static void |
3985 sweep_timeout_data (void) | |
3986 { | |
3987 #define UNMARK_timeout_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
3988 #define ADDITIONAL_FREE_timeout_data(ptr) | |
3989 | |
3990 SWEEP_FIXED_TYPE_BLOCK (timeout_data, Lisp_Timeout_Data); | |
3991 } | |
3263 | 3992 #endif /* not NEW_GC */ |
934 | 3993 |
1204 | 3994 void |
3995 free_timeout_data (Lisp_Object ptr) | |
3996 { | |
3263 | 3997 #ifdef NEW_GC |
2720 | 3998 free_lrecord (ptr); |
3263 | 3999 #else /* not NEW_GC */ |
1204 | 4000 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (timeout_data, Lisp_Timeout_Data, XTIMEOUT_DATA (ptr)); |
3263 | 4001 #endif /* not NEW_GC */ |
2720 | 4002 } |
4003 | |
3263 | 4004 #ifndef NEW_GC |
934 | 4005 static void |
4006 sweep_magic_data (void) | |
4007 { | |
4008 #define UNMARK_magic_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4009 #define ADDITIONAL_FREE_magic_data(ptr) | |
4010 | |
4011 SWEEP_FIXED_TYPE_BLOCK (magic_data, Lisp_Magic_Data); | |
4012 } | |
3263 | 4013 #endif /* not NEW_GC */ |
934 | 4014 |
1204 | 4015 void |
4016 free_magic_data (Lisp_Object ptr) | |
4017 { | |
3263 | 4018 #ifdef NEW_GC |
2720 | 4019 free_lrecord (ptr); |
3263 | 4020 #else /* not NEW_GC */ |
1204 | 4021 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (magic_data, Lisp_Magic_Data, XMAGIC_DATA (ptr)); |
3263 | 4022 #endif /* not NEW_GC */ |
2720 | 4023 } |
4024 | |
3263 | 4025 #ifndef NEW_GC |
934 | 4026 static void |
4027 sweep_magic_eval_data (void) | |
4028 { | |
4029 #define UNMARK_magic_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4030 #define ADDITIONAL_FREE_magic_eval_data(ptr) | |
4031 | |
4032 SWEEP_FIXED_TYPE_BLOCK (magic_eval_data, Lisp_Magic_Eval_Data); | |
4033 } | |
3263 | 4034 #endif /* not NEW_GC */ |
934 | 4035 |
1204 | 4036 void |
4037 free_magic_eval_data (Lisp_Object ptr) | |
4038 { | |
3263 | 4039 #ifdef NEW_GC |
2720 | 4040 free_lrecord (ptr); |
3263 | 4041 #else /* not NEW_GC */ |
1204 | 4042 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (magic_eval_data, Lisp_Magic_Eval_Data, XMAGIC_EVAL_DATA (ptr)); |
3263 | 4043 #endif /* not NEW_GC */ |
2720 | 4044 } |
4045 | |
3263 | 4046 #ifndef NEW_GC |
934 | 4047 static void |
4048 sweep_eval_data (void) | |
4049 { | |
4050 #define UNMARK_eval_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4051 #define ADDITIONAL_FREE_eval_data(ptr) | |
4052 | |
4053 SWEEP_FIXED_TYPE_BLOCK (eval_data, Lisp_Eval_Data); | |
4054 } | |
3263 | 4055 #endif /* not NEW_GC */ |
934 | 4056 |
1204 | 4057 void |
4058 free_eval_data (Lisp_Object ptr) | |
4059 { | |
3263 | 4060 #ifdef NEW_GC |
2720 | 4061 free_lrecord (ptr); |
3263 | 4062 #else /* not NEW_GC */ |
1204 | 4063 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (eval_data, Lisp_Eval_Data, XEVAL_DATA (ptr)); |
3263 | 4064 #endif /* not NEW_GC */ |
2720 | 4065 } |
4066 | |
3263 | 4067 #ifndef NEW_GC |
934 | 4068 static void |
4069 sweep_misc_user_data (void) | |
4070 { | |
4071 #define UNMARK_misc_user_data(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4072 #define ADDITIONAL_FREE_misc_user_data(ptr) | |
4073 | |
4074 SWEEP_FIXED_TYPE_BLOCK (misc_user_data, Lisp_Misc_User_Data); | |
4075 } | |
3263 | 4076 #endif /* not NEW_GC */ |
934 | 4077 |
1204 | 4078 void |
4079 free_misc_user_data (Lisp_Object ptr) | |
4080 { | |
3263 | 4081 #ifdef NEW_GC |
2720 | 4082 free_lrecord (ptr); |
3263 | 4083 #else /* not NEW_GC */ |
1204 | 4084 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (misc_user_data, Lisp_Misc_User_Data, XMISC_USER_DATA (ptr)); |
3263 | 4085 #endif /* not NEW_GC */ |
1204 | 4086 } |
4087 | |
4088 #endif /* EVENT_DATA_AS_OBJECTS */ | |
934 | 4089 |
3263 | 4090 #ifndef NEW_GC |
428 | 4091 static void |
4092 sweep_markers (void) | |
4093 { | |
4094 #define UNMARK_marker(ptr) UNMARK_RECORD_HEADER (&((ptr)->lheader)) | |
4095 #define ADDITIONAL_FREE_marker(ptr) \ | |
4096 do { Lisp_Object tem; \ | |
793 | 4097 tem = wrap_marker (ptr); \ |
428 | 4098 unchain_marker (tem); \ |
4099 } while (0) | |
4100 | |
440 | 4101 SWEEP_FIXED_TYPE_BLOCK (marker, Lisp_Marker); |
428 | 4102 } |
3263 | 4103 #endif /* not NEW_GC */ |
428 | 4104 |
4105 /* Explicitly free a marker. */ | |
4106 void | |
1204 | 4107 free_marker (Lisp_Object ptr) |
428 | 4108 { |
3263 | 4109 #ifdef NEW_GC |
2720 | 4110 free_lrecord (ptr); |
3263 | 4111 #else /* not NEW_GC */ |
1204 | 4112 FREE_FIXED_TYPE_WHEN_NOT_IN_GC (marker, Lisp_Marker, XMARKER (ptr)); |
3263 | 4113 #endif /* not NEW_GC */ |
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 { |
4330 /* Free all unmarked records. Do this at the very beginning, | |
4331 before anything else, so that the finalize methods can safely | |
4332 examine items in the objects. sweep_lcrecords_1() makes | |
4333 sure to call all the finalize methods *before* freeing anything, | |
4334 to complete the safety. */ | |
4335 { | |
4336 int ignored; | |
4337 sweep_lcrecords_1 (&all_lcrecords, &ignored); | |
4338 } | |
4339 | |
4340 compact_string_chars (); | |
4341 | |
4342 /* Finalize methods below (called through the ADDITIONAL_FREE_foo | |
4343 macros) must be *extremely* careful to make sure they're not | |
4344 referencing freed objects. The only two existing finalize | |
4345 methods (for strings and markers) pass muster -- the string | |
4346 finalizer doesn't look at anything but its own specially- | |
4347 created block, and the marker finalizer only looks at live | |
4348 buffers (which will never be freed) and at the markers before | |
4349 and after it in the chain (which, by induction, will never be | |
4350 freed because if so, they would have already removed themselves | |
4351 from the chain). */ | |
4352 | |
4353 /* Put all unmarked strings on free list, free'ing the string chars | |
4354 of large unmarked strings */ | |
4355 sweep_strings (); | |
4356 | |
4357 /* Put all unmarked conses on free list */ | |
4358 sweep_conses (); | |
4359 | |
4360 /* Free all unmarked compiled-function objects */ | |
4361 sweep_compiled_functions (); | |
4362 | |
4363 /* Put all unmarked floats on free list */ | |
4364 sweep_floats (); | |
4365 | |
1983 | 4366 #ifdef HAVE_BIGNUM |
4367 /* Put all unmarked bignums on free list */ | |
4368 sweep_bignums (); | |
4369 #endif | |
4370 | |
4371 #ifdef HAVE_RATIO | |
4372 /* Put all unmarked ratios on free list */ | |
4373 sweep_ratios (); | |
4374 #endif | |
4375 | |
4376 #ifdef HAVE_BIGFLOAT | |
4377 /* Put all unmarked bigfloats on free list */ | |
4378 sweep_bigfloats (); | |
4379 #endif | |
4380 | |
428 | 4381 /* Put all unmarked symbols on free list */ |
4382 sweep_symbols (); | |
4383 | |
4384 /* Put all unmarked extents on free list */ | |
4385 sweep_extents (); | |
4386 | |
4387 /* Put all unmarked markers on free list. | |
4388 Dechain each one first from the buffer into which it points. */ | |
4389 sweep_markers (); | |
4390 | |
4391 sweep_events (); | |
4392 | |
1204 | 4393 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 4394 sweep_key_data (); |
4395 sweep_button_data (); | |
4396 sweep_motion_data (); | |
4397 sweep_process_data (); | |
4398 sweep_timeout_data (); | |
4399 sweep_magic_data (); | |
4400 sweep_magic_eval_data (); | |
4401 sweep_eval_data (); | |
4402 sweep_misc_user_data (); | |
1204 | 4403 #endif /* EVENT_DATA_AS_OBJECTS */ |
3263 | 4404 #endif /* not NEW_GC */ |
4405 | |
4406 #ifndef NEW_GC | |
428 | 4407 #ifdef PDUMP |
442 | 4408 pdump_objects_unmark (); |
428 | 4409 #endif |
4410 } | |
3092 | 4411 #endif /* not NEW_GC */ |
428 | 4412 |
4413 /* Clearing for disksave. */ | |
4414 | |
4415 void | |
4416 disksave_object_finalization (void) | |
4417 { | |
4418 /* It's important that certain information from the environment not get | |
4419 dumped with the executable (pathnames, environment variables, etc.). | |
4420 To make it easier to tell when this has happened with strings(1) we | |
4421 clear some known-to-be-garbage blocks of memory, so that leftover | |
4422 results of old evaluation don't look like potential problems. | |
4423 But first we set some notable variables to nil and do one more GC, | |
4424 to turn those strings into garbage. | |
440 | 4425 */ |
428 | 4426 |
4427 /* Yeah, this list is pretty ad-hoc... */ | |
4428 Vprocess_environment = Qnil; | |
771 | 4429 env_initted = 0; |
428 | 4430 Vexec_directory = Qnil; |
4431 Vdata_directory = Qnil; | |
4432 Vsite_directory = Qnil; | |
4433 Vdoc_directory = Qnil; | |
4434 Vexec_path = Qnil; | |
4435 Vload_path = Qnil; | |
4436 /* Vdump_load_path = Qnil; */ | |
4437 /* Release hash tables for locate_file */ | |
4438 Flocate_file_clear_hashing (Qt); | |
771 | 4439 uncache_home_directory (); |
776 | 4440 zero_out_command_line_status_vars (); |
872 | 4441 clear_default_devices (); |
428 | 4442 |
4443 #if defined(LOADHIST) && !(defined(LOADHIST_DUMPED) || \ | |
4444 defined(LOADHIST_BUILTIN)) | |
4445 Vload_history = Qnil; | |
4446 #endif | |
4447 Vshell_file_name = Qnil; | |
4448 | |
3092 | 4449 #ifdef NEW_GC |
4450 gc_full (); | |
4451 #else /* not NEW_GC */ | |
428 | 4452 garbage_collect_1 (); |
3092 | 4453 #endif /* not NEW_GC */ |
428 | 4454 |
4455 /* Run the disksave finalization methods of all live objects. */ | |
4456 disksave_object_finalization_1 (); | |
4457 | |
3092 | 4458 #ifndef NEW_GC |
428 | 4459 /* Zero out the uninitialized (really, unused) part of the containers |
4460 for the live strings. */ | |
4461 { | |
4462 struct string_chars_block *scb; | |
4463 for (scb = first_string_chars_block; scb; scb = scb->next) | |
4464 { | |
4465 int count = sizeof (scb->string_chars) - scb->pos; | |
4466 | |
4467 assert (count >= 0 && count < STRING_CHARS_BLOCK_SIZE); | |
440 | 4468 if (count != 0) |
4469 { | |
4470 /* from the block's fill ptr to the end */ | |
4471 memset ((scb->string_chars + scb->pos), 0, count); | |
4472 } | |
428 | 4473 } |
4474 } | |
3092 | 4475 #endif /* not NEW_GC */ |
428 | 4476 |
4477 /* There, that ought to be enough... */ | |
4478 | |
4479 } | |
4480 | |
2994 | 4481 #ifdef ALLOC_TYPE_STATS |
4482 | |
2720 | 4483 static Lisp_Object |
2994 | 4484 gc_plist_hack (const Ascbyte *name, EMACS_INT value, Lisp_Object tail) |
2720 | 4485 { |
4486 /* C doesn't have local functions (or closures, or GC, or readable syntax, | |
4487 or portable numeric datatypes, or bit-vectors, or characters, or | |
4488 arrays, or exceptions, or ...) */ | |
4489 return cons3 (intern (name), make_int (value), tail); | |
4490 } | |
2775 | 4491 |
2994 | 4492 static Lisp_Object |
4493 object_memory_usage_stats (int set_total_gc_usage) | |
2720 | 4494 { |
4495 Lisp_Object pl = Qnil; | |
4496 int i; | |
2994 | 4497 EMACS_INT tgu_val = 0; |
4498 | |
3263 | 4499 #ifdef NEW_GC |
2775 | 4500 |
3461 | 4501 for (i = 0; i < countof (lrecord_implementations_table); i++) |
2720 | 4502 { |
4503 if (lrecord_stats[i].instances_in_use != 0) | |
4504 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
4505 Ascbyte buf[255]; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
4506 const Ascbyte *name = lrecord_implementations_table[i]->name; |
2720 | 4507 int len = strlen (name); |
4508 | |
4509 if (lrecord_stats[i].bytes_in_use_including_overhead != | |
4510 lrecord_stats[i].bytes_in_use) | |
4511 { | |
4512 sprintf (buf, "%s-storage-including-overhead", name); | |
4513 pl = gc_plist_hack (buf, | |
4514 lrecord_stats[i] | |
4515 .bytes_in_use_including_overhead, | |
4516 pl); | |
4517 } | |
4518 | |
4519 sprintf (buf, "%s-storage", name); | |
4520 pl = gc_plist_hack (buf, | |
4521 lrecord_stats[i].bytes_in_use, | |
4522 pl); | |
2994 | 4523 tgu_val += lrecord_stats[i].bytes_in_use_including_overhead; |
2720 | 4524 |
4525 if (name[len-1] == 's') | |
4526 sprintf (buf, "%ses-used", name); | |
4527 else | |
4528 sprintf (buf, "%ss-used", name); | |
4529 pl = gc_plist_hack (buf, lrecord_stats[i].instances_in_use, pl); | |
4530 } | |
4531 } | |
2994 | 4532 |
3263 | 4533 #else /* not NEW_GC */ |
428 | 4534 |
4535 #define HACK_O_MATIC(type, name, pl) do { \ | |
2994 | 4536 EMACS_INT s = 0; \ |
428 | 4537 struct type##_block *x = current_##type##_block; \ |
4538 while (x) { s += sizeof (*x) + MALLOC_OVERHEAD; x = x->prev; } \ | |
2994 | 4539 tgu_val += s; \ |
428 | 4540 (pl) = gc_plist_hack ((name), s, (pl)); \ |
4541 } while (0) | |
4542 | |
442 | 4543 for (i = 0; i < lrecord_type_count; i++) |
428 | 4544 { |
4545 if (lcrecord_stats[i].bytes_in_use != 0 | |
4546 || lcrecord_stats[i].bytes_freed != 0 | |
4547 || lcrecord_stats[i].instances_on_free_list != 0) | |
4548 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
4549 Ascbyte buf[255]; |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
4550 const Ascbyte *name = lrecord_implementations_table[i]->name; |
428 | 4551 int len = strlen (name); |
4552 | |
4553 sprintf (buf, "%s-storage", name); | |
4554 pl = gc_plist_hack (buf, lcrecord_stats[i].bytes_in_use, pl); | |
2994 | 4555 tgu_val += lcrecord_stats[i].bytes_in_use; |
428 | 4556 /* Okay, simple pluralization check for `symbol-value-varalias' */ |
4557 if (name[len-1] == 's') | |
4558 sprintf (buf, "%ses-freed", name); | |
4559 else | |
4560 sprintf (buf, "%ss-freed", name); | |
4561 if (lcrecord_stats[i].instances_freed != 0) | |
4562 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_freed, pl); | |
4563 if (name[len-1] == 's') | |
4564 sprintf (buf, "%ses-on-free-list", name); | |
4565 else | |
4566 sprintf (buf, "%ss-on-free-list", name); | |
4567 if (lcrecord_stats[i].instances_on_free_list != 0) | |
4568 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_on_free_list, | |
4569 pl); | |
4570 if (name[len-1] == 's') | |
4571 sprintf (buf, "%ses-used", name); | |
4572 else | |
4573 sprintf (buf, "%ss-used", name); | |
4574 pl = gc_plist_hack (buf, lcrecord_stats[i].instances_in_use, pl); | |
4575 } | |
4576 } | |
4577 | |
4578 HACK_O_MATIC (extent, "extent-storage", pl); | |
4579 pl = gc_plist_hack ("extents-free", gc_count_num_extent_freelist, pl); | |
4580 pl = gc_plist_hack ("extents-used", gc_count_num_extent_in_use, pl); | |
4581 HACK_O_MATIC (event, "event-storage", pl); | |
4582 pl = gc_plist_hack ("events-free", gc_count_num_event_freelist, pl); | |
4583 pl = gc_plist_hack ("events-used", gc_count_num_event_in_use, pl); | |
4584 HACK_O_MATIC (marker, "marker-storage", pl); | |
4585 pl = gc_plist_hack ("markers-free", gc_count_num_marker_freelist, pl); | |
4586 pl = gc_plist_hack ("markers-used", gc_count_num_marker_in_use, pl); | |
4587 HACK_O_MATIC (float, "float-storage", pl); | |
4588 pl = gc_plist_hack ("floats-free", gc_count_num_float_freelist, pl); | |
4589 pl = gc_plist_hack ("floats-used", gc_count_num_float_in_use, pl); | |
1983 | 4590 #ifdef HAVE_BIGNUM |
4591 HACK_O_MATIC (bignum, "bignum-storage", pl); | |
4592 pl = gc_plist_hack ("bignums-free", gc_count_num_bignum_freelist, pl); | |
4593 pl = gc_plist_hack ("bignums-used", gc_count_num_bignum_in_use, pl); | |
4594 #endif /* HAVE_BIGNUM */ | |
4595 #ifdef HAVE_RATIO | |
4596 HACK_O_MATIC (ratio, "ratio-storage", pl); | |
4597 pl = gc_plist_hack ("ratios-free", gc_count_num_ratio_freelist, pl); | |
4598 pl = gc_plist_hack ("ratios-used", gc_count_num_ratio_in_use, pl); | |
4599 #endif /* HAVE_RATIO */ | |
4600 #ifdef HAVE_BIGFLOAT | |
4601 HACK_O_MATIC (bigfloat, "bigfloat-storage", pl); | |
4602 pl = gc_plist_hack ("bigfloats-free", gc_count_num_bigfloat_freelist, pl); | |
4603 pl = gc_plist_hack ("bigfloats-used", gc_count_num_bigfloat_in_use, pl); | |
4604 #endif /* HAVE_BIGFLOAT */ | |
428 | 4605 HACK_O_MATIC (string, "string-header-storage", pl); |
4606 pl = gc_plist_hack ("long-strings-total-length", | |
4607 gc_count_string_total_size | |
4608 - gc_count_short_string_total_size, pl); | |
4609 HACK_O_MATIC (string_chars, "short-string-storage", pl); | |
4610 pl = gc_plist_hack ("short-strings-total-length", | |
4611 gc_count_short_string_total_size, pl); | |
4612 pl = gc_plist_hack ("strings-free", gc_count_num_string_freelist, pl); | |
4613 pl = gc_plist_hack ("long-strings-used", | |
4614 gc_count_num_string_in_use | |
4615 - gc_count_num_short_string_in_use, pl); | |
4616 pl = gc_plist_hack ("short-strings-used", | |
4617 gc_count_num_short_string_in_use, pl); | |
4618 | |
4619 HACK_O_MATIC (compiled_function, "compiled-function-storage", pl); | |
4620 pl = gc_plist_hack ("compiled-functions-free", | |
4621 gc_count_num_compiled_function_freelist, pl); | |
4622 pl = gc_plist_hack ("compiled-functions-used", | |
4623 gc_count_num_compiled_function_in_use, pl); | |
4624 | |
4625 HACK_O_MATIC (symbol, "symbol-storage", pl); | |
4626 pl = gc_plist_hack ("symbols-free", gc_count_num_symbol_freelist, pl); | |
4627 pl = gc_plist_hack ("symbols-used", gc_count_num_symbol_in_use, pl); | |
4628 | |
4629 HACK_O_MATIC (cons, "cons-storage", pl); | |
4630 pl = gc_plist_hack ("conses-free", gc_count_num_cons_freelist, pl); | |
4631 pl = gc_plist_hack ("conses-used", gc_count_num_cons_in_use, pl); | |
4632 | |
2994 | 4633 #undef HACK_O_MATIC |
4634 | |
3263 | 4635 #endif /* NEW_GC */ |
2994 | 4636 |
4637 if (set_total_gc_usage) | |
4638 { | |
4639 total_gc_usage = tgu_val; | |
4640 total_gc_usage_set = 1; | |
4641 } | |
4642 | |
4643 return pl; | |
4644 } | |
4645 | |
4646 DEFUN("object-memory-usage-stats", Fobject_memory_usage_stats, 0, 0 ,"", /* | |
4647 Return statistics about memory usage of Lisp objects. | |
4648 */ | |
4649 ()) | |
4650 { | |
4651 return object_memory_usage_stats (0); | |
4652 } | |
4653 | |
4654 #endif /* ALLOC_TYPE_STATS */ | |
4655 | |
4656 /* Debugging aids. */ | |
4657 | |
4658 DEFUN ("garbage-collect", Fgarbage_collect, 0, 0, "", /* | |
4659 Reclaim storage for Lisp objects no longer needed. | |
4660 Return info on amount of space in use: | |
4661 ((USED-CONSES . FREE-CONSES) (USED-SYMS . FREE-SYMS) | |
4662 (USED-MARKERS . FREE-MARKERS) USED-STRING-CHARS USED-VECTOR-SLOTS | |
4663 PLIST) | |
4664 where `PLIST' is a list of alternating keyword/value pairs providing | |
4665 more detailed information. | |
4666 Garbage collection happens automatically if you cons more than | |
4667 `gc-cons-threshold' bytes of Lisp data since previous garbage collection. | |
4668 */ | |
4669 ()) | |
4670 { | |
4671 /* Record total usage for purposes of determining next GC */ | |
3092 | 4672 #ifdef NEW_GC |
4673 gc_full (); | |
4674 #else /* not NEW_GC */ | |
2994 | 4675 garbage_collect_1 (); |
3092 | 4676 #endif /* not NEW_GC */ |
2994 | 4677 |
4678 /* This will get set to 1, and total_gc_usage computed, as part of the | |
4679 call to object_memory_usage_stats() -- if ALLOC_TYPE_STATS is enabled. */ | |
4680 total_gc_usage_set = 0; | |
4681 #ifdef ALLOC_TYPE_STATS | |
428 | 4682 /* The things we do for backwards-compatibility */ |
3263 | 4683 #ifdef NEW_GC |
2994 | 4684 return |
4685 list6 | |
4686 (Fcons (make_int (lrecord_stats[lrecord_type_cons].instances_in_use), | |
4687 make_int (lrecord_stats[lrecord_type_cons] | |
4688 .bytes_in_use_including_overhead)), | |
4689 Fcons (make_int (lrecord_stats[lrecord_type_symbol].instances_in_use), | |
4690 make_int (lrecord_stats[lrecord_type_symbol] | |
4691 .bytes_in_use_including_overhead)), | |
4692 Fcons (make_int (lrecord_stats[lrecord_type_marker].instances_in_use), | |
4693 make_int (lrecord_stats[lrecord_type_marker] | |
4694 .bytes_in_use_including_overhead)), | |
4695 make_int (lrecord_stats[lrecord_type_string] | |
4696 .bytes_in_use_including_overhead), | |
4697 make_int (lrecord_stats[lrecord_type_vector] | |
4698 .bytes_in_use_including_overhead), | |
4699 object_memory_usage_stats (1)); | |
3263 | 4700 #else /* not NEW_GC */ |
428 | 4701 return |
4702 list6 (Fcons (make_int (gc_count_num_cons_in_use), | |
4703 make_int (gc_count_num_cons_freelist)), | |
4704 Fcons (make_int (gc_count_num_symbol_in_use), | |
4705 make_int (gc_count_num_symbol_freelist)), | |
4706 Fcons (make_int (gc_count_num_marker_in_use), | |
4707 make_int (gc_count_num_marker_freelist)), | |
4708 make_int (gc_count_string_total_size), | |
2994 | 4709 make_int (lcrecord_stats[lrecord_type_vector].bytes_in_use + |
4710 lcrecord_stats[lrecord_type_vector].bytes_freed), | |
4711 object_memory_usage_stats (1)); | |
3263 | 4712 #endif /* not NEW_GC */ |
2994 | 4713 #else /* not ALLOC_TYPE_STATS */ |
4714 return Qnil; | |
4715 #endif /* ALLOC_TYPE_STATS */ | |
4716 } | |
428 | 4717 |
4718 DEFUN ("consing-since-gc", Fconsing_since_gc, 0, 0, "", /* | |
4719 Return the number of bytes consed since the last garbage collection. | |
4720 \"Consed\" is a misnomer in that this actually counts allocation | |
4721 of all different kinds of objects, not just conses. | |
4722 | |
4723 If this value exceeds `gc-cons-threshold', a garbage collection happens. | |
4724 */ | |
4725 ()) | |
4726 { | |
4727 return make_int (consing_since_gc); | |
4728 } | |
4729 | |
440 | 4730 #if 0 |
444 | 4731 DEFUN ("memory-limit", Fmemory_limit, 0, 0, 0, /* |
801 | 4732 Return the address of the last byte XEmacs has allocated, divided by 1024. |
4733 This may be helpful in debugging XEmacs's memory usage. | |
428 | 4734 The value is divided by 1024 to make sure it will fit in a lisp integer. |
4735 */ | |
4736 ()) | |
4737 { | |
4738 return make_int ((EMACS_INT) sbrk (0) / 1024); | |
4739 } | |
440 | 4740 #endif |
428 | 4741 |
2994 | 4742 DEFUN ("total-memory-usage", Ftotal_memory_usage, 0, 0, 0, /* |
801 | 4743 Return the total number of bytes used by the data segment in XEmacs. |
4744 This may be helpful in debugging XEmacs's memory usage. | |
2994 | 4745 NOTE: This may or may not be accurate! It is hard to determine this |
4746 value in a system-independent fashion. On Windows, for example, the | |
4747 returned number tends to be much greater than reality. | |
801 | 4748 */ |
4749 ()) | |
4750 { | |
4751 return make_int (total_data_usage ()); | |
4752 } | |
4753 | |
2994 | 4754 #ifdef ALLOC_TYPE_STATS |
4755 DEFUN ("object-memory-usage", Fobject_memory_usage, 0, 0, 0, /* | |
4756 Return total number of bytes used for object storage in XEmacs. | |
4757 This may be helpful in debugging XEmacs's memory usage. | |
4758 See also `consing-since-gc' and `object-memory-usage-stats'. | |
4759 */ | |
4760 ()) | |
4761 { | |
4762 return make_int (total_gc_usage + consing_since_gc); | |
4763 } | |
4764 #endif /* ALLOC_TYPE_STATS */ | |
4765 | |
4803
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4766 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4767 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
|
4768 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
|
4769 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
|
4770 */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4771 ()) |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4772 { |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4773 VALGRIND_DO_LEAK_CHECK; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4774 return Qnil; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4775 } |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4776 |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4777 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
|
4778 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
|
4779 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
|
4780 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
|
4781 */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4782 ()) |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4783 { |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4784 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
|
4785 return Qnil; |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4786 } |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4787 #endif /* USE_VALGRIND */ |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
4788 |
851 | 4789 void |
4790 recompute_funcall_allocation_flag (void) | |
4791 { | |
887 | 4792 funcall_allocation_flag = |
4793 need_to_garbage_collect || | |
4794 need_to_check_c_alloca || | |
4795 need_to_signal_post_gc; | |
851 | 4796 } |
4797 | |
428 | 4798 |
4799 int | |
4800 object_dead_p (Lisp_Object obj) | |
4801 { | |
4802 return ((BUFFERP (obj) && !BUFFER_LIVE_P (XBUFFER (obj))) || | |
4803 (FRAMEP (obj) && !FRAME_LIVE_P (XFRAME (obj))) || | |
4804 (WINDOWP (obj) && !WINDOW_LIVE_P (XWINDOW (obj))) || | |
4805 (DEVICEP (obj) && !DEVICE_LIVE_P (XDEVICE (obj))) || | |
4806 (CONSOLEP (obj) && !CONSOLE_LIVE_P (XCONSOLE (obj))) || | |
4807 (EVENTP (obj) && !EVENT_LIVE_P (XEVENT (obj))) || | |
4808 (EXTENTP (obj) && !EXTENT_LIVE_P (XEXTENT (obj)))); | |
4809 } | |
4810 | |
4811 #ifdef MEMORY_USAGE_STATS | |
4812 | |
4813 /* Attempt to determine the actual amount of space that is used for | |
4814 the block allocated starting at PTR, supposedly of size "CLAIMED_SIZE". | |
4815 | |
4816 It seems that the following holds: | |
4817 | |
4818 1. When using the old allocator (malloc.c): | |
4819 | |
4820 -- blocks are always allocated in chunks of powers of two. For | |
4821 each block, there is an overhead of 8 bytes if rcheck is not | |
4822 defined, 20 bytes if it is defined. In other words, a | |
4823 one-byte allocation needs 8 bytes of overhead for a total of | |
4824 9 bytes, and needs to have 16 bytes of memory chunked out for | |
4825 it. | |
4826 | |
4827 2. When using the new allocator (gmalloc.c): | |
4828 | |
4829 -- blocks are always allocated in chunks of powers of two up | |
4830 to 4096 bytes. Larger blocks are allocated in chunks of | |
4831 an integral multiple of 4096 bytes. The minimum block | |
4832 size is 2*sizeof (void *), or 16 bytes if SUNOS_LOCALTIME_BUG | |
4833 is defined. There is no per-block overhead, but there | |
4834 is an overhead of 3*sizeof (size_t) for each 4096 bytes | |
4835 allocated. | |
4836 | |
4837 3. When using the system malloc, anything goes, but they are | |
4838 generally slower and more space-efficient than the GNU | |
4839 allocators. One possibly reasonable assumption to make | |
4840 for want of better data is that sizeof (void *), or maybe | |
4841 2 * sizeof (void *), is required as overhead and that | |
4842 blocks are allocated in the minimum required size except | |
4843 that some minimum block size is imposed (e.g. 16 bytes). */ | |
4844 | |
665 | 4845 Bytecount |
2286 | 4846 malloced_storage_size (void *UNUSED (ptr), Bytecount claimed_size, |
428 | 4847 struct overhead_stats *stats) |
4848 { | |
665 | 4849 Bytecount orig_claimed_size = claimed_size; |
428 | 4850 |
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
|
4851 #ifndef SYSTEM_MALLOC |
665 | 4852 if (claimed_size < (Bytecount) (2 * sizeof (void *))) |
428 | 4853 claimed_size = 2 * sizeof (void *); |
4854 # ifdef SUNOS_LOCALTIME_BUG | |
4855 if (claimed_size < 16) | |
4856 claimed_size = 16; | |
4857 # endif | |
4858 if (claimed_size < 4096) | |
4859 { | |
2260 | 4860 /* fxg: rename log->log2 to supress gcc3 shadow warning */ |
4861 int log2 = 1; | |
428 | 4862 |
4863 /* compute the log base two, more or less, then use it to compute | |
4864 the block size needed. */ | |
4865 claimed_size--; | |
4866 /* It's big, it's heavy, it's wood! */ | |
4867 while ((claimed_size /= 2) != 0) | |
2260 | 4868 ++log2; |
428 | 4869 claimed_size = 1; |
4870 /* It's better than bad, it's good! */ | |
2260 | 4871 while (log2 > 0) |
428 | 4872 { |
4873 claimed_size *= 2; | |
2260 | 4874 log2--; |
428 | 4875 } |
4876 /* We have to come up with some average about the amount of | |
4877 blocks used. */ | |
665 | 4878 if ((Bytecount) (rand () & 4095) < claimed_size) |
428 | 4879 claimed_size += 3 * sizeof (void *); |
4880 } | |
4881 else | |
4882 { | |
4883 claimed_size += 4095; | |
4884 claimed_size &= ~4095; | |
4885 claimed_size += (claimed_size / 4096) * 3 * sizeof (size_t); | |
4886 } | |
4887 | |
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
|
4888 #else |
428 | 4889 |
4890 if (claimed_size < 16) | |
4891 claimed_size = 16; | |
4892 claimed_size += 2 * sizeof (void *); | |
4893 | |
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
|
4894 #endif /* system allocator */ |
428 | 4895 |
4896 if (stats) | |
4897 { | |
4898 stats->was_requested += orig_claimed_size; | |
4899 stats->malloc_overhead += claimed_size - orig_claimed_size; | |
4900 } | |
4901 return claimed_size; | |
4902 } | |
4903 | |
3263 | 4904 #ifndef NEW_GC |
665 | 4905 Bytecount |
4906 fixed_type_block_overhead (Bytecount size) | |
428 | 4907 { |
665 | 4908 Bytecount per_block = TYPE_ALLOC_SIZE (cons, unsigned char); |
4909 Bytecount overhead = 0; | |
4910 Bytecount storage_size = malloced_storage_size (0, per_block, 0); | |
428 | 4911 while (size >= per_block) |
4912 { | |
4913 size -= per_block; | |
4914 overhead += sizeof (void *) + per_block - storage_size; | |
4915 } | |
4916 if (rand () % per_block < size) | |
4917 overhead += sizeof (void *) + per_block - storage_size; | |
4918 return overhead; | |
4919 } | |
3263 | 4920 #endif /* not NEW_GC */ |
428 | 4921 #endif /* MEMORY_USAGE_STATS */ |
4922 | |
4923 | |
4924 /* Initialization */ | |
771 | 4925 static void |
1204 | 4926 common_init_alloc_early (void) |
428 | 4927 { |
771 | 4928 #ifndef Qzero |
4929 Qzero = make_int (0); /* Only used if Lisp_Object is a union type */ | |
4930 #endif | |
4931 | |
4932 #ifndef Qnull_pointer | |
4933 /* C guarantees that Qnull_pointer will be initialized to all 0 bits, | |
4934 so the following is actually a no-op. */ | |
793 | 4935 Qnull_pointer = wrap_pointer_1 (0); |
771 | 4936 #endif |
4937 | |
3263 | 4938 #ifndef NEW_GC |
428 | 4939 breathing_space = 0; |
4940 all_lcrecords = 0; | |
3263 | 4941 #endif /* not NEW_GC */ |
428 | 4942 ignore_malloc_warnings = 1; |
4943 #ifdef DOUG_LEA_MALLOC | |
4944 mallopt (M_TRIM_THRESHOLD, 128*1024); /* trim threshold */ | |
4945 mallopt (M_MMAP_THRESHOLD, 64*1024); /* mmap threshold */ | |
4946 #if 0 /* Moved to emacs.c */ | |
4947 mallopt (M_MMAP_MAX, 64); /* max. number of mmap'ed areas */ | |
4948 #endif | |
4949 #endif | |
3092 | 4950 #ifndef NEW_GC |
2720 | 4951 init_string_chars_alloc (); |
428 | 4952 init_string_alloc (); |
4953 init_string_chars_alloc (); | |
4954 init_cons_alloc (); | |
4955 init_symbol_alloc (); | |
4956 init_compiled_function_alloc (); | |
4957 init_float_alloc (); | |
1983 | 4958 #ifdef HAVE_BIGNUM |
4959 init_bignum_alloc (); | |
4960 #endif | |
4961 #ifdef HAVE_RATIO | |
4962 init_ratio_alloc (); | |
4963 #endif | |
4964 #ifdef HAVE_BIGFLOAT | |
4965 init_bigfloat_alloc (); | |
4966 #endif | |
428 | 4967 init_marker_alloc (); |
4968 init_extent_alloc (); | |
4969 init_event_alloc (); | |
1204 | 4970 #ifdef EVENT_DATA_AS_OBJECTS |
934 | 4971 init_key_data_alloc (); |
4972 init_button_data_alloc (); | |
4973 init_motion_data_alloc (); | |
4974 init_process_data_alloc (); | |
4975 init_timeout_data_alloc (); | |
4976 init_magic_data_alloc (); | |
4977 init_magic_eval_data_alloc (); | |
4978 init_eval_data_alloc (); | |
4979 init_misc_user_data_alloc (); | |
1204 | 4980 #endif /* EVENT_DATA_AS_OBJECTS */ |
3263 | 4981 #endif /* not NEW_GC */ |
428 | 4982 |
4983 ignore_malloc_warnings = 0; | |
4984 | |
452 | 4985 if (staticpros_nodump) |
4986 Dynarr_free (staticpros_nodump); | |
4987 staticpros_nodump = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); | |
4988 Dynarr_resize (staticpros_nodump, 100); /* merely a small optimization */ | |
771 | 4989 #ifdef DEBUG_XEMACS |
4990 if (staticpro_nodump_names) | |
4991 Dynarr_free (staticpro_nodump_names); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
4992 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
|
4993 const Ascbyte *); |
771 | 4994 Dynarr_resize (staticpro_nodump_names, 100); /* ditto */ |
4995 #endif | |
428 | 4996 |
3263 | 4997 #ifdef NEW_GC |
2720 | 4998 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
4999 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
5000 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
5001 #ifdef DEBUG_XEMACS | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5002 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
2720 | 5003 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
|
5004 dump_add_root_block_ptr (&mcpro_names, |
4964 | 5005 &const_Ascbyte_ptr_dynarr_description); |
2720 | 5006 #endif |
3263 | 5007 #endif /* NEW_GC */ |
2720 | 5008 |
428 | 5009 consing_since_gc = 0; |
851 | 5010 need_to_check_c_alloca = 0; |
5011 funcall_allocation_flag = 0; | |
5012 funcall_alloca_count = 0; | |
814 | 5013 |
428 | 5014 lrecord_uid_counter = 259; |
3263 | 5015 #ifndef NEW_GC |
428 | 5016 debug_string_purity = 0; |
3263 | 5017 #endif /* not NEW_GC */ |
428 | 5018 |
800 | 5019 #ifdef ERROR_CHECK_TYPES |
428 | 5020 ERROR_ME.really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = |
5021 666; | |
5022 ERROR_ME_NOT. | |
5023 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = 42; | |
5024 ERROR_ME_WARN. | |
5025 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
5026 3333632; | |
793 | 5027 ERROR_ME_DEBUG_WARN. |
5028 really_unlikely_name_to_have_accidentally_in_a_non_errb_structure = | |
5029 8675309; | |
800 | 5030 #endif /* ERROR_CHECK_TYPES */ |
428 | 5031 } |
5032 | |
3263 | 5033 #ifndef NEW_GC |
771 | 5034 static void |
5035 init_lcrecord_lists (void) | |
5036 { | |
5037 int i; | |
5038 | |
5039 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
5040 { | |
5041 all_lcrecord_lists[i] = Qzero; /* Qnil not yet set */ | |
5042 staticpro_nodump (&all_lcrecord_lists[i]); | |
5043 } | |
5044 } | |
3263 | 5045 #endif /* not NEW_GC */ |
771 | 5046 |
5047 void | |
1204 | 5048 init_alloc_early (void) |
771 | 5049 { |
1204 | 5050 #if defined (__cplusplus) && defined (ERROR_CHECK_GC) |
5051 static struct gcpro initial_gcpro; | |
5052 | |
5053 initial_gcpro.next = 0; | |
5054 initial_gcpro.var = &Qnil; | |
5055 initial_gcpro.nvars = 1; | |
5056 gcprolist = &initial_gcpro; | |
5057 #else | |
5058 gcprolist = 0; | |
5059 #endif /* defined (__cplusplus) && defined (ERROR_CHECK_GC) */ | |
5060 } | |
5061 | |
5062 void | |
5063 reinit_alloc_early (void) | |
5064 { | |
5065 common_init_alloc_early (); | |
3263 | 5066 #ifndef NEW_GC |
771 | 5067 init_lcrecord_lists (); |
3263 | 5068 #endif /* not NEW_GC */ |
771 | 5069 } |
5070 | |
428 | 5071 void |
5072 init_alloc_once_early (void) | |
5073 { | |
1204 | 5074 common_init_alloc_early (); |
428 | 5075 |
442 | 5076 { |
5077 int i; | |
5078 for (i = 0; i < countof (lrecord_implementations_table); i++) | |
5079 lrecord_implementations_table[i] = 0; | |
5080 } | |
5081 | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
5082 INIT_LISP_OBJECT (cons); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
5083 INIT_LISP_OBJECT (vector); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
5084 INIT_LISP_OBJECT (string); |
3092 | 5085 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
5086 INIT_LISP_OBJECT (string_indirect_data); |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
5087 INIT_LISP_OBJECT (string_direct_data); |
3092 | 5088 #endif /* NEW_GC */ |
3263 | 5089 #ifndef NEW_GC |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
5090 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
|
5091 INIT_LISP_OBJECT (free); |
3263 | 5092 #endif /* not NEW_GC */ |
428 | 5093 |
452 | 5094 staticpros = Dynarr_new2 (Lisp_Object_ptr_dynarr, Lisp_Object *); |
5095 Dynarr_resize (staticpros, 1410); /* merely a small optimization */ | |
2367 | 5096 dump_add_root_block_ptr (&staticpros, &staticpros_description); |
771 | 5097 #ifdef DEBUG_XEMACS |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5098 staticpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
771 | 5099 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
|
5100 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
|
5101 &const_Ascbyte_ptr_dynarr_description); |
771 | 5102 #endif |
5103 | |
3263 | 5104 #ifdef NEW_GC |
2720 | 5105 mcpros = Dynarr_new2 (Lisp_Object_dynarr, Lisp_Object); |
5106 Dynarr_resize (mcpros, 1410); /* merely a small optimization */ | |
5107 dump_add_root_block_ptr (&mcpros, &mcpros_description); | |
5108 #ifdef DEBUG_XEMACS | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4938
diff
changeset
|
5109 mcpro_names = Dynarr_new2 (const_Ascbyte_ptr_dynarr, const Ascbyte *); |
2720 | 5110 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
|
5111 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
|
5112 &const_Ascbyte_ptr_dynarr_description); |
2720 | 5113 #endif |
3263 | 5114 #else /* not NEW_GC */ |
771 | 5115 init_lcrecord_lists (); |
3263 | 5116 #endif /* not NEW_GC */ |
428 | 5117 } |
5118 | |
5119 void | |
5120 syms_of_alloc (void) | |
5121 { | |
442 | 5122 DEFSYMBOL (Qgarbage_collecting); |
428 | 5123 |
5124 DEFSUBR (Fcons); | |
5125 DEFSUBR (Flist); | |
5126 DEFSUBR (Fvector); | |
5127 DEFSUBR (Fbit_vector); | |
5128 DEFSUBR (Fmake_byte_code); | |
5129 DEFSUBR (Fmake_list); | |
5130 DEFSUBR (Fmake_vector); | |
5131 DEFSUBR (Fmake_bit_vector); | |
5132 DEFSUBR (Fmake_string); | |
5133 DEFSUBR (Fstring); | |
5134 DEFSUBR (Fmake_symbol); | |
5135 DEFSUBR (Fmake_marker); | |
5136 DEFSUBR (Fpurecopy); | |
2994 | 5137 #ifdef ALLOC_TYPE_STATS |
5138 DEFSUBR (Fobject_memory_usage_stats); | |
5139 DEFSUBR (Fobject_memory_usage); | |
5140 #endif /* ALLOC_TYPE_STATS */ | |
428 | 5141 DEFSUBR (Fgarbage_collect); |
440 | 5142 #if 0 |
428 | 5143 DEFSUBR (Fmemory_limit); |
440 | 5144 #endif |
2994 | 5145 DEFSUBR (Ftotal_memory_usage); |
428 | 5146 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
|
5147 #ifdef USE_VALGRIND |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5148 DEFSUBR (Fvalgrind_leak_check); |
5d120deb60ca
Enable rudimentary support for valgrind, including functions that tell valgrind
Jerry James <james@xemacs.org>
parents:
4776
diff
changeset
|
5149 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
|
5150 #endif |
428 | 5151 } |
5152 | |
5153 void | |
5154 vars_of_alloc (void) | |
5155 { | |
5156 #ifdef DEBUG_XEMACS | |
5157 DEFVAR_INT ("debug-allocation", &debug_allocation /* | |
5158 If non-zero, print out information to stderr about all objects allocated. | |
5159 See also `debug-allocation-backtrace-length'. | |
5160 */ ); | |
5161 debug_allocation = 0; | |
5162 | |
5163 DEFVAR_INT ("debug-allocation-backtrace-length", | |
5164 &debug_allocation_backtrace_length /* | |
5165 Length (in stack frames) of short backtrace printed out by `debug-allocation'. | |
5166 */ ); | |
5167 debug_allocation_backtrace_length = 2; | |
5168 #endif | |
5169 | |
5170 DEFVAR_BOOL ("purify-flag", &purify_flag /* | |
5171 Non-nil means loading Lisp code in order to dump an executable. | |
5172 This means that certain objects should be allocated in readonly space. | |
5173 */ ); | |
5174 } |