Mercurial > emacs
comparison src/alloc.c @ 85674:01258ecfc38e
(spare_memory, stack_copy, stack_copy_size, ignore_warnings, Vdead,
dont_register_blocks, staticvec, staticidx, interval_block, n_interval_blocks,
init_strings, check_string_bytes, check_sblock, init_float, free_float,
n_cons_blocks, init_cons, all_vectors, n_vectors, symbol_block,
symbol_block_index, symbol_free_list, n_symbol_blocks, init_symbol,
marker_block, marker_free_list, n_marker_blocks, init_marker, valid_pointer_p,
make_pure_float, last_marked, mark_object_loop_halt): Make static.
| author | Juanma Barranquero <lekktu@gmail.com> |
|---|---|
| date | Fri, 26 Oct 2007 13:42:26 +0000 |
| parents | 99492f857499 |
| children | 1ede747999c6 4bc33ffdda1a |
comparison
equal
deleted
inserted
replaced
| 85673:beece3f27ef3 | 85674:01258ecfc38e |
|---|---|
| 239 | 239 |
| 240 /* Points to memory space allocated as "spare", to be freed if we run | 240 /* Points to memory space allocated as "spare", to be freed if we run |
| 241 out of memory. We keep one large block, four cons-blocks, and | 241 out of memory. We keep one large block, four cons-blocks, and |
| 242 two string blocks. */ | 242 two string blocks. */ |
| 243 | 243 |
| 244 char *spare_memory[7]; | 244 static char *spare_memory[7]; |
| 245 | 245 |
| 246 /* Amount of spare memory to keep in large reserve block. */ | 246 /* Amount of spare memory to keep in large reserve block. */ |
| 247 | 247 |
| 248 #define SPARE_MEMORY (1 << 14) | 248 #define SPARE_MEMORY (1 << 14) |
| 249 | 249 |
| 322 #define MAX_SAVE_STACK 16000 | 322 #define MAX_SAVE_STACK 16000 |
| 323 #endif | 323 #endif |
| 324 | 324 |
| 325 /* Buffer in which we save a copy of the C stack at each GC. */ | 325 /* Buffer in which we save a copy of the C stack at each GC. */ |
| 326 | 326 |
| 327 char *stack_copy; | 327 static char *stack_copy; |
| 328 int stack_copy_size; | 328 static int stack_copy_size; |
| 329 | 329 |
| 330 /* Non-zero means ignore malloc warnings. Set during initialization. | 330 /* Non-zero means ignore malloc warnings. Set during initialization. |
| 331 Currently not used. */ | 331 Currently not used. */ |
| 332 | 332 |
| 333 int ignore_warnings; | 333 static int ignore_warnings; |
| 334 | 334 |
| 335 Lisp_Object Qgc_cons_threshold, Qchar_table_extra_slots; | 335 Lisp_Object Qgc_cons_threshold, Qchar_table_extra_slots; |
| 336 | 336 |
| 337 /* Hook run after GC has finished. */ | 337 /* Hook run after GC has finished. */ |
| 338 | 338 |
| 395 #endif | 395 #endif |
| 396 | 396 |
| 397 /* A unique object in pure space used to make some Lisp objects | 397 /* A unique object in pure space used to make some Lisp objects |
| 398 on free lists recognizable in O(1). */ | 398 on free lists recognizable in O(1). */ |
| 399 | 399 |
| 400 Lisp_Object Vdead; | 400 static Lisp_Object Vdead; |
| 401 | 401 |
| 402 #ifdef GC_MALLOC_CHECK | 402 #ifdef GC_MALLOC_CHECK |
| 403 | 403 |
| 404 enum mem_type allocated_mem_type; | 404 enum mem_type allocated_mem_type; |
| 405 int dont_register_blocks; | 405 static int dont_register_blocks; |
| 406 | 406 |
| 407 #endif /* GC_MALLOC_CHECK */ | 407 #endif /* GC_MALLOC_CHECK */ |
| 408 | 408 |
| 409 /* A node in the red-black tree describing allocated memory containing | 409 /* A node in the red-black tree describing allocated memory containing |
| 410 Lisp data. Each such block is recorded with its start and end | 410 Lisp data. Each such block is recorded with its start and end |
| 501 | 501 |
| 502 /* Addresses of staticpro'd variables. Initialize it to a nonzero | 502 /* Addresses of staticpro'd variables. Initialize it to a nonzero |
| 503 value; otherwise some compilers put it into BSS. */ | 503 value; otherwise some compilers put it into BSS. */ |
| 504 | 504 |
| 505 #define NSTATICS 1280 | 505 #define NSTATICS 1280 |
| 506 Lisp_Object *staticvec[NSTATICS] = {&Vpurify_flag}; | 506 static Lisp_Object *staticvec[NSTATICS] = {&Vpurify_flag}; |
| 507 | 507 |
| 508 /* Index of next unused slot in staticvec. */ | 508 /* Index of next unused slot in staticvec. */ |
| 509 | 509 |
| 510 int staticidx = 0; | 510 static int staticidx = 0; |
| 511 | 511 |
| 512 static POINTER_TYPE *pure_alloc P_ ((size_t, int)); | 512 static POINTER_TYPE *pure_alloc P_ ((size_t, int)); |
| 513 | 513 |
| 514 | 514 |
| 515 /* Value is SZ rounded up to the next multiple of ALIGNMENT. | 515 /* Value is SZ rounded up to the next multiple of ALIGNMENT. |
| 1415 }; | 1415 }; |
| 1416 | 1416 |
| 1417 /* Current interval block. Its `next' pointer points to older | 1417 /* Current interval block. Its `next' pointer points to older |
| 1418 blocks. */ | 1418 blocks. */ |
| 1419 | 1419 |
| 1420 struct interval_block *interval_block; | 1420 static struct interval_block *interval_block; |
| 1421 | 1421 |
| 1422 /* Index in interval_block above of the next unused interval | 1422 /* Index in interval_block above of the next unused interval |
| 1423 structure. */ | 1423 structure. */ |
| 1424 | 1424 |
| 1425 static int interval_block_index; | 1425 static int interval_block_index; |
| 1432 | 1432 |
| 1433 INTERVAL interval_free_list; | 1433 INTERVAL interval_free_list; |
| 1434 | 1434 |
| 1435 /* Total number of interval blocks now in use. */ | 1435 /* Total number of interval blocks now in use. */ |
| 1436 | 1436 |
| 1437 int n_interval_blocks; | 1437 static int n_interval_blocks; |
| 1438 | 1438 |
| 1439 | 1439 |
| 1440 /* Initialize interval allocation. */ | 1440 /* Initialize interval allocation. */ |
| 1441 | 1441 |
| 1442 static void | 1442 static void |
| 1754 | 1754 |
| 1755 #define GC_STRING_EXTRA (GC_STRING_OVERRUN_COOKIE_SIZE) | 1755 #define GC_STRING_EXTRA (GC_STRING_OVERRUN_COOKIE_SIZE) |
| 1756 | 1756 |
| 1757 /* Initialize string allocation. Called from init_alloc_once. */ | 1757 /* Initialize string allocation. Called from init_alloc_once. */ |
| 1758 | 1758 |
| 1759 void | 1759 static void |
| 1760 init_strings () | 1760 init_strings () |
| 1761 { | 1761 { |
| 1762 total_strings = total_free_strings = total_string_size = 0; | 1762 total_strings = total_free_strings = total_string_size = 0; |
| 1763 oldest_sblock = current_sblock = large_sblocks = NULL; | 1763 oldest_sblock = current_sblock = large_sblocks = NULL; |
| 1764 string_blocks = NULL; | 1764 string_blocks = NULL; |
| 1771 | 1771 |
| 1772 #ifdef GC_CHECK_STRING_BYTES | 1772 #ifdef GC_CHECK_STRING_BYTES |
| 1773 | 1773 |
| 1774 static int check_string_bytes_count; | 1774 static int check_string_bytes_count; |
| 1775 | 1775 |
| 1776 void check_string_bytes P_ ((int)); | 1776 static void check_string_bytes P_ ((int)); |
| 1777 void check_sblock P_ ((struct sblock *)); | 1777 static void check_sblock P_ ((struct sblock *)); |
| 1778 | 1778 |
| 1779 #define CHECK_STRING_BYTES(S) STRING_BYTES (S) | 1779 #define CHECK_STRING_BYTES(S) STRING_BYTES (S) |
| 1780 | 1780 |
| 1781 | 1781 |
| 1782 /* Like GC_STRING_BYTES, but with debugging check. */ | 1782 /* Like GC_STRING_BYTES, but with debugging check. */ |
| 1793 return nbytes; | 1793 return nbytes; |
| 1794 } | 1794 } |
| 1795 | 1795 |
| 1796 /* Check validity of Lisp strings' string_bytes member in B. */ | 1796 /* Check validity of Lisp strings' string_bytes member in B. */ |
| 1797 | 1797 |
| 1798 void | 1798 static void |
| 1799 check_sblock (b) | 1799 check_sblock (b) |
| 1800 struct sblock *b; | 1800 struct sblock *b; |
| 1801 { | 1801 { |
| 1802 struct sdata *from, *end, *from_end; | 1802 struct sdata *from, *end, *from_end; |
| 1803 | 1803 |
| 1827 | 1827 |
| 1828 /* Check validity of Lisp strings' string_bytes member. ALL_P | 1828 /* Check validity of Lisp strings' string_bytes member. ALL_P |
| 1829 non-zero means check all strings, otherwise check only most | 1829 non-zero means check all strings, otherwise check only most |
| 1830 recently allocated strings. Used for hunting a bug. */ | 1830 recently allocated strings. Used for hunting a bug. */ |
| 1831 | 1831 |
| 1832 void | 1832 static void |
| 1833 check_string_bytes (all_p) | 1833 check_string_bytes (all_p) |
| 1834 int all_p; | 1834 int all_p; |
| 1835 { | 1835 { |
| 1836 if (all_p) | 1836 if (all_p) |
| 1837 { | 1837 { |
| 2580 struct Lisp_Float *float_free_list; | 2580 struct Lisp_Float *float_free_list; |
| 2581 | 2581 |
| 2582 | 2582 |
| 2583 /* Initialize float allocation. */ | 2583 /* Initialize float allocation. */ |
| 2584 | 2584 |
| 2585 void | 2585 static void |
| 2586 init_float () | 2586 init_float () |
| 2587 { | 2587 { |
| 2588 float_block = NULL; | 2588 float_block = NULL; |
| 2589 float_block_index = FLOAT_BLOCK_SIZE; /* Force alloc of new float_block. */ | 2589 float_block_index = FLOAT_BLOCK_SIZE; /* Force alloc of new float_block. */ |
| 2590 float_free_list = 0; | 2590 float_free_list = 0; |
| 2592 } | 2592 } |
| 2593 | 2593 |
| 2594 | 2594 |
| 2595 /* Explicitly free a float cell by putting it on the free-list. */ | 2595 /* Explicitly free a float cell by putting it on the free-list. */ |
| 2596 | 2596 |
| 2597 void | 2597 static void |
| 2598 free_float (ptr) | 2598 free_float (ptr) |
| 2599 struct Lisp_Float *ptr; | 2599 struct Lisp_Float *ptr; |
| 2600 { | 2600 { |
| 2601 ptr->u.chain = float_free_list; | 2601 ptr->u.chain = float_free_list; |
| 2602 float_free_list = ptr; | 2602 float_free_list = ptr; |
| 2699 | 2699 |
| 2700 struct Lisp_Cons *cons_free_list; | 2700 struct Lisp_Cons *cons_free_list; |
| 2701 | 2701 |
| 2702 /* Total number of cons blocks now in use. */ | 2702 /* Total number of cons blocks now in use. */ |
| 2703 | 2703 |
| 2704 int n_cons_blocks; | 2704 static int n_cons_blocks; |
| 2705 | 2705 |
| 2706 | 2706 |
| 2707 /* Initialize cons allocation. */ | 2707 /* Initialize cons allocation. */ |
| 2708 | 2708 |
| 2709 void | 2709 static void |
| 2710 init_cons () | 2710 init_cons () |
| 2711 { | 2711 { |
| 2712 cons_block = NULL; | 2712 cons_block = NULL; |
| 2713 cons_block_index = CONS_BLOCK_SIZE; /* Force alloc of new cons_block. */ | 2713 cons_block_index = CONS_BLOCK_SIZE; /* Force alloc of new cons_block. */ |
| 2714 cons_free_list = 0; | 2714 cons_free_list = 0; |
| 2901 Vector Allocation | 2901 Vector Allocation |
| 2902 ***********************************************************************/ | 2902 ***********************************************************************/ |
| 2903 | 2903 |
| 2904 /* Singly-linked list of all vectors. */ | 2904 /* Singly-linked list of all vectors. */ |
| 2905 | 2905 |
| 2906 struct Lisp_Vector *all_vectors; | 2906 static struct Lisp_Vector *all_vectors; |
| 2907 | 2907 |
| 2908 /* Total number of vector-like objects now in use. */ | 2908 /* Total number of vector-like objects now in use. */ |
| 2909 | 2909 |
| 2910 int n_vectors; | 2910 static int n_vectors; |
| 2911 | 2911 |
| 2912 | 2912 |
| 2913 /* Value is a pointer to a newly allocated Lisp_Vector structure | 2913 /* Value is a pointer to a newly allocated Lisp_Vector structure |
| 2914 with room for LEN Lisp_Objects. */ | 2914 with room for LEN Lisp_Objects. */ |
| 2915 | 2915 |
| 3200 }; | 3200 }; |
| 3201 | 3201 |
| 3202 /* Current symbol block and index of first unused Lisp_Symbol | 3202 /* Current symbol block and index of first unused Lisp_Symbol |
| 3203 structure in it. */ | 3203 structure in it. */ |
| 3204 | 3204 |
| 3205 struct symbol_block *symbol_block; | 3205 static struct symbol_block *symbol_block; |
| 3206 int symbol_block_index; | 3206 static int symbol_block_index; |
| 3207 | 3207 |
| 3208 /* List of free symbols. */ | 3208 /* List of free symbols. */ |
| 3209 | 3209 |
| 3210 struct Lisp_Symbol *symbol_free_list; | 3210 static struct Lisp_Symbol *symbol_free_list; |
| 3211 | 3211 |
| 3212 /* Total number of symbol blocks now in use. */ | 3212 /* Total number of symbol blocks now in use. */ |
| 3213 | 3213 |
| 3214 int n_symbol_blocks; | 3214 static int n_symbol_blocks; |
| 3215 | 3215 |
| 3216 | 3216 |
| 3217 /* Initialize symbol allocation. */ | 3217 /* Initialize symbol allocation. */ |
| 3218 | 3218 |
| 3219 void | 3219 static void |
| 3220 init_symbol () | 3220 init_symbol () |
| 3221 { | 3221 { |
| 3222 symbol_block = NULL; | 3222 symbol_block = NULL; |
| 3223 symbol_block_index = SYMBOL_BLOCK_SIZE; | 3223 symbol_block_index = SYMBOL_BLOCK_SIZE; |
| 3224 symbol_free_list = 0; | 3224 symbol_free_list = 0; |
| 3296 /* Place `markers' first, to preserve alignment. */ | 3296 /* Place `markers' first, to preserve alignment. */ |
| 3297 union Lisp_Misc markers[MARKER_BLOCK_SIZE]; | 3297 union Lisp_Misc markers[MARKER_BLOCK_SIZE]; |
| 3298 struct marker_block *next; | 3298 struct marker_block *next; |
| 3299 }; | 3299 }; |
| 3300 | 3300 |
| 3301 struct marker_block *marker_block; | 3301 static struct marker_block *marker_block; |
| 3302 int marker_block_index; | 3302 static int marker_block_index; |
| 3303 | 3303 |
| 3304 union Lisp_Misc *marker_free_list; | 3304 static union Lisp_Misc *marker_free_list; |
| 3305 | 3305 |
| 3306 /* Total number of marker blocks now in use. */ | 3306 /* Total number of marker blocks now in use. */ |
| 3307 | 3307 |
| 3308 int n_marker_blocks; | 3308 static int n_marker_blocks; |
| 3309 | 3309 |
| 3310 void | 3310 static void |
| 3311 init_marker () | 3311 init_marker () |
| 3312 { | 3312 { |
| 3313 marker_block = NULL; | 3313 marker_block = NULL; |
| 3314 marker_block_index = MARKER_BLOCK_SIZE; | 3314 marker_block_index = MARKER_BLOCK_SIZE; |
| 3315 marker_free_list = 0; | 3315 marker_free_list = 0; |
| 4602 | 4602 |
| 4603 #endif /* GC_MARK_STACK != 0 */ | 4603 #endif /* GC_MARK_STACK != 0 */ |
| 4604 | 4604 |
| 4605 | 4605 |
| 4606 /* Determine whether it is safe to access memory at address P. */ | 4606 /* Determine whether it is safe to access memory at address P. */ |
| 4607 int | 4607 static int |
| 4608 valid_pointer_p (p) | 4608 valid_pointer_p (p) |
| 4609 void *p; | 4609 void *p; |
| 4610 { | 4610 { |
| 4611 #ifdef WINDOWSNT | 4611 #ifdef WINDOWSNT |
| 4612 return w32_valid_pointer_p (p, 16); | 4612 return w32_valid_pointer_p (p, 16); |
| 4898 } | 4898 } |
| 4899 | 4899 |
| 4900 | 4900 |
| 4901 /* Value is a float object with value NUM allocated from pure space. */ | 4901 /* Value is a float object with value NUM allocated from pure space. */ |
| 4902 | 4902 |
| 4903 Lisp_Object | 4903 static Lisp_Object |
| 4904 make_pure_float (num) | 4904 make_pure_float (num) |
| 4905 double num; | 4905 double num; |
| 4906 { | 4906 { |
| 4907 register Lisp_Object new; | 4907 register Lisp_Object new; |
| 4908 struct Lisp_Float *p; | 4908 struct Lisp_Float *p; |
| 5423 /* Mark reference to a Lisp_Object. | 5423 /* Mark reference to a Lisp_Object. |
| 5424 If the object referred to has not been seen yet, recursively mark | 5424 If the object referred to has not been seen yet, recursively mark |
| 5425 all the references contained in it. */ | 5425 all the references contained in it. */ |
| 5426 | 5426 |
| 5427 #define LAST_MARKED_SIZE 500 | 5427 #define LAST_MARKED_SIZE 500 |
| 5428 Lisp_Object last_marked[LAST_MARKED_SIZE]; | 5428 static Lisp_Object last_marked[LAST_MARKED_SIZE]; |
| 5429 int last_marked_index; | 5429 int last_marked_index; |
| 5430 | 5430 |
| 5431 /* For debugging--call abort when we cdr down this many | 5431 /* For debugging--call abort when we cdr down this many |
| 5432 links of a list, in mark_object. In debugging, | 5432 links of a list, in mark_object. In debugging, |
| 5433 the call to abort will hit a breakpoint. | 5433 the call to abort will hit a breakpoint. |
| 5434 Normally this is zero and the check never goes off. */ | 5434 Normally this is zero and the check never goes off. */ |
| 5435 int mark_object_loop_halt; | 5435 static int mark_object_loop_halt; |
| 5436 | 5436 |
| 5437 /* Return non-zero if the object was not yet marked. */ | 5437 /* Return non-zero if the object was not yet marked. */ |
| 5438 static int | 5438 static int |
| 5439 mark_vectorlike (ptr) | 5439 mark_vectorlike (ptr) |
| 5440 struct Lisp_Vector *ptr; | 5440 struct Lisp_Vector *ptr; |
| 5445 if (VECTOR_MARKED_P (ptr)) | 5445 if (VECTOR_MARKED_P (ptr)) |
| 5446 return 0; /* Already marked */ | 5446 return 0; /* Already marked */ |
| 5447 VECTOR_MARK (ptr); /* Else mark it */ | 5447 VECTOR_MARK (ptr); /* Else mark it */ |
| 5448 if (size & PSEUDOVECTOR_FLAG) | 5448 if (size & PSEUDOVECTOR_FLAG) |
| 5449 size &= PSEUDOVECTOR_SIZE_MASK; | 5449 size &= PSEUDOVECTOR_SIZE_MASK; |
| 5450 | 5450 |
| 5451 /* Note that this size is not the memory-footprint size, but only | 5451 /* Note that this size is not the memory-footprint size, but only |
| 5452 the number of Lisp_Object fields that we should trace. | 5452 the number of Lisp_Object fields that we should trace. |
| 5453 The distinction is used e.g. by Lisp_Process which places extra | 5453 The distinction is used e.g. by Lisp_Process which places extra |
| 5454 non-Lisp_Object fields at the end of the structure. */ | 5454 non-Lisp_Object fields at the end of the structure. */ |
| 5455 for (i = 0; i < size; i++) /* and then mark its elements */ | 5455 for (i = 0; i < size; i++) /* and then mark its elements */ |
| 6293 | 6293 |
| 6294 return Flist (8, consed); | 6294 return Flist (8, consed); |
| 6295 } | 6295 } |
| 6296 | 6296 |
| 6297 int suppress_checking; | 6297 int suppress_checking; |
| 6298 | |
| 6298 void | 6299 void |
| 6299 die (msg, file, line) | 6300 die (msg, file, line) |
| 6300 const char *msg; | 6301 const char *msg; |
| 6301 const char *file; | 6302 const char *file; |
| 6302 int line; | 6303 int line; |
