# HG changeset patch # User Jim Blandy # Date 721875248 0 # Node ID ac1be1d32868bed17be89051f5bfc494af9ba6c8 # Parent b476a97ad17e5837077f8444ce00f0da4a7c12ae * ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC. (free_bloc): This can now be simplified. * ralloc.c (r_alloc_sbrk): When we allocate new space for the malloc heap, zero it out even if we don't have any blocs in the free list. diff -r b476a97ad17e -r ac1be1d32868 src/ralloc.c --- a/src/ralloc.c Mon Nov 16 00:53:26 1992 +0000 +++ b/src/ralloc.c Mon Nov 16 00:54:08 1992 +0000 @@ -91,7 +91,8 @@ /* This is the size of a page. We round memory requests to this boundary. */ static int page_size; -/* Whenever we get memory from the system, get this many extra bytes. */ +/* Whenever we get memory from the system, get this many extra bytes. This + must be a multiple of page_size. */ static int extra_bytes; /* Macros for rounding. Note that rounding to any value is possible @@ -258,6 +259,8 @@ indicated by ADDRESS. Direction of relocation is determined by the position of ADDRESS relative to BLOC->data. + If BLOC is NIL_BLOC, nothing is done. + Note that ordering of blocs is not affected by this function. */ static void @@ -265,21 +268,23 @@ bloc_ptr bloc; POINTER address; { - register bloc_ptr b; - POINTER data_zone = bloc->data; - register SIZE data_zone_size = 0; - register SIZE offset = bloc->data - address; - POINTER new_data_zone = data_zone - offset; - - for (b = bloc; b != NIL_BLOC; b = b->next) + if (bloc != NIL_BLOC) { - data_zone_size += b->size; - b->data -= offset; - *b->variable = b->data; + register SIZE offset = address - bloc->data; + register SIZE data_size = 0; + register bloc_ptr b; + + for (b = bloc; b != NIL_BLOC; b = b->next) + { + data_size += b->size; + b->data += offset; + *b->variable = b->data; + } + + safe_bcopy (address - offset, address, data_size); } +} - safe_bcopy (data_zone, new_data_zone, data_zone_size); -} /* Free BLOC from the chain of blocs, relocating any blocs above it and returning BLOC->size bytes to the free area. */ @@ -301,15 +306,14 @@ { first_bloc = bloc->next; first_bloc->prev = NIL_BLOC; - relocate_some_blocs (bloc->next, bloc->data); } else { bloc->next->prev = bloc->prev; bloc->prev->next = bloc->next; - relocate_some_blocs (bloc->next, bloc->data); } + relocate_some_blocs (bloc->next, bloc->data); relinquish (bloc->size); free (bloc); } @@ -355,13 +359,11 @@ return 0; if (first_bloc) - { - relocate_some_blocs (first_bloc, first_bloc->data + get); + relocate_some_blocs (first_bloc, first_bloc->data + get); - /* Zero out the space we just allocated, to help catch bugs - quickly. */ - bzero (virtual_break_value, get); - } + /* Zero out the space we just allocated, to help catch bugs + quickly. */ + bzero (virtual_break_value, get); } /* Can we keep extra_bytes of gap while freeing at least extra_bytes? */ else if (size < 0 && already_available - size > 2 * extra_bytes)