Mercurial > emacs
comparison src/alloc.c @ 52256:36e112575ca8
(lisp_align_malloc): Check for memory full when
allocating ablocks, which also avoids freeing a pointer into an
ablocks structure.
| author | Gerd Moellmann <gerd@gnu.org> |
|---|---|
| date | Tue, 19 Aug 2003 12:58:06 +0000 |
| parents | 25f780eb3fd8 |
| children | 5623f26dff58 |
comparison
equal
deleted
inserted
replaced
| 52255:eb8d63124c39 | 52256:36e112575ca8 |
|---|---|
| 764 #ifdef DOUG_LEA_MALLOC | 764 #ifdef DOUG_LEA_MALLOC |
| 765 /* Back to a reasonable maximum of mmap'ed areas. */ | 765 /* Back to a reasonable maximum of mmap'ed areas. */ |
| 766 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); | 766 mallopt (M_MMAP_MAX, MMAP_MAX_AREAS); |
| 767 #endif | 767 #endif |
| 768 | 768 |
| 769 /* If the memory just allocated cannot be addressed thru a Lisp | |
| 770 object's pointer, and it needs to be, that's equivalent to | |
| 771 running out of memory. */ | |
| 772 if (type != MEM_TYPE_NON_LISP) | |
| 773 { | |
| 774 Lisp_Object tem; | |
| 775 char *end = (char *) base + ABLOCKS_BYTES - 1; | |
| 776 XSETCONS (tem, end); | |
| 777 if ((char *) XCONS (tem) != end) | |
| 778 { | |
| 779 lisp_malloc_loser = base; | |
| 780 free (base); | |
| 781 UNBLOCK_INPUT; | |
| 782 memory_full (); | |
| 783 } | |
| 784 } | |
| 785 | |
| 769 /* Initialize the blocks and put them on the free list. | 786 /* Initialize the blocks and put them on the free list. |
| 770 Is `base' was not properly aligned, we can't use the last block. */ | 787 Is `base' was not properly aligned, we can't use the last block. */ |
| 771 for (i = 0; i < (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1); i++) | 788 for (i = 0; i < (aligned ? ABLOCKS_SIZE : ABLOCKS_SIZE - 1); i++) |
| 772 { | 789 { |
| 773 abase->blocks[i].abase = abase; | 790 abase->blocks[i].abase = abase; |
| 785 | 802 |
| 786 abase = ABLOCK_ABASE (free_ablock); | 803 abase = ABLOCK_ABASE (free_ablock); |
| 787 ABLOCKS_BUSY (abase) = (struct ablocks *) (2 + (int) ABLOCKS_BUSY (abase)); | 804 ABLOCKS_BUSY (abase) = (struct ablocks *) (2 + (int) ABLOCKS_BUSY (abase)); |
| 788 val = free_ablock; | 805 val = free_ablock; |
| 789 free_ablock = free_ablock->x.next_free; | 806 free_ablock = free_ablock->x.next_free; |
| 790 | |
| 791 /* If the memory just allocated cannot be addressed thru a Lisp | |
| 792 object's pointer, and it needs to be, | |
| 793 that's equivalent to running out of memory. */ | |
| 794 if (val && type != MEM_TYPE_NON_LISP) | |
| 795 { | |
| 796 Lisp_Object tem; | |
| 797 XSETCONS (tem, (char *) val + nbytes - 1); | |
| 798 if ((char *) XCONS (tem) != (char *) val + nbytes - 1) | |
| 799 { | |
| 800 lisp_malloc_loser = val; | |
| 801 free (val); | |
| 802 val = 0; | |
| 803 } | |
| 804 } | |
| 805 | 807 |
| 806 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK | 808 #if GC_MARK_STACK && !defined GC_MALLOC_CHECK |
| 807 if (val && type != MEM_TYPE_NON_LISP) | 809 if (val && type != MEM_TYPE_NON_LISP) |
| 808 mem_insert (val, (char *) val + nbytes, type); | 810 mem_insert (val, (char *) val + nbytes, type); |
| 809 #endif | 811 #endif |
