diff options
| author | Paul Eggert | 2013-02-22 11:23:12 -0800 |
|---|---|---|
| committer | Paul Eggert | 2013-02-22 11:23:12 -0800 |
| commit | fcee50281201215b76621d91885c26cd9936b3f3 (patch) | |
| tree | 97c9443279758ea22e6d610bd3b320415a146c3c /src/ralloc.c | |
| parent | bba90ab24e80476efcad6b6a770fd5fda522a621 (diff) | |
| download | emacs-fcee50281201215b76621d91885c26cd9936b3f3.tar.gz emacs-fcee50281201215b76621d91885c26cd9936b3f3.zip | |
Assume C89 or better.
* ralloc.c (SIZE, POINTER, NIL):
* vm-limit.c (POINTER):
Remove, replacing all uses with C89 equivalents. These old
symbols were present only for porting to pre-C89 platforms.
Diffstat (limited to 'src/ralloc.c')
| -rw-r--r-- | src/ralloc.c | 188 |
1 files changed, 92 insertions, 96 deletions
diff --git a/src/ralloc.c b/src/ralloc.c index ec1ac40414c..13fd65cbb0c 100644 --- a/src/ralloc.c +++ b/src/ralloc.c | |||
| @@ -52,10 +52,6 @@ extern size_t __malloc_extra_blocks; | |||
| 52 | 52 | ||
| 53 | #include "getpagesize.h" | 53 | #include "getpagesize.h" |
| 54 | 54 | ||
| 55 | typedef size_t SIZE; | ||
| 56 | typedef void *POINTER; | ||
| 57 | #define NIL ((POINTER) 0) | ||
| 58 | |||
| 59 | /* A flag to indicate whether we have initialized ralloc yet. For | 55 | /* A flag to indicate whether we have initialized ralloc yet. For |
| 60 | Emacs's sake, please do not make this local to malloc_init; on some | 56 | Emacs's sake, please do not make this local to malloc_init; on some |
| 61 | machines, the dumping procedure makes all static variables | 57 | machines, the dumping procedure makes all static variables |
| @@ -72,14 +68,14 @@ static void r_alloc_init (void); | |||
| 72 | /* Declarations for working with the malloc, ralloc, and system breaks. */ | 68 | /* Declarations for working with the malloc, ralloc, and system breaks. */ |
| 73 | 69 | ||
| 74 | /* Function to set the real break value. */ | 70 | /* Function to set the real break value. */ |
| 75 | POINTER (*real_morecore) (ptrdiff_t); | 71 | void *(*real_morecore) (ptrdiff_t); |
| 76 | 72 | ||
| 77 | /* The break value, as seen by malloc. */ | 73 | /* The break value, as seen by malloc. */ |
| 78 | static POINTER virtual_break_value; | 74 | static void *virtual_break_value; |
| 79 | 75 | ||
| 80 | /* The address of the end of the last data in use by ralloc, | 76 | /* The address of the end of the last data in use by ralloc, |
| 81 | including relocatable blocs as well as malloc data. */ | 77 | including relocatable blocs as well as malloc data. */ |
| 82 | static POINTER break_value; | 78 | static void *break_value; |
| 83 | 79 | ||
| 84 | /* This is the size of a page. We round memory requests to this boundary. */ | 80 | /* This is the size of a page. We round memory requests to this boundary. */ |
| 85 | static int page_size; | 81 | static int page_size; |
| @@ -92,17 +88,17 @@ static int extra_bytes; | |||
| 92 | by changing the definition of PAGE. */ | 88 | by changing the definition of PAGE. */ |
| 93 | #define PAGE (getpagesize ()) | 89 | #define PAGE (getpagesize ()) |
| 94 | #define ROUNDUP(size) (((size_t) (size) + page_size - 1) \ | 90 | #define ROUNDUP(size) (((size_t) (size) + page_size - 1) \ |
| 95 | & ~((size_t)(page_size - 1))) | 91 | & ~((size_t) (page_size - 1))) |
| 96 | 92 | ||
| 97 | #define MEM_ALIGN sizeof (double) | 93 | #define MEM_ALIGN sizeof (double) |
| 98 | #define MEM_ROUNDUP(addr) (((size_t)(addr) + MEM_ALIGN - 1) \ | 94 | #define MEM_ROUNDUP(addr) (((size_t) (addr) + MEM_ALIGN - 1) \ |
| 99 | & ~(MEM_ALIGN - 1)) | 95 | & ~(MEM_ALIGN - 1)) |
| 100 | 96 | ||
| 101 | /* The hook `malloc' uses for the function which gets more space | 97 | /* The hook `malloc' uses for the function which gets more space |
| 102 | from the system. */ | 98 | from the system. */ |
| 103 | 99 | ||
| 104 | #ifndef SYSTEM_MALLOC | 100 | #ifndef SYSTEM_MALLOC |
| 105 | extern POINTER (*__morecore) (ptrdiff_t); | 101 | extern void *(*__morecore) (ptrdiff_t); |
| 106 | #endif | 102 | #endif |
| 107 | 103 | ||
| 108 | 104 | ||
| @@ -131,13 +127,13 @@ typedef struct heap | |||
| 131 | struct heap *next; | 127 | struct heap *next; |
| 132 | struct heap *prev; | 128 | struct heap *prev; |
| 133 | /* Start of memory range of this heap. */ | 129 | /* Start of memory range of this heap. */ |
| 134 | POINTER start; | 130 | void *start; |
| 135 | /* End of memory range of this heap. */ | 131 | /* End of memory range of this heap. */ |
| 136 | POINTER end; | 132 | void *end; |
| 137 | /* Start of relocatable data in this heap. */ | 133 | /* Start of relocatable data in this heap. */ |
| 138 | POINTER bloc_start; | 134 | void *bloc_start; |
| 139 | /* Start of unused space in this heap. */ | 135 | /* Start of unused space in this heap. */ |
| 140 | POINTER free; | 136 | void *free; |
| 141 | /* First bloc in this heap. */ | 137 | /* First bloc in this heap. */ |
| 142 | struct bp *first_bloc; | 138 | struct bp *first_bloc; |
| 143 | /* Last bloc in this heap. */ | 139 | /* Last bloc in this heap. */ |
| @@ -159,7 +155,7 @@ static heap_ptr first_heap, last_heap; | |||
| 159 | The data blocks abut each other; if b->next is non-nil, then | 155 | The data blocks abut each other; if b->next is non-nil, then |
| 160 | b->data + b->size == b->next->data. | 156 | b->data + b->size == b->next->data. |
| 161 | 157 | ||
| 162 | An element with variable==NIL denotes a freed block, which has not yet | 158 | An element with variable==NULL denotes a freed block, which has not yet |
| 163 | been collected. They may only appear while r_alloc_freeze_level > 0, | 159 | been collected. They may only appear while r_alloc_freeze_level > 0, |
| 164 | and will be freed when the arena is thawed. Currently, these blocs are | 160 | and will be freed when the arena is thawed. Currently, these blocs are |
| 165 | not reusable, while the arena is frozen. Very inefficient. */ | 161 | not reusable, while the arena is frozen. Very inefficient. */ |
| @@ -168,10 +164,10 @@ typedef struct bp | |||
| 168 | { | 164 | { |
| 169 | struct bp *next; | 165 | struct bp *next; |
| 170 | struct bp *prev; | 166 | struct bp *prev; |
| 171 | POINTER *variable; | 167 | void **variable; |
| 172 | POINTER data; | 168 | void *data; |
| 173 | SIZE size; | 169 | size_t size; |
| 174 | POINTER new_data; /* temporarily used for relocation */ | 170 | void *new_data; /* temporarily used for relocation */ |
| 175 | struct heap *heap; /* Heap this bloc is in. */ | 171 | struct heap *heap; /* Heap this bloc is in. */ |
| 176 | } *bloc_ptr; | 172 | } *bloc_ptr; |
| 177 | 173 | ||
| @@ -192,7 +188,7 @@ static int r_alloc_freeze_level; | |||
| 192 | /* Find the heap that ADDRESS falls within. */ | 188 | /* Find the heap that ADDRESS falls within. */ |
| 193 | 189 | ||
| 194 | static heap_ptr | 190 | static heap_ptr |
| 195 | find_heap (POINTER address) | 191 | find_heap (void *address) |
| 196 | { | 192 | { |
| 197 | heap_ptr heap; | 193 | heap_ptr heap; |
| 198 | 194 | ||
| @@ -223,11 +219,11 @@ find_heap (POINTER address) | |||
| 223 | Return the address of the space if all went well, or zero if we couldn't | 219 | Return the address of the space if all went well, or zero if we couldn't |
| 224 | allocate the memory. */ | 220 | allocate the memory. */ |
| 225 | 221 | ||
| 226 | static POINTER | 222 | static void * |
| 227 | obtain (POINTER address, SIZE size) | 223 | obtain (void *address, size_t size) |
| 228 | { | 224 | { |
| 229 | heap_ptr heap; | 225 | heap_ptr heap; |
| 230 | SIZE already_available; | 226 | size_t already_available; |
| 231 | 227 | ||
| 232 | /* Find the heap that ADDRESS falls within. */ | 228 | /* Find the heap that ADDRESS falls within. */ |
| 233 | for (heap = last_heap; heap; heap = heap->prev) | 229 | for (heap = last_heap; heap; heap = heap->prev) |
| @@ -253,19 +249,19 @@ obtain (POINTER address, SIZE size) | |||
| 253 | get more space. */ | 249 | get more space. */ |
| 254 | if (heap == NIL_HEAP) | 250 | if (heap == NIL_HEAP) |
| 255 | { | 251 | { |
| 256 | POINTER new = (*real_morecore)(0); | 252 | void *new = real_morecore (0); |
| 257 | SIZE get; | 253 | size_t get; |
| 258 | 254 | ||
| 259 | already_available = (char *)last_heap->end - (char *)address; | 255 | already_available = (char *) last_heap->end - (char *) address; |
| 260 | 256 | ||
| 261 | if (new != last_heap->end) | 257 | if (new != last_heap->end) |
| 262 | { | 258 | { |
| 263 | /* Someone else called sbrk. Make a new heap. */ | 259 | /* Someone else called sbrk. Make a new heap. */ |
| 264 | 260 | ||
| 265 | heap_ptr new_heap = (heap_ptr) MEM_ROUNDUP (new); | 261 | heap_ptr new_heap = (heap_ptr) MEM_ROUNDUP (new); |
| 266 | POINTER bloc_start = (POINTER) MEM_ROUNDUP ((POINTER)(new_heap + 1)); | 262 | void *bloc_start = (void *) MEM_ROUNDUP ((void *) (new_heap + 1)); |
| 267 | 263 | ||
| 268 | if ((*real_morecore) ((char *) bloc_start - (char *) new) != new) | 264 | if (real_morecore ((char *) bloc_start - (char *) new) != new) |
| 269 | return 0; | 265 | return 0; |
| 270 | 266 | ||
| 271 | new_heap->start = new; | 267 | new_heap->start = new; |
| @@ -287,10 +283,10 @@ obtain (POINTER address, SIZE size) | |||
| 287 | Get some extra, so we can come here less often. */ | 283 | Get some extra, so we can come here less often. */ |
| 288 | 284 | ||
| 289 | get = size + extra_bytes - already_available; | 285 | get = size + extra_bytes - already_available; |
| 290 | get = (char *) ROUNDUP ((char *)last_heap->end + get) | 286 | get = (char *) ROUNDUP ((char *) last_heap->end + get) |
| 291 | - (char *) last_heap->end; | 287 | - (char *) last_heap->end; |
| 292 | 288 | ||
| 293 | if ((*real_morecore) (get) != last_heap->end) | 289 | if (real_morecore (get) != last_heap->end) |
| 294 | return 0; | 290 | return 0; |
| 295 | 291 | ||
| 296 | last_heap->end = (char *) last_heap->end + get; | 292 | last_heap->end = (char *) last_heap->end + get; |
| @@ -319,13 +315,13 @@ relinquish (void) | |||
| 319 | ? h->bloc_start : break_value); | 315 | ? h->bloc_start : break_value); |
| 320 | } | 316 | } |
| 321 | 317 | ||
| 322 | if (excess > extra_bytes * 2 && (*real_morecore) (0) == last_heap->end) | 318 | if (excess > extra_bytes * 2 && real_morecore (0) == last_heap->end) |
| 323 | { | 319 | { |
| 324 | /* Keep extra_bytes worth of empty space. | 320 | /* Keep extra_bytes worth of empty space. |
| 325 | And don't free anything unless we can free at least extra_bytes. */ | 321 | And don't free anything unless we can free at least extra_bytes. */ |
| 326 | excess -= extra_bytes; | 322 | excess -= extra_bytes; |
| 327 | 323 | ||
| 328 | if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess) | 324 | if ((char *) last_heap->end - (char *) last_heap->bloc_start <= excess) |
| 329 | { | 325 | { |
| 330 | heap_ptr lh_prev; | 326 | heap_ptr lh_prev; |
| 331 | 327 | ||
| @@ -336,12 +332,12 @@ relinquish (void) | |||
| 336 | return; | 332 | return; |
| 337 | 333 | ||
| 338 | /* Return the last heap, with its header, to the system. */ | 334 | /* Return the last heap, with its header, to the system. */ |
| 339 | excess = (char *)last_heap->end - (char *)last_heap->start; | 335 | excess = (char *) last_heap->end - (char *) last_heap->start; |
| 340 | lh_prev = last_heap->prev; | 336 | lh_prev = last_heap->prev; |
| 341 | /* If the system doesn't want that much memory back, leave | 337 | /* If the system doesn't want that much memory back, leave |
| 342 | last_heap unaltered to reflect that. This can occur if | 338 | last_heap unaltered to reflect that. This can occur if |
| 343 | break_value is still within the original data segment. */ | 339 | break_value is still within the original data segment. */ |
| 344 | if ((*real_morecore) (- excess) != 0) | 340 | if (real_morecore (- excess) != 0) |
| 345 | { | 341 | { |
| 346 | last_heap = lh_prev; | 342 | last_heap = lh_prev; |
| 347 | last_heap->next = NIL_HEAP; | 343 | last_heap->next = NIL_HEAP; |
| @@ -349,13 +345,13 @@ relinquish (void) | |||
| 349 | } | 345 | } |
| 350 | else | 346 | else |
| 351 | { | 347 | { |
| 352 | excess = (char *) last_heap->end | 348 | excess = ((char *) last_heap->end |
| 353 | - (char *) ROUNDUP ((char *)last_heap->end - excess); | 349 | - (char *) ROUNDUP ((char *) last_heap->end - excess)); |
| 354 | /* If the system doesn't want that much memory back, leave | 350 | /* If the system doesn't want that much memory back, leave |
| 355 | the end of the last heap unchanged to reflect that. This | 351 | the end of the last heap unchanged to reflect that. This |
| 356 | can occur if break_value is still within the original | 352 | can occur if break_value is still within the original |
| 357 | data segment. */ | 353 | data segment. */ |
| 358 | if ((*real_morecore) (- excess) != 0) | 354 | if (real_morecore (- excess) != 0) |
| 359 | last_heap->end = (char *) last_heap->end - excess; | 355 | last_heap->end = (char *) last_heap->end - excess; |
| 360 | } | 356 | } |
| 361 | } | 357 | } |
| @@ -367,9 +363,9 @@ relinquish (void) | |||
| 367 | to that block. */ | 363 | to that block. */ |
| 368 | 364 | ||
| 369 | static bloc_ptr | 365 | static bloc_ptr |
| 370 | find_bloc (POINTER *ptr) | 366 | find_bloc (void **ptr) |
| 371 | { | 367 | { |
| 372 | register bloc_ptr p = first_bloc; | 368 | bloc_ptr p = first_bloc; |
| 373 | 369 | ||
| 374 | while (p != NIL_BLOC) | 370 | while (p != NIL_BLOC) |
| 375 | { | 371 | { |
| @@ -392,10 +388,10 @@ find_bloc (POINTER *ptr) | |||
| 392 | memory for the new block. */ | 388 | memory for the new block. */ |
| 393 | 389 | ||
| 394 | static bloc_ptr | 390 | static bloc_ptr |
| 395 | get_bloc (SIZE size) | 391 | get_bloc (size_t size) |
| 396 | { | 392 | { |
| 397 | register bloc_ptr new_bloc; | 393 | bloc_ptr new_bloc; |
| 398 | register heap_ptr heap; | 394 | heap_ptr heap; |
| 399 | 395 | ||
| 400 | if (! (new_bloc = malloc (BLOC_PTR_SIZE)) | 396 | if (! (new_bloc = malloc (BLOC_PTR_SIZE)) |
| 401 | || ! (new_bloc->data = obtain (break_value, size))) | 397 | || ! (new_bloc->data = obtain (break_value, size))) |
| @@ -409,7 +405,7 @@ get_bloc (SIZE size) | |||
| 409 | 405 | ||
| 410 | new_bloc->size = size; | 406 | new_bloc->size = size; |
| 411 | new_bloc->next = NIL_BLOC; | 407 | new_bloc->next = NIL_BLOC; |
| 412 | new_bloc->variable = (POINTER *) NIL; | 408 | new_bloc->variable = NULL; |
| 413 | new_bloc->new_data = 0; | 409 | new_bloc->new_data = 0; |
| 414 | 410 | ||
| 415 | /* Record in the heap that this space is in use. */ | 411 | /* Record in the heap that this space is in use. */ |
| @@ -447,9 +443,9 @@ get_bloc (SIZE size) | |||
| 447 | Do not touch the contents of blocs or break_value. */ | 443 | Do not touch the contents of blocs or break_value. */ |
| 448 | 444 | ||
| 449 | static int | 445 | static int |
| 450 | relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address) | 446 | relocate_blocs (bloc_ptr bloc, heap_ptr heap, void *address) |
| 451 | { | 447 | { |
| 452 | register bloc_ptr b = bloc; | 448 | bloc_ptr b = bloc; |
| 453 | 449 | ||
| 454 | /* No need to ever call this if arena is frozen, bug somewhere! */ | 450 | /* No need to ever call this if arena is frozen, bug somewhere! */ |
| 455 | if (r_alloc_freeze_level) | 451 | if (r_alloc_freeze_level) |
| @@ -471,8 +467,8 @@ relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address) | |||
| 471 | get enough new space to hold BLOC and all following blocs. */ | 467 | get enough new space to hold BLOC and all following blocs. */ |
| 472 | if (heap == NIL_HEAP) | 468 | if (heap == NIL_HEAP) |
| 473 | { | 469 | { |
| 474 | register bloc_ptr tb = b; | 470 | bloc_ptr tb = b; |
| 475 | register SIZE s = 0; | 471 | size_t s = 0; |
| 476 | 472 | ||
| 477 | /* Add up the size of all the following blocs. */ | 473 | /* Add up the size of all the following blocs. */ |
| 478 | while (tb != NIL_BLOC) | 474 | while (tb != NIL_BLOC) |
| @@ -568,12 +564,12 @@ update_heap_bloc_correspondence (bloc_ptr bloc, heap_ptr heap) | |||
| 568 | that come after BLOC in memory. */ | 564 | that come after BLOC in memory. */ |
| 569 | 565 | ||
| 570 | static int | 566 | static int |
| 571 | resize_bloc (bloc_ptr bloc, SIZE size) | 567 | resize_bloc (bloc_ptr bloc, size_t size) |
| 572 | { | 568 | { |
| 573 | register bloc_ptr b; | 569 | bloc_ptr b; |
| 574 | heap_ptr heap; | 570 | heap_ptr heap; |
| 575 | POINTER address; | 571 | void *address; |
| 576 | SIZE old_size; | 572 | size_t old_size; |
| 577 | 573 | ||
| 578 | /* No need to ever call this if arena is frozen, bug somewhere! */ | 574 | /* No need to ever call this if arena is frozen, bug somewhere! */ |
| 579 | if (r_alloc_freeze_level) | 575 | if (r_alloc_freeze_level) |
| @@ -675,7 +671,7 @@ free_bloc (bloc_ptr bloc) | |||
| 675 | 671 | ||
| 676 | if (r_alloc_freeze_level) | 672 | if (r_alloc_freeze_level) |
| 677 | { | 673 | { |
| 678 | bloc->variable = (POINTER *) NIL; | 674 | bloc->variable = NULL; |
| 679 | return; | 675 | return; |
| 680 | } | 676 | } |
| 681 | 677 | ||
| @@ -752,17 +748,17 @@ free_bloc (bloc_ptr bloc) | |||
| 752 | __morecore hook values - in particular, __default_morecore in the | 748 | __morecore hook values - in particular, __default_morecore in the |
| 753 | GNU malloc package. */ | 749 | GNU malloc package. */ |
| 754 | 750 | ||
| 755 | static POINTER | 751 | static void * |
| 756 | r_alloc_sbrk (ptrdiff_t size) | 752 | r_alloc_sbrk (ptrdiff_t size) |
| 757 | { | 753 | { |
| 758 | register bloc_ptr b; | 754 | bloc_ptr b; |
| 759 | POINTER address; | 755 | void *address; |
| 760 | 756 | ||
| 761 | if (! r_alloc_initialized) | 757 | if (! r_alloc_initialized) |
| 762 | r_alloc_init (); | 758 | r_alloc_init (); |
| 763 | 759 | ||
| 764 | if (use_relocatable_buffers <= 0) | 760 | if (use_relocatable_buffers <= 0) |
| 765 | return (*real_morecore) (size); | 761 | return real_morecore (size); |
| 766 | 762 | ||
| 767 | if (size == 0) | 763 | if (size == 0) |
| 768 | return virtual_break_value; | 764 | return virtual_break_value; |
| @@ -772,19 +768,19 @@ r_alloc_sbrk (ptrdiff_t size) | |||
| 772 | /* Allocate a page-aligned space. GNU malloc would reclaim an | 768 | /* Allocate a page-aligned space. GNU malloc would reclaim an |
| 773 | extra space if we passed an unaligned one. But we could | 769 | extra space if we passed an unaligned one. But we could |
| 774 | not always find a space which is contiguous to the previous. */ | 770 | not always find a space which is contiguous to the previous. */ |
| 775 | POINTER new_bloc_start; | 771 | void *new_bloc_start; |
| 776 | heap_ptr h = first_heap; | 772 | heap_ptr h = first_heap; |
| 777 | SIZE get = ROUNDUP (size); | 773 | size_t get = ROUNDUP (size); |
| 778 | 774 | ||
| 779 | address = (POINTER) ROUNDUP (virtual_break_value); | 775 | address = (void *) ROUNDUP (virtual_break_value); |
| 780 | 776 | ||
| 781 | /* Search the list upward for a heap which is large enough. */ | 777 | /* Search the list upward for a heap which is large enough. */ |
| 782 | while ((char *) h->end < (char *) MEM_ROUNDUP ((char *)address + get)) | 778 | while ((char *) h->end < (char *) MEM_ROUNDUP ((char *) address + get)) |
| 783 | { | 779 | { |
| 784 | h = h->next; | 780 | h = h->next; |
| 785 | if (h == NIL_HEAP) | 781 | if (h == NIL_HEAP) |
| 786 | break; | 782 | break; |
| 787 | address = (POINTER) ROUNDUP (h->start); | 783 | address = (void *) ROUNDUP (h->start); |
| 788 | } | 784 | } |
| 789 | 785 | ||
| 790 | /* If not found, obtain more space. */ | 786 | /* If not found, obtain more space. */ |
| @@ -796,19 +792,19 @@ r_alloc_sbrk (ptrdiff_t size) | |||
| 796 | return 0; | 792 | return 0; |
| 797 | 793 | ||
| 798 | if (first_heap == last_heap) | 794 | if (first_heap == last_heap) |
| 799 | address = (POINTER) ROUNDUP (virtual_break_value); | 795 | address = (void *) ROUNDUP (virtual_break_value); |
| 800 | else | 796 | else |
| 801 | address = (POINTER) ROUNDUP (last_heap->start); | 797 | address = (void *) ROUNDUP (last_heap->start); |
| 802 | h = last_heap; | 798 | h = last_heap; |
| 803 | } | 799 | } |
| 804 | 800 | ||
| 805 | new_bloc_start = (POINTER) MEM_ROUNDUP ((char *)address + get); | 801 | new_bloc_start = (void *) MEM_ROUNDUP ((char *) address + get); |
| 806 | 802 | ||
| 807 | if (first_heap->bloc_start < new_bloc_start) | 803 | if (first_heap->bloc_start < new_bloc_start) |
| 808 | { | 804 | { |
| 809 | /* This is no clean solution - no idea how to do it better. */ | 805 | /* This is no clean solution - no idea how to do it better. */ |
| 810 | if (r_alloc_freeze_level) | 806 | if (r_alloc_freeze_level) |
| 811 | return NIL; | 807 | return NULL; |
| 812 | 808 | ||
| 813 | /* There is a bug here: if the above obtain call succeeded, but the | 809 | /* There is a bug here: if the above obtain call succeeded, but the |
| 814 | relocate_blocs call below does not succeed, we need to free | 810 | relocate_blocs call below does not succeed, we need to free |
| @@ -818,7 +814,7 @@ r_alloc_sbrk (ptrdiff_t size) | |||
| 818 | if (! relocate_blocs (first_bloc, h, new_bloc_start)) | 814 | if (! relocate_blocs (first_bloc, h, new_bloc_start)) |
| 819 | return 0; | 815 | return 0; |
| 820 | 816 | ||
| 821 | /* Note that (POINTER)(h+1) <= new_bloc_start since | 817 | /* Note that (char *) (h + 1) <= (char *) new_bloc_start since |
| 822 | get >= page_size, so the following does not destroy the heap | 818 | get >= page_size, so the following does not destroy the heap |
| 823 | header. */ | 819 | header. */ |
| 824 | for (b = last_bloc; b != NIL_BLOC; b = b->prev) | 820 | for (b = last_bloc; b != NIL_BLOC; b = b->prev) |
| @@ -855,8 +851,8 @@ r_alloc_sbrk (ptrdiff_t size) | |||
| 855 | } | 851 | } |
| 856 | else /* size < 0 */ | 852 | else /* size < 0 */ |
| 857 | { | 853 | { |
| 858 | SIZE excess = (char *)first_heap->bloc_start | 854 | size_t excess = ((char *) first_heap->bloc_start |
| 859 | - ((char *)virtual_break_value + size); | 855 | - ((char *) virtual_break_value + size)); |
| 860 | 856 | ||
| 861 | address = virtual_break_value; | 857 | address = virtual_break_value; |
| 862 | 858 | ||
| @@ -864,7 +860,7 @@ r_alloc_sbrk (ptrdiff_t size) | |||
| 864 | { | 860 | { |
| 865 | excess -= extra_bytes; | 861 | excess -= extra_bytes; |
| 866 | first_heap->bloc_start | 862 | first_heap->bloc_start |
| 867 | = (POINTER) MEM_ROUNDUP ((char *)first_heap->bloc_start - excess); | 863 | = (void *) MEM_ROUNDUP ((char *) first_heap->bloc_start - excess); |
| 868 | 864 | ||
| 869 | relocate_blocs (first_bloc, first_heap, first_heap->bloc_start); | 865 | relocate_blocs (first_bloc, first_heap, first_heap->bloc_start); |
| 870 | 866 | ||
| @@ -876,14 +872,14 @@ r_alloc_sbrk (ptrdiff_t size) | |||
| 876 | } | 872 | } |
| 877 | } | 873 | } |
| 878 | 874 | ||
| 879 | if ((char *)virtual_break_value + size < (char *)first_heap->start) | 875 | if ((char *) virtual_break_value + size < (char *) first_heap->start) |
| 880 | { | 876 | { |
| 881 | /* We found an additional space below the first heap */ | 877 | /* We found an additional space below the first heap */ |
| 882 | first_heap->start = (POINTER) ((char *)virtual_break_value + size); | 878 | first_heap->start = (void *) ((char *) virtual_break_value + size); |
| 883 | } | 879 | } |
| 884 | } | 880 | } |
| 885 | 881 | ||
| 886 | virtual_break_value = (POINTER) ((char *)address + size); | 882 | virtual_break_value = (void *) ((char *) address + size); |
| 887 | break_value = (last_bloc | 883 | break_value = (last_bloc |
| 888 | ? (char *) last_bloc->data + last_bloc->size | 884 | ? (char *) last_bloc->data + last_bloc->size |
| 889 | : (char *) first_heap->bloc_start); | 885 | : (char *) first_heap->bloc_start); |
| @@ -905,10 +901,10 @@ r_alloc_sbrk (ptrdiff_t size) | |||
| 905 | If we can't allocate the necessary memory, set *PTR to zero, and | 901 | If we can't allocate the necessary memory, set *PTR to zero, and |
| 906 | return zero. */ | 902 | return zero. */ |
| 907 | 903 | ||
| 908 | POINTER | 904 | void * |
| 909 | r_alloc (POINTER *ptr, SIZE size) | 905 | r_alloc (void **ptr, size_t size) |
| 910 | { | 906 | { |
| 911 | register bloc_ptr new_bloc; | 907 | bloc_ptr new_bloc; |
| 912 | 908 | ||
| 913 | if (! r_alloc_initialized) | 909 | if (! r_alloc_initialized) |
| 914 | r_alloc_init (); | 910 | r_alloc_init (); |
| @@ -929,9 +925,9 @@ r_alloc (POINTER *ptr, SIZE size) | |||
| 929 | Store 0 in *PTR to show there's no block allocated. */ | 925 | Store 0 in *PTR to show there's no block allocated. */ |
| 930 | 926 | ||
| 931 | void | 927 | void |
| 932 | r_alloc_free (register POINTER *ptr) | 928 | r_alloc_free (void **ptr) |
| 933 | { | 929 | { |
| 934 | register bloc_ptr dead_bloc; | 930 | bloc_ptr dead_bloc; |
| 935 | 931 | ||
| 936 | if (! r_alloc_initialized) | 932 | if (! r_alloc_initialized) |
| 937 | r_alloc_init (); | 933 | r_alloc_init (); |
| @@ -962,10 +958,10 @@ r_alloc_free (register POINTER *ptr) | |||
| 962 | If more memory cannot be allocated, then leave *PTR unchanged, and | 958 | If more memory cannot be allocated, then leave *PTR unchanged, and |
| 963 | return zero. */ | 959 | return zero. */ |
| 964 | 960 | ||
| 965 | POINTER | 961 | void * |
| 966 | r_re_alloc (POINTER *ptr, SIZE size) | 962 | r_re_alloc (void **ptr, size_t size) |
| 967 | { | 963 | { |
| 968 | register bloc_ptr bloc; | 964 | bloc_ptr bloc; |
| 969 | 965 | ||
| 970 | if (! r_alloc_initialized) | 966 | if (! r_alloc_initialized) |
| 971 | r_alloc_init (); | 967 | r_alloc_init (); |
| @@ -1004,15 +1000,15 @@ r_re_alloc (POINTER *ptr, SIZE size) | |||
| 1004 | { | 1000 | { |
| 1005 | new_bloc->variable = ptr; | 1001 | new_bloc->variable = ptr; |
| 1006 | *ptr = new_bloc->data; | 1002 | *ptr = new_bloc->data; |
| 1007 | bloc->variable = (POINTER *) NIL; | 1003 | bloc->variable = NULL; |
| 1008 | } | 1004 | } |
| 1009 | else | 1005 | else |
| 1010 | return NIL; | 1006 | return NULL; |
| 1011 | } | 1007 | } |
| 1012 | else | 1008 | else |
| 1013 | { | 1009 | { |
| 1014 | if (! resize_bloc (bloc, MEM_ROUNDUP (size))) | 1010 | if (! resize_bloc (bloc, MEM_ROUNDUP (size))) |
| 1015 | return NIL; | 1011 | return NULL; |
| 1016 | } | 1012 | } |
| 1017 | } | 1013 | } |
| 1018 | return *ptr; | 1014 | return *ptr; |
| @@ -1052,27 +1048,27 @@ r_alloc_check (void) | |||
| 1052 | return; | 1048 | return; |
| 1053 | 1049 | ||
| 1054 | assert (first_heap); | 1050 | assert (first_heap); |
| 1055 | assert (last_heap->end <= (POINTER) sbrk (0)); | 1051 | assert (last_heap->end <= (void *) sbrk (0)); |
| 1056 | assert ((POINTER) first_heap < first_heap->start); | 1052 | assert ((void *) first_heap < first_heap->start); |
| 1057 | assert (first_heap->start <= virtual_break_value); | 1053 | assert (first_heap->start <= virtual_break_value); |
| 1058 | assert (virtual_break_value <= first_heap->end); | 1054 | assert (virtual_break_value <= first_heap->end); |
| 1059 | 1055 | ||
| 1060 | for (h = first_heap; h; h = h->next) | 1056 | for (h = first_heap; h; h = h->next) |
| 1061 | { | 1057 | { |
| 1062 | assert (h->prev == ph); | 1058 | assert (h->prev == ph); |
| 1063 | assert ((POINTER) ROUNDUP (h->end) == h->end); | 1059 | assert ((void *) ROUNDUP (h->end) == h->end); |
| 1064 | #if 0 /* ??? The code in ralloc.c does not really try to ensure | 1060 | #if 0 /* ??? The code in ralloc.c does not really try to ensure |
| 1065 | the heap start has any sort of alignment. | 1061 | the heap start has any sort of alignment. |
| 1066 | Perhaps it should. */ | 1062 | Perhaps it should. */ |
| 1067 | assert ((POINTER) MEM_ROUNDUP (h->start) == h->start); | 1063 | assert ((void *) MEM_ROUNDUP (h->start) == h->start); |
| 1068 | #endif | 1064 | #endif |
| 1069 | assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start); | 1065 | assert ((void *) MEM_ROUNDUP (h->bloc_start) == h->bloc_start); |
| 1070 | assert (h->start <= h->bloc_start && h->bloc_start <= h->end); | 1066 | assert (h->start <= h->bloc_start && h->bloc_start <= h->end); |
| 1071 | 1067 | ||
| 1072 | if (ph) | 1068 | if (ph) |
| 1073 | { | 1069 | { |
| 1074 | assert (ph->end < h->start); | 1070 | assert (ph->end < h->start); |
| 1075 | assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start); | 1071 | assert (h->start <= (void *) h && (void *) (h + 1) <= h->bloc_start); |
| 1076 | } | 1072 | } |
| 1077 | 1073 | ||
| 1078 | if (h->bloc_start <= break_value && break_value <= h->end) | 1074 | if (h->bloc_start <= break_value && break_value <= h->end) |
| @@ -1087,8 +1083,8 @@ r_alloc_check (void) | |||
| 1087 | for (b = first_bloc; b; b = b->next) | 1083 | for (b = first_bloc; b; b = b->next) |
| 1088 | { | 1084 | { |
| 1089 | assert (b->prev == pb); | 1085 | assert (b->prev == pb); |
| 1090 | assert ((POINTER) MEM_ROUNDUP (b->data) == b->data); | 1086 | assert ((void *) MEM_ROUNDUP (b->data) == b->data); |
| 1091 | assert ((SIZE) MEM_ROUNDUP (b->size) == b->size); | 1087 | assert ((size_t) MEM_ROUNDUP (b->size) == b->size); |
| 1092 | 1088 | ||
| 1093 | ph = 0; | 1089 | ph = 0; |
| 1094 | for (h = first_heap; h; h = h->next) | 1090 | for (h = first_heap; h; h = h->next) |
| @@ -1137,7 +1133,7 @@ r_alloc_check (void) | |||
| 1137 | is checked to ensure that memory corruption does not occur due to | 1133 | is checked to ensure that memory corruption does not occur due to |
| 1138 | misuse. */ | 1134 | misuse. */ |
| 1139 | void | 1135 | void |
| 1140 | r_alloc_reset_variable (POINTER *old, POINTER *new) | 1136 | r_alloc_reset_variable (void **old, void **new) |
| 1141 | { | 1137 | { |
| 1142 | bloc_ptr bloc = first_bloc; | 1138 | bloc_ptr bloc = first_bloc; |
| 1143 | 1139 | ||
| @@ -1192,8 +1188,8 @@ r_alloc_init (void) | |||
| 1192 | first_heap = last_heap = &heap_base; | 1188 | first_heap = last_heap = &heap_base; |
| 1193 | first_heap->next = first_heap->prev = NIL_HEAP; | 1189 | first_heap->next = first_heap->prev = NIL_HEAP; |
| 1194 | first_heap->start = first_heap->bloc_start | 1190 | first_heap->start = first_heap->bloc_start |
| 1195 | = virtual_break_value = break_value = (*real_morecore) (0); | 1191 | = virtual_break_value = break_value = real_morecore (0); |
| 1196 | if (break_value == NIL) | 1192 | if (break_value == NULL) |
| 1197 | emacs_abort (); | 1193 | emacs_abort (); |
| 1198 | 1194 | ||
| 1199 | extra_bytes = ROUNDUP (50000); | 1195 | extra_bytes = ROUNDUP (50000); |
| @@ -1218,7 +1214,7 @@ r_alloc_init (void) | |||
| 1218 | #endif | 1214 | #endif |
| 1219 | 1215 | ||
| 1220 | #ifndef SYSTEM_MALLOC | 1216 | #ifndef SYSTEM_MALLOC |
| 1221 | first_heap->end = (POINTER) ROUNDUP (first_heap->start); | 1217 | first_heap->end = (void *) ROUNDUP (first_heap->start); |
| 1222 | 1218 | ||
| 1223 | /* The extra call to real_morecore guarantees that the end of the | 1219 | /* The extra call to real_morecore guarantees that the end of the |
| 1224 | address space is a multiple of page_size, even if page_size is | 1220 | address space is a multiple of page_size, even if page_size is |
| @@ -1226,7 +1222,7 @@ r_alloc_init (void) | |||
| 1226 | which page_size is stored. This allows a binary to be built on a | 1222 | which page_size is stored. This allows a binary to be built on a |
| 1227 | system with one page size and run on a system with a smaller page | 1223 | system with one page size and run on a system with a smaller page |
| 1228 | size. */ | 1224 | size. */ |
| 1229 | (*real_morecore) ((char *) first_heap->end - (char *) first_heap->start); | 1225 | real_morecore ((char *) first_heap->end - (char *) first_heap->start); |
| 1230 | 1226 | ||
| 1231 | /* Clear the rest of the last page; this memory is in our address space | 1227 | /* Clear the rest of the last page; this memory is in our address space |
| 1232 | even though it is after the sbrk value. */ | 1228 | even though it is after the sbrk value. */ |