X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/322b7dab59b98b5d8625d2cd29e48f1ce605f769..a8e7d6d783219972c08fd49a3a2afaf26eb139c2:/src/ralloc.c diff --git a/src/ralloc.c b/src/ralloc.c index 9c601a0ac2..4bb2f24043 100644 --- a/src/ralloc.c +++ b/src/ralloc.c @@ -1,5 +1,5 @@ /* Block-relocating memory allocator. - Copyright (C) 1993, 1995, 2000-2011 Free Software Foundation, Inc. + Copyright (C) 1993, 1995, 2000-2012 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -95,12 +95,10 @@ static int extra_bytes; /* Macros for rounding. Note that rounding to any value is possible by changing the definition of PAGE. */ #define PAGE (getpagesize ()) -#define ALIGNED(addr) (((unsigned long int) (addr) & (page_size - 1)) == 0) #define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \ & ~(page_size - 1)) -#define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1))) -#define MEM_ALIGN sizeof(double) +#define MEM_ALIGN sizeof (double) #define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ & ~(MEM_ALIGN - 1)) @@ -151,7 +149,6 @@ typedef struct heap } *heap_ptr; #define NIL_HEAP ((heap_ptr) 0) -#define HEAP_PTR_SIZE (sizeof (struct heap)) /* This is the first heap object. If we need additional heap objects, each one resides at the beginning of @@ -219,13 +216,13 @@ find_heap (POINTER address) If enough space is not presently available in our reserve, this means getting more page-aligned space from the system. If the returned space is not contiguous to the last heap, allocate a new heap, and append it + to the heap list. - obtain does not try to keep track of whether space is in use - or not in use. It just returns the address of SIZE bytes that - fall within a single heap. If you call obtain twice in a row - with the same arguments, you typically get the same value. - to the heap list. It's the caller's responsibility to keep - track of what space is in use. + obtain does not try to keep track of whether space is in use or not + in use. It just returns the address of SIZE bytes that fall within a + single heap. If you call obtain twice in a row with the same arguments, + you typically get the same value. It's the caller's responsibility to + keep track of what space is in use. Return the address of the space if all went well, or zero if we couldn't allocate the memory. */ @@ -366,15 +363,6 @@ relinquish (void) } } } - -/* Return the total size in use by relocating allocator, - above where malloc gets space. */ - -long -r_alloc_size_in_use (void) -{ - return (char *) break_value - (char *) virtual_break_value; -} /* The meat - allocating, freeing, and relocating blocs. */ @@ -389,7 +377,7 @@ find_bloc (POINTER *ptr) while (p != NIL_BLOC) { /* Consistency check. Don't return inconsistent blocs. - Don't abort here, as callers might be expecting this, but + Don't abort here, as callers might be expecting this, but callers that always expect a bloc to be returned should abort if one isn't to avoid a memory corruption bug that is difficult to track down. */ @@ -468,7 +456,7 @@ relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address) /* No need to ever call this if arena is frozen, bug somewhere! */ if (r_alloc_freeze_level) - abort(); + abort (); while (b) { @@ -592,7 +580,7 @@ resize_bloc (bloc_ptr bloc, SIZE size) /* No need to ever call this if arena is frozen, bug somewhere! */ if (r_alloc_freeze_level) - abort(); + abort (); if (bloc == NIL_BLOC || size == bloc->size) return 1; @@ -636,7 +624,8 @@ resize_bloc (bloc_ptr bloc, SIZE size) } else { - memmove (b->new_data, b->data, b->size); + if (b->new_data != b->data) + memmove (b->new_data, b->data, b->size); *b->variable = b->data = b->new_data; } } @@ -647,7 +636,8 @@ resize_bloc (bloc_ptr bloc, SIZE size) } else { - memmove (bloc->new_data, bloc->data, old_size); + if (bloc->new_data != bloc->data) + memmove (bloc->new_data, bloc->data, old_size); memset ((char *) bloc->new_data + old_size, 0, size - old_size); *bloc->variable = bloc->data = bloc->new_data; } @@ -663,7 +653,8 @@ resize_bloc (bloc_ptr bloc, SIZE size) } else { - memmove (b->new_data, b->data, b->size); + if (b->new_data != b->data) + memmove (b->new_data, b->data, b->size); *b->variable = b->data = b->new_data; } } @@ -745,7 +736,7 @@ free_bloc (bloc_ptr bloc) __morecore hook values - in particular, __default_morecore in the GNU malloc package. */ -POINTER +static POINTER r_alloc_sbrk (long int size) { register bloc_ptr b; @@ -816,7 +807,8 @@ r_alloc_sbrk (long int size) header. */ for (b = last_bloc; b != NIL_BLOC; b = b->prev) { - memmove (b->new_data, b->data, b->size); + if (b->new_data != b->data) + memmove (b->new_data, b->data, b->size); *b->variable = b->data = b->new_data; } @@ -862,7 +854,8 @@ r_alloc_sbrk (long int size) for (b = first_bloc; b != NIL_BLOC; b = b->next) { - memmove (b->new_data, b->data, b->size); + if (b->new_data != b->data) + memmove (b->new_data, b->data, b->size); *b->variable = b->data = b->new_data; } } @@ -1009,52 +1002,6 @@ r_re_alloc (POINTER *ptr, SIZE size) return *ptr; } -/* Disable relocations, after making room for at least SIZE bytes - of non-relocatable heap if possible. The relocatable blocs are - guaranteed to hold still until thawed, even if this means that - malloc must return a null pointer. */ - -void -r_alloc_freeze (long int size) -{ - if (! r_alloc_initialized) - r_alloc_init (); - - /* If already frozen, we can't make any more room, so don't try. */ - if (r_alloc_freeze_level > 0) - size = 0; - /* If we can't get the amount requested, half is better than nothing. */ - while (size > 0 && r_alloc_sbrk (size) == 0) - size /= 2; - ++r_alloc_freeze_level; - if (size > 0) - r_alloc_sbrk (-size); -} - -void -r_alloc_thaw (void) -{ - - if (! r_alloc_initialized) - r_alloc_init (); - - if (--r_alloc_freeze_level < 0) - abort (); - - /* This frees all unused blocs. It is not too inefficient, as the resize - and memcpy is done only once. Afterwards, all unreferenced blocs are - already shrunk to zero size. */ - if (!r_alloc_freeze_level) - { - bloc_ptr *b = &first_bloc; - while (*b) - if (!(*b)->variable) - free_bloc (*b); - else - b = &(*b)->next; - } -} - #if defined (emacs) && defined (DOUG_LEA_MALLOC) @@ -1079,7 +1026,7 @@ r_alloc_reinit (void) #include void -r_alloc_check () +r_alloc_check (void) { int found = 0; heap_ptr h, ph = 0; @@ -1180,7 +1127,7 @@ r_alloc_reset_variable (POINTER *old, POINTER *new) /* Find the bloc that corresponds to the data pointed to by pointer. find_bloc cannot be used, as it has internal consistency checks - which fail when the variable needs reseting. */ + which fail when the variable needs resetting. */ while (bloc != NIL_BLOC) { if (bloc->data == *new)