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