Mercurial > hg > xemacs-beta
comparison src/ralloc.c @ 424:11054d720c21 r21-2-20
Import from CVS: tag r21-2-20
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:26:11 +0200 |
parents | 697ef44129c6 |
children |
comparison
equal
deleted
inserted
replaced
423:28d9c139be4c | 424:11054d720c21 |
---|---|
96 | 96 |
97 | 97 |
98 /* Declarations for working with the malloc, ralloc, and system breaks. */ | 98 /* Declarations for working with the malloc, ralloc, and system breaks. */ |
99 | 99 |
100 /* Function to set the real break value. */ | 100 /* Function to set the real break value. */ |
101 static POINTER (*real_morecore) (long size); | 101 static POINTER (*real_morecore) (ptrdiff_t size); |
102 | 102 |
103 /* The break value, as seen by malloc (). */ | 103 /* The break value, as seen by malloc (). */ |
104 static POINTER virtual_break_value; | 104 static POINTER virtual_break_value; |
105 | 105 |
106 /* The break value, viewed by the relocatable blocs. */ | 106 /* The break value, viewed by the relocatable blocs. */ |
337 | 337 |
338 /* Note that SIZE bytes of space have been relinquished by the process. | 338 /* Note that SIZE bytes of space have been relinquished by the process. |
339 If SIZE is more than a page, return the space to the system. */ | 339 If SIZE is more than a page, return the space to the system. */ |
340 | 340 |
341 static void | 341 static void |
342 relinquish () | 342 relinquish (void) |
343 { | 343 { |
344 register heap_ptr h; | 344 register heap_ptr h; |
345 int excess = 0; | 345 int excess = 0; |
346 | 346 |
347 /* Add the amount of space beyond break_value | 347 /* Add the amount of space beyond break_value |
788 | 788 |
789 If we're out of memory, we should return zero, to imitate the other | 789 If we're out of memory, we should return zero, to imitate the other |
790 __morecore hook values - in particular, __default_morecore in the | 790 __morecore hook values - in particular, __default_morecore in the |
791 GNU malloc package. */ | 791 GNU malloc package. */ |
792 | 792 |
793 POINTER r_alloc_sbrk (long size); | 793 POINTER r_alloc_sbrk (ptrdiff_t size); |
794 POINTER | 794 POINTER |
795 r_alloc_sbrk (long size) | 795 r_alloc_sbrk (ptrdiff_t size) |
796 { | 796 { |
797 register bloc_ptr b; | 797 register bloc_ptr b; |
798 POINTER address; | 798 POINTER address; |
799 | 799 |
800 if (! r_alloc_initialized) | 800 if (! r_alloc_initialized) |
1080 r_alloc_sbrk (-size); | 1080 r_alloc_sbrk (-size); |
1081 } | 1081 } |
1082 | 1082 |
1083 void r_alloc_thaw (void); | 1083 void r_alloc_thaw (void); |
1084 void | 1084 void |
1085 r_alloc_thaw () | 1085 r_alloc_thaw (void) |
1086 { | 1086 { |
1087 | 1087 |
1088 if (! r_alloc_initialized) | 1088 if (! r_alloc_initialized) |
1089 init_ralloc (); | 1089 init_ralloc (); |
1090 | 1090 |
1107 | 1107 |
1108 | 1108 |
1109 /* The hook `malloc' uses for the function which gets more space | 1109 /* The hook `malloc' uses for the function which gets more space |
1110 from the system. */ | 1110 from the system. */ |
1111 #ifndef DOUG_LEA_MALLOC | 1111 #ifndef DOUG_LEA_MALLOC |
1112 extern POINTER (*__morecore) (long size); | 1112 extern POINTER (*__morecore) (ptrdiff_t size); |
1113 #endif | 1113 #endif |
1114 | 1114 |
1115 /* Initialize various things for memory allocation. */ | 1115 /* Initialize various things for memory allocation. */ |
1116 | |
1117 #define SET_FUN_PTR(fun_ptr, fun_val) \ | |
1118 (*((void **) (&fun_ptr)) = ((void *) (fun_val))) | |
1119 | 1116 |
1120 void | 1117 void |
1121 init_ralloc (void) | 1118 init_ralloc (void) |
1122 { | 1119 { |
1123 if (r_alloc_initialized) | 1120 if (r_alloc_initialized) |
1124 return; | 1121 return; |
1125 | 1122 |
1126 r_alloc_initialized = 1; | 1123 r_alloc_initialized = 1; |
1127 SET_FUN_PTR (real_morecore, __morecore); | 1124 real_morecore = (POINTER (*) (ptrdiff_t)) __morecore; |
1128 SET_FUN_PTR (__morecore, r_alloc_sbrk); | 1125 __morecore = |
1126 #ifdef __GNUC__ | |
1127 (__typeof__ (__morecore)) | |
1128 #endif | |
1129 r_alloc_sbrk; | |
1129 | 1130 |
1130 first_heap = last_heap = &heap_base; | 1131 first_heap = last_heap = &heap_base; |
1131 first_heap->next = first_heap->prev = NIL_HEAP; | 1132 first_heap->next = first_heap->prev = NIL_HEAP; |
1132 first_heap->start = first_heap->bloc_start | 1133 first_heap->start = first_heap->bloc_start |
1133 = virtual_break_value = break_value = (*real_morecore) (0); | 1134 = virtual_break_value = break_value = (*real_morecore) (0); |
1170 | 1171 |
1171 /* Reinitialize the morecore hook variables after restarting a dumped | 1172 /* Reinitialize the morecore hook variables after restarting a dumped |
1172 Emacs. This is needed when using Doug Lea's malloc from GNU libc. */ | 1173 Emacs. This is needed when using Doug Lea's malloc from GNU libc. */ |
1173 void r_alloc_reinit (void); | 1174 void r_alloc_reinit (void); |
1174 void | 1175 void |
1175 r_alloc_reinit () | 1176 r_alloc_reinit (void) |
1176 { | 1177 { |
1177 /* Only do this if the hook has been reset, so that we don't get an | 1178 /* Only do this if the hook has been reset, so that we don't get an |
1178 infinite loop, in case Emacs was linked statically. */ | 1179 infinite loop, in case Emacs was linked statically. */ |
1179 if ( ((void*) __morecore) != (void *) (r_alloc_sbrk)) | 1180 if ( (POINTER (*) (ptrdiff_t)) __morecore != r_alloc_sbrk) |
1180 { | 1181 { |
1181 SET_FUN_PTR (real_morecore, __morecore); | 1182 real_morecore = (POINTER (*) (ptrdiff_t)) __morecore; |
1182 SET_FUN_PTR (__morecore, r_alloc_sbrk); | 1183 __morecore = |
1184 #ifdef __GNUC__ | |
1185 (__typeof__ (__morecore)) | |
1186 #endif | |
1187 r_alloc_sbrk; | |
1183 } | 1188 } |
1184 } | 1189 } |
1185 #if 0 | 1190 #if 0 |
1186 #ifdef DEBUG | 1191 #ifdef DEBUG |
1187 | 1192 |
1188 void | 1193 void |
1189 r_alloc_check () | 1194 r_alloc_check (void) |
1190 { | 1195 { |
1191 int found = 0; | 1196 int found = 0; |
1192 heap_ptr h, ph = 0; | 1197 heap_ptr h, ph = 0; |
1193 bloc_ptr b, pb = 0; | 1198 bloc_ptr b, pb = 0; |
1194 | 1199 |