aboutsummaryrefslogtreecommitdiffstats
path: root/src/ralloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ralloc.c')
-rw-r--r--src/ralloc.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/ralloc.c b/src/ralloc.c
index 9c601a0ac24..896ad9f3155 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -1,5 +1,5 @@
1/* Block-relocating memory allocator. 1/* Block-relocating memory allocator.
2 Copyright (C) 1993, 1995, 2000-2011 Free Software Foundation, Inc. 2 Copyright (C) 1993, 1995, 2000-2012 Free Software Foundation, Inc.
3 3
4This file is part of GNU Emacs. 4This file is part of GNU Emacs.
5 5
@@ -100,7 +100,7 @@ static int extra_bytes;
100 & ~(page_size - 1)) 100 & ~(page_size - 1))
101#define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1))) 101#define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1)))
102 102
103#define MEM_ALIGN sizeof(double) 103#define MEM_ALIGN sizeof (double)
104#define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ 104#define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \
105 & ~(MEM_ALIGN - 1)) 105 & ~(MEM_ALIGN - 1))
106 106
@@ -219,13 +219,13 @@ find_heap (POINTER address)
219 If enough space is not presently available in our reserve, this means 219 If enough space is not presently available in our reserve, this means
220 getting more page-aligned space from the system. If the returned space 220 getting more page-aligned space from the system. If the returned space
221 is not contiguous to the last heap, allocate a new heap, and append it 221 is not contiguous to the last heap, allocate a new heap, and append it
222 to the heap list.
222 223
223 obtain does not try to keep track of whether space is in use 224 obtain does not try to keep track of whether space is in use or not
224 or not in use. It just returns the address of SIZE bytes that 225 in use. It just returns the address of SIZE bytes that fall within a
225 fall within a single heap. If you call obtain twice in a row 226 single heap. If you call obtain twice in a row with the same arguments,
226 with the same arguments, you typically get the same value. 227 you typically get the same value. It's the caller's responsibility to
227 to the heap list. It's the caller's responsibility to keep 228 keep track of what space is in use.
228 track of what space is in use.
229 229
230 Return the address of the space if all went well, or zero if we couldn't 230 Return the address of the space if all went well, or zero if we couldn't
231 allocate the memory. */ 231 allocate the memory. */
@@ -389,7 +389,7 @@ find_bloc (POINTER *ptr)
389 while (p != NIL_BLOC) 389 while (p != NIL_BLOC)
390 { 390 {
391 /* Consistency check. Don't return inconsistent blocs. 391 /* Consistency check. Don't return inconsistent blocs.
392 Don't abort here, as callers might be expecting this, but 392 Don't abort here, as callers might be expecting this, but
393 callers that always expect a bloc to be returned should abort 393 callers that always expect a bloc to be returned should abort
394 if one isn't to avoid a memory corruption bug that is 394 if one isn't to avoid a memory corruption bug that is
395 difficult to track down. */ 395 difficult to track down. */
@@ -468,7 +468,7 @@ relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address)
468 468
469 /* No need to ever call this if arena is frozen, bug somewhere! */ 469 /* No need to ever call this if arena is frozen, bug somewhere! */
470 if (r_alloc_freeze_level) 470 if (r_alloc_freeze_level)
471 abort(); 471 abort ();
472 472
473 while (b) 473 while (b)
474 { 474 {
@@ -592,7 +592,7 @@ resize_bloc (bloc_ptr bloc, SIZE size)
592 592
593 /* No need to ever call this if arena is frozen, bug somewhere! */ 593 /* No need to ever call this if arena is frozen, bug somewhere! */
594 if (r_alloc_freeze_level) 594 if (r_alloc_freeze_level)
595 abort(); 595 abort ();
596 596
597 if (bloc == NIL_BLOC || size == bloc->size) 597 if (bloc == NIL_BLOC || size == bloc->size)
598 return 1; 598 return 1;
@@ -636,7 +636,8 @@ resize_bloc (bloc_ptr bloc, SIZE size)
636 } 636 }
637 else 637 else
638 { 638 {
639 memmove (b->new_data, b->data, b->size); 639 if (b->new_data != b->data)
640 memmove (b->new_data, b->data, b->size);
640 *b->variable = b->data = b->new_data; 641 *b->variable = b->data = b->new_data;
641 } 642 }
642 } 643 }
@@ -647,7 +648,8 @@ resize_bloc (bloc_ptr bloc, SIZE size)
647 } 648 }
648 else 649 else
649 { 650 {
650 memmove (bloc->new_data, bloc->data, old_size); 651 if (bloc->new_data != bloc->data)
652 memmove (bloc->new_data, bloc->data, old_size);
651 memset ((char *) bloc->new_data + old_size, 0, size - old_size); 653 memset ((char *) bloc->new_data + old_size, 0, size - old_size);
652 *bloc->variable = bloc->data = bloc->new_data; 654 *bloc->variable = bloc->data = bloc->new_data;
653 } 655 }
@@ -663,7 +665,8 @@ resize_bloc (bloc_ptr bloc, SIZE size)
663 } 665 }
664 else 666 else
665 { 667 {
666 memmove (b->new_data, b->data, b->size); 668 if (b->new_data != b->data)
669 memmove (b->new_data, b->data, b->size);
667 *b->variable = b->data = b->new_data; 670 *b->variable = b->data = b->new_data;
668 } 671 }
669 } 672 }
@@ -816,7 +819,8 @@ r_alloc_sbrk (long int size)
816 header. */ 819 header. */
817 for (b = last_bloc; b != NIL_BLOC; b = b->prev) 820 for (b = last_bloc; b != NIL_BLOC; b = b->prev)
818 { 821 {
819 memmove (b->new_data, b->data, b->size); 822 if (b->new_data != b->data)
823 memmove (b->new_data, b->data, b->size);
820 *b->variable = b->data = b->new_data; 824 *b->variable = b->data = b->new_data;
821 } 825 }
822 826
@@ -862,7 +866,8 @@ r_alloc_sbrk (long int size)
862 866
863 for (b = first_bloc; b != NIL_BLOC; b = b->next) 867 for (b = first_bloc; b != NIL_BLOC; b = b->next)
864 { 868 {
865 memmove (b->new_data, b->data, b->size); 869 if (b->new_data != b->data)
870 memmove (b->new_data, b->data, b->size);
866 *b->variable = b->data = b->new_data; 871 *b->variable = b->data = b->new_data;
867 } 872 }
868 } 873 }
@@ -1079,7 +1084,7 @@ r_alloc_reinit (void)
1079#include <assert.h> 1084#include <assert.h>
1080 1085
1081void 1086void
1082r_alloc_check () 1087r_alloc_check (void)
1083{ 1088{
1084 int found = 0; 1089 int found = 0;
1085 heap_ptr h, ph = 0; 1090 heap_ptr h, ph = 0;
@@ -1180,7 +1185,7 @@ r_alloc_reset_variable (POINTER *old, POINTER *new)
1180 1185
1181 /* Find the bloc that corresponds to the data pointed to by pointer. 1186 /* Find the bloc that corresponds to the data pointed to by pointer.
1182 find_bloc cannot be used, as it has internal consistency checks 1187 find_bloc cannot be used, as it has internal consistency checks
1183 which fail when the variable needs reseting. */ 1188 which fail when the variable needs resetting. */
1184 while (bloc != NIL_BLOC) 1189 while (bloc != NIL_BLOC)
1185 { 1190 {
1186 if (bloc->data == *new) 1191 if (bloc->data == *new)