diff options
| author | Jim Blandy | 1992-11-16 00:54:08 +0000 |
|---|---|---|
| committer | Jim Blandy | 1992-11-16 00:54:08 +0000 |
| commit | ad3bb3d26038b562fb539a4c9217cdc26c0b42f8 (patch) | |
| tree | 08daf0467623e1d7eeb58f9c620e985828095f86 /src/ralloc.c | |
| parent | b0310da46a84635eb11693f59fe456c40cb8dc39 (diff) | |
| download | emacs-ad3bb3d26038b562fb539a4c9217cdc26c0b42f8.tar.gz emacs-ad3bb3d26038b562fb539a4c9217cdc26c0b42f8.zip | |
* 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.
Diffstat (limited to 'src/ralloc.c')
| -rw-r--r-- | src/ralloc.c | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/ralloc.c b/src/ralloc.c index 4a76ebfb4ac..de6060cfd4f 100644 --- a/src/ralloc.c +++ b/src/ralloc.c | |||
| @@ -91,7 +91,8 @@ static POINTER page_break_value; | |||
| 91 | /* This is the size of a page. We round memory requests to this boundary. */ | 91 | /* This is the size of a page. We round memory requests to this boundary. */ |
| 92 | static int page_size; | 92 | static int page_size; |
| 93 | 93 | ||
| 94 | /* Whenever we get memory from the system, get this many extra bytes. */ | 94 | /* Whenever we get memory from the system, get this many extra bytes. This |
| 95 | must be a multiple of page_size. */ | ||
| 95 | static int extra_bytes; | 96 | static int extra_bytes; |
| 96 | 97 | ||
| 97 | /* Macros for rounding. Note that rounding to any value is possible | 98 | /* Macros for rounding. Note that rounding to any value is possible |
| @@ -258,6 +259,8 @@ get_bloc (size) | |||
| 258 | indicated by ADDRESS. Direction of relocation is determined by | 259 | indicated by ADDRESS. Direction of relocation is determined by |
| 259 | the position of ADDRESS relative to BLOC->data. | 260 | the position of ADDRESS relative to BLOC->data. |
| 260 | 261 | ||
| 262 | If BLOC is NIL_BLOC, nothing is done. | ||
| 263 | |||
| 261 | Note that ordering of blocs is not affected by this function. */ | 264 | Note that ordering of blocs is not affected by this function. */ |
| 262 | 265 | ||
| 263 | static void | 266 | static void |
| @@ -265,22 +268,24 @@ relocate_some_blocs (bloc, address) | |||
| 265 | bloc_ptr bloc; | 268 | bloc_ptr bloc; |
| 266 | POINTER address; | 269 | POINTER address; |
| 267 | { | 270 | { |
| 268 | register bloc_ptr b; | 271 | if (bloc != NIL_BLOC) |
| 269 | POINTER data_zone = bloc->data; | ||
| 270 | register SIZE data_zone_size = 0; | ||
| 271 | register SIZE offset = bloc->data - address; | ||
| 272 | POINTER new_data_zone = data_zone - offset; | ||
| 273 | |||
| 274 | for (b = bloc; b != NIL_BLOC; b = b->next) | ||
| 275 | { | 272 | { |
| 276 | data_zone_size += b->size; | 273 | register SIZE offset = address - bloc->data; |
| 277 | b->data -= offset; | 274 | register SIZE data_size = 0; |
| 278 | *b->variable = b->data; | 275 | register bloc_ptr b; |
| 279 | } | 276 | |
| 277 | for (b = bloc; b != NIL_BLOC; b = b->next) | ||
| 278 | { | ||
| 279 | data_size += b->size; | ||
| 280 | b->data += offset; | ||
| 281 | *b->variable = b->data; | ||
| 282 | } | ||
| 280 | 283 | ||
| 281 | safe_bcopy (data_zone, new_data_zone, data_zone_size); | 284 | safe_bcopy (address - offset, address, data_size); |
| 285 | } | ||
| 282 | } | 286 | } |
| 283 | 287 | ||
| 288 | |||
| 284 | /* Free BLOC from the chain of blocs, relocating any blocs above it | 289 | /* Free BLOC from the chain of blocs, relocating any blocs above it |
| 285 | and returning BLOC->size bytes to the free area. */ | 290 | and returning BLOC->size bytes to the free area. */ |
| 286 | 291 | ||
| @@ -301,15 +306,14 @@ free_bloc (bloc) | |||
| 301 | { | 306 | { |
| 302 | first_bloc = bloc->next; | 307 | first_bloc = bloc->next; |
| 303 | first_bloc->prev = NIL_BLOC; | 308 | first_bloc->prev = NIL_BLOC; |
| 304 | relocate_some_blocs (bloc->next, bloc->data); | ||
| 305 | } | 309 | } |
| 306 | else | 310 | else |
| 307 | { | 311 | { |
| 308 | bloc->next->prev = bloc->prev; | 312 | bloc->next->prev = bloc->prev; |
| 309 | bloc->prev->next = bloc->next; | 313 | bloc->prev->next = bloc->next; |
| 310 | relocate_some_blocs (bloc->next, bloc->data); | ||
| 311 | } | 314 | } |
| 312 | 315 | ||
| 316 | relocate_some_blocs (bloc->next, bloc->data); | ||
| 313 | relinquish (bloc->size); | 317 | relinquish (bloc->size); |
| 314 | free (bloc); | 318 | free (bloc); |
| 315 | } | 319 | } |
| @@ -355,13 +359,11 @@ r_alloc_sbrk (size) | |||
| 355 | return 0; | 359 | return 0; |
| 356 | 360 | ||
| 357 | if (first_bloc) | 361 | if (first_bloc) |
| 358 | { | 362 | relocate_some_blocs (first_bloc, first_bloc->data + get); |
| 359 | relocate_some_blocs (first_bloc, first_bloc->data + get); | ||
| 360 | 363 | ||
| 361 | /* Zero out the space we just allocated, to help catch bugs | 364 | /* Zero out the space we just allocated, to help catch bugs |
| 362 | quickly. */ | 365 | quickly. */ |
| 363 | bzero (virtual_break_value, get); | 366 | bzero (virtual_break_value, get); |
| 364 | } | ||
| 365 | } | 367 | } |
| 366 | /* Can we keep extra_bytes of gap while freeing at least extra_bytes? */ | 368 | /* Can we keep extra_bytes of gap while freeing at least extra_bytes? */ |
| 367 | else if (size < 0 && already_available - size > 2 * extra_bytes) | 369 | else if (size < 0 && already_available - size > 2 * extra_bytes) |