Mercurial > emacs
comparison src/alloc.c @ 50468:16fdb9f87d89
(VALIDATE_LISP_STORAGE): Macro deleted. All calls deleted.
(lisp_malloc): Do the work here directly.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 06 Apr 2003 20:27:19 +0000 |
parents | a617ca0d5d85 |
children | a5a77c7717cb |
comparison
equal
deleted
inserted
replaced
50467:cb9a2b0620a3 | 50468:16fdb9f87d89 |
---|---|
81 #define __malloc_size_t size_t | 81 #define __malloc_size_t size_t |
82 extern __malloc_size_t _bytes_used; | 82 extern __malloc_size_t _bytes_used; |
83 extern __malloc_size_t __malloc_extra_blocks; | 83 extern __malloc_size_t __malloc_extra_blocks; |
84 | 84 |
85 #endif /* not DOUG_LEA_MALLOC */ | 85 #endif /* not DOUG_LEA_MALLOC */ |
86 | |
87 /* Macro to verify that storage intended for Lisp objects is not | |
88 out of range to fit in the space for a pointer. | |
89 ADDRESS is the start of the block, and SIZE | |
90 is the amount of space within which objects can start. */ | |
91 | |
92 #define VALIDATE_LISP_STORAGE(address, size) \ | |
93 do \ | |
94 { \ | |
95 Lisp_Object val; \ | |
96 XSETCONS (val, (char *) address + size); \ | |
97 if ((char *) XCONS (val) != (char *) address + size) \ | |
98 { \ | |
99 xfree (address); \ | |
100 memory_full (); \ | |
101 } \ | |
102 } while (0) | |
103 | 86 |
104 /* Value of _bytes_used, when spare_memory was freed. */ | 87 /* Value of _bytes_used, when spare_memory was freed. */ |
105 | 88 |
106 static __malloc_size_t bytes_used_when_full; | 89 static __malloc_size_t bytes_used_when_full; |
107 | 90 |
582 | 565 |
583 /* Like malloc but used for allocating Lisp data. NBYTES is the | 566 /* Like malloc but used for allocating Lisp data. NBYTES is the |
584 number of bytes to allocate, TYPE describes the intended use of the | 567 number of bytes to allocate, TYPE describes the intended use of the |
585 allcated memory block (for strings, for conses, ...). */ | 568 allcated memory block (for strings, for conses, ...). */ |
586 | 569 |
570 static void *lisp_malloc_loser; | |
571 | |
587 static POINTER_TYPE * | 572 static POINTER_TYPE * |
588 lisp_malloc (nbytes, type) | 573 lisp_malloc (nbytes, type) |
589 size_t nbytes; | 574 size_t nbytes; |
590 enum mem_type type; | 575 enum mem_type type; |
591 { | 576 { |
597 allocated_mem_type = type; | 582 allocated_mem_type = type; |
598 #endif | 583 #endif |
599 | 584 |
600 val = (void *) malloc (nbytes); | 585 val = (void *) malloc (nbytes); |
601 | 586 |
587 /* If the memory just allocated cannot be addressed thru a Lisp | |
588 object's pointer, and it needs to be, | |
589 that's equivalent to running out of memory. */ | |
590 if (val && type != MEM_TYPE_NON_LISP) | |
591 { | |
592 Lisp_Object tem; | |
593 XSETCONS (tem, (char *) val + nbytes - 1); | |
594 if ((char *) XCONS (tem) != (char *) val + nbytes - 1) | |
595 { | |
596 lisp_malloc_loser = val; | |
597 free (val); | |
598 val = 0; | |
599 } | |
600 } | |
601 | |
602 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK | 602 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK |
603 if (val && type != MEM_TYPE_NON_LISP) | 603 if (val && type != MEM_TYPE_NON_LISP) |
604 mem_insert (val, (char *) val + nbytes, type); | 604 mem_insert (val, (char *) val + nbytes, type); |
605 #endif | 605 #endif |
606 | 606 |
618 allocate_buffer () | 618 allocate_buffer () |
619 { | 619 { |
620 struct buffer *b | 620 struct buffer *b |
621 = (struct buffer *) lisp_malloc (sizeof (struct buffer), | 621 = (struct buffer *) lisp_malloc (sizeof (struct buffer), |
622 MEM_TYPE_BUFFER); | 622 MEM_TYPE_BUFFER); |
623 VALIDATE_LISP_STORAGE (b, sizeof *b); | |
624 return b; | 623 return b; |
625 } | 624 } |
626 | 625 |
627 | 626 |
628 /* Free BLOCK. This must be called to free memory allocated with a | 627 /* Free BLOCK. This must be called to free memory allocated with a |
930 register struct interval_block *newi; | 929 register struct interval_block *newi; |
931 | 930 |
932 newi = (struct interval_block *) lisp_malloc (sizeof *newi, | 931 newi = (struct interval_block *) lisp_malloc (sizeof *newi, |
933 MEM_TYPE_NON_LISP); | 932 MEM_TYPE_NON_LISP); |
934 | 933 |
935 VALIDATE_LISP_STORAGE (newi, sizeof *newi); | |
936 newi->next = interval_block; | 934 newi->next = interval_block; |
937 interval_block = newi; | 935 interval_block = newi; |
938 interval_block_index = 0; | 936 interval_block_index = 0; |
939 n_interval_blocks++; | 937 n_interval_blocks++; |
940 } | 938 } |
1313 { | 1311 { |
1314 struct string_block *b; | 1312 struct string_block *b; |
1315 int i; | 1313 int i; |
1316 | 1314 |
1317 b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING); | 1315 b = (struct string_block *) lisp_malloc (sizeof *b, MEM_TYPE_STRING); |
1318 VALIDATE_LISP_STORAGE (b, sizeof *b); | |
1319 bzero (b, sizeof *b); | 1316 bzero (b, sizeof *b); |
1320 b->next = string_blocks; | 1317 b->next = string_blocks; |
1321 string_blocks = b; | 1318 string_blocks = b; |
1322 ++n_string_blocks; | 1319 ++n_string_blocks; |
1323 | 1320 |
1981 { | 1978 { |
1982 register struct float_block *new; | 1979 register struct float_block *new; |
1983 | 1980 |
1984 new = (struct float_block *) lisp_malloc (sizeof *new, | 1981 new = (struct float_block *) lisp_malloc (sizeof *new, |
1985 MEM_TYPE_FLOAT); | 1982 MEM_TYPE_FLOAT); |
1986 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
1987 new->next = float_block; | 1983 new->next = float_block; |
1988 float_block = new; | 1984 float_block = new; |
1989 float_block_index = 0; | 1985 float_block_index = 0; |
1990 n_float_blocks++; | 1986 n_float_blocks++; |
1991 } | 1987 } |
2088 if (cons_block_index == CONS_BLOCK_SIZE) | 2084 if (cons_block_index == CONS_BLOCK_SIZE) |
2089 { | 2085 { |
2090 register struct cons_block *new; | 2086 register struct cons_block *new; |
2091 new = (struct cons_block *) lisp_malloc (sizeof *new, | 2087 new = (struct cons_block *) lisp_malloc (sizeof *new, |
2092 MEM_TYPE_CONS); | 2088 MEM_TYPE_CONS); |
2093 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
2094 new->next = cons_block; | 2089 new->next = cons_block; |
2095 cons_block = new; | 2090 cons_block = new; |
2096 cons_block_index = 0; | 2091 cons_block_index = 0; |
2097 n_cons_blocks++; | 2092 n_cons_blocks++; |
2098 } | 2093 } |
2248 #ifdef DOUG_LEA_MALLOC | 2243 #ifdef DOUG_LEA_MALLOC |
2249 /* Back to a reasonable maximum of mmap'ed areas. */ | 2244 /* Back to a reasonable maximum of mmap'ed areas. */ |
2250 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 2245 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
2251 #endif | 2246 #endif |
2252 | 2247 |
2253 VALIDATE_LISP_STORAGE (p, 0); | |
2254 consing_since_gc += nbytes; | 2248 consing_since_gc += nbytes; |
2255 vector_cells_consed += len; | 2249 vector_cells_consed += len; |
2256 | 2250 |
2257 p->next = all_vectors; | 2251 p->next = all_vectors; |
2258 all_vectors = p; | 2252 all_vectors = p; |
2546 if (symbol_block_index == SYMBOL_BLOCK_SIZE) | 2540 if (symbol_block_index == SYMBOL_BLOCK_SIZE) |
2547 { | 2541 { |
2548 struct symbol_block *new; | 2542 struct symbol_block *new; |
2549 new = (struct symbol_block *) lisp_malloc (sizeof *new, | 2543 new = (struct symbol_block *) lisp_malloc (sizeof *new, |
2550 MEM_TYPE_SYMBOL); | 2544 MEM_TYPE_SYMBOL); |
2551 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
2552 new->next = symbol_block; | 2545 new->next = symbol_block; |
2553 symbol_block = new; | 2546 symbol_block = new; |
2554 symbol_block_index = 0; | 2547 symbol_block_index = 0; |
2555 n_symbol_blocks++; | 2548 n_symbol_blocks++; |
2556 } | 2549 } |
2627 if (marker_block_index == MARKER_BLOCK_SIZE) | 2620 if (marker_block_index == MARKER_BLOCK_SIZE) |
2628 { | 2621 { |
2629 struct marker_block *new; | 2622 struct marker_block *new; |
2630 new = (struct marker_block *) lisp_malloc (sizeof *new, | 2623 new = (struct marker_block *) lisp_malloc (sizeof *new, |
2631 MEM_TYPE_MISC); | 2624 MEM_TYPE_MISC); |
2632 VALIDATE_LISP_STORAGE (new, sizeof *new); | |
2633 new->next = marker_block; | 2625 new->next = marker_block; |
2634 marker_block = new; | 2626 marker_block = new; |
2635 marker_block_index = 0; | 2627 marker_block_index = 0; |
2636 n_marker_blocks++; | 2628 n_marker_blocks++; |
2637 } | 2629 } |