Mercurial > emacs
comparison src/ralloc.c @ 109126:aec1143e8d85
Convert (most) functions in src to standard C.
* src/alloc.c: Convert function definitions to standard C.
* src/atimer.c:
* src/bidi.c:
* src/bytecode.c:
* src/callint.c:
* src/callproc.c:
* src/casefiddle.c:
* src/casetab.c:
* src/category.c:
* src/ccl.c:
* src/character.c:
* src/charset.c:
* src/chartab.c:
* src/cmds.c:
* src/coding.c:
* src/composite.c:
* src/data.c:
* src/dbusbind.c:
* src/dired.c:
* src/dispnew.c:
* src/doc.c:
* src/doprnt.c:
* src/ecrt0.c:
* src/editfns.c:
* src/fileio.c:
* src/filelock.c:
* src/filemode.c:
* src/fns.c:
* src/font.c:
* src/fontset.c:
* src/frame.c:
* src/fringe.c:
* src/ftfont.c:
* src/ftxfont.c:
* src/gtkutil.c:
* src/indent.c:
* src/insdel.c:
* src/intervals.c:
* src/keymap.c:
* src/lread.c:
* src/macros.c:
* src/marker.c:
* src/md5.c:
* src/menu.c:
* src/minibuf.c:
* src/prefix-args.c:
* src/print.c:
* src/ralloc.c:
* src/regex.c:
* src/region-cache.c:
* src/scroll.c:
* src/search.c:
* src/sound.c:
* src/strftime.c:
* src/syntax.c:
* src/sysdep.c:
* src/termcap.c:
* src/terminal.c:
* src/terminfo.c:
* src/textprop.c:
* src/tparam.c:
* src/undo.c:
* src/unexelf.c:
* src/window.c:
* src/xfaces.c:
* src/xfns.c:
* src/xfont.c:
* src/xftfont.c:
* src/xgselect.c:
* src/xmenu.c:
* src/xrdb.c:
* src/xselect.c:
* src/xsettings.c:
* src/xsmfns.c:
* src/xterm.c: Likewise.
| author | Dan Nicolaescu <dann@ics.uci.edu> |
|---|---|
| date | Sun, 04 Jul 2010 00:50:25 -0700 |
| parents | 1d1d5d9bd884 |
| children | 750db9f3e6d8 |
comparison
equal
deleted
inserted
replaced
| 109125:12b02558bf51 | 109126:aec1143e8d85 |
|---|---|
| 38 typedef size_t SIZE; | 38 typedef size_t SIZE; |
| 39 | 39 |
| 40 /* Declared in dispnew.c, this version doesn't screw up if regions | 40 /* Declared in dispnew.c, this version doesn't screw up if regions |
| 41 overlap. */ | 41 overlap. */ |
| 42 | 42 |
| 43 extern void safe_bcopy (); | 43 extern void safe_bcopy (const char *, char *, int); |
| 44 | 44 |
| 45 #ifdef DOUG_LEA_MALLOC | 45 #ifdef DOUG_LEA_MALLOC |
| 46 #define M_TOP_PAD -2 | 46 #define M_TOP_PAD -2 |
| 47 extern int mallopt (); | 47 extern int mallopt (int, int); |
| 48 #else /* not DOUG_LEA_MALLOC */ | 48 #else /* not DOUG_LEA_MALLOC */ |
| 49 #ifndef SYSTEM_MALLOC | 49 #ifndef SYSTEM_MALLOC |
| 50 extern size_t __malloc_extra_blocks; | 50 extern size_t __malloc_extra_blocks; |
| 51 #endif /* SYSTEM_MALLOC */ | 51 #endif /* SYSTEM_MALLOC */ |
| 52 #endif /* not DOUG_LEA_MALLOC */ | 52 #endif /* not DOUG_LEA_MALLOC */ |
| 79 automatic variable, and loses its value each time Emacs is started | 79 automatic variable, and loses its value each time Emacs is started |
| 80 up. */ | 80 up. */ |
| 81 | 81 |
| 82 static int r_alloc_initialized = 0; | 82 static int r_alloc_initialized = 0; |
| 83 | 83 |
| 84 static void r_alloc_init (); | 84 static void r_alloc_init (void); |
| 85 | 85 |
| 86 | 86 |
| 87 /* Declarations for working with the malloc, ralloc, and system breaks. */ | 87 /* Declarations for working with the malloc, ralloc, and system breaks. */ |
| 88 | 88 |
| 89 /* Function to set the real break value. */ | 89 /* Function to set the real break value. */ |
| 208 /* Functions to get and return memory from the system. */ | 208 /* Functions to get and return memory from the system. */ |
| 209 | 209 |
| 210 /* Find the heap that ADDRESS falls within. */ | 210 /* Find the heap that ADDRESS falls within. */ |
| 211 | 211 |
| 212 static heap_ptr | 212 static heap_ptr |
| 213 find_heap (address) | 213 find_heap (POINTER address) |
| 214 POINTER address; | |
| 215 { | 214 { |
| 216 heap_ptr heap; | 215 heap_ptr heap; |
| 217 | 216 |
| 218 for (heap = last_heap; heap; heap = heap->prev) | 217 for (heap = last_heap; heap; heap = heap->prev) |
| 219 { | 218 { |
| 241 | 240 |
| 242 Return the address of the space if all went well, or zero if we couldn't | 241 Return the address of the space if all went well, or zero if we couldn't |
| 243 allocate the memory. */ | 242 allocate the memory. */ |
| 244 | 243 |
| 245 static POINTER | 244 static POINTER |
| 246 obtain (address, size) | 245 obtain (POINTER address, SIZE size) |
| 247 POINTER address; | |
| 248 SIZE size; | |
| 249 { | 246 { |
| 250 heap_ptr heap; | 247 heap_ptr heap; |
| 251 SIZE already_available; | 248 SIZE already_available; |
| 252 | 249 |
| 253 /* Find the heap that ADDRESS falls within. */ | 250 /* Find the heap that ADDRESS falls within. */ |
| 324 if there is a lot of unused space now. | 321 if there is a lot of unused space now. |
| 325 This can make the last heap smaller; | 322 This can make the last heap smaller; |
| 326 it can also eliminate the last heap entirely. */ | 323 it can also eliminate the last heap entirely. */ |
| 327 | 324 |
| 328 static void | 325 static void |
| 329 relinquish () | 326 relinquish (void) |
| 330 { | 327 { |
| 331 register heap_ptr h; | 328 register heap_ptr h; |
| 332 long excess = 0; | 329 long excess = 0; |
| 333 | 330 |
| 334 /* Add the amount of space beyond break_value | 331 /* Add the amount of space beyond break_value |
| 383 | 380 |
| 384 /* Return the total size in use by relocating allocator, | 381 /* Return the total size in use by relocating allocator, |
| 385 above where malloc gets space. */ | 382 above where malloc gets space. */ |
| 386 | 383 |
| 387 long | 384 long |
| 388 r_alloc_size_in_use () | 385 r_alloc_size_in_use (void) |
| 389 { | 386 { |
| 390 return (char *) break_value - (char *) virtual_break_value; | 387 return (char *) break_value - (char *) virtual_break_value; |
| 391 } | 388 } |
| 392 | 389 |
| 393 /* The meat - allocating, freeing, and relocating blocs. */ | 390 /* The meat - allocating, freeing, and relocating blocs. */ |
| 394 | 391 |
| 395 /* Find the bloc referenced by the address in PTR. Returns a pointer | 392 /* Find the bloc referenced by the address in PTR. Returns a pointer |
| 396 to that block. */ | 393 to that block. */ |
| 397 | 394 |
| 398 static bloc_ptr | 395 static bloc_ptr |
| 399 find_bloc (ptr) | 396 find_bloc (POINTER *ptr) |
| 400 POINTER *ptr; | |
| 401 { | 397 { |
| 402 register bloc_ptr p = first_bloc; | 398 register bloc_ptr p = first_bloc; |
| 403 | 399 |
| 404 while (p != NIL_BLOC) | 400 while (p != NIL_BLOC) |
| 405 { | 401 { |
| 420 /* Allocate a bloc of SIZE bytes and append it to the chain of blocs. | 416 /* Allocate a bloc of SIZE bytes and append it to the chain of blocs. |
| 421 Returns a pointer to the new bloc, or zero if we couldn't allocate | 417 Returns a pointer to the new bloc, or zero if we couldn't allocate |
| 422 memory for the new block. */ | 418 memory for the new block. */ |
| 423 | 419 |
| 424 static bloc_ptr | 420 static bloc_ptr |
| 425 get_bloc (size) | 421 get_bloc (SIZE size) |
| 426 SIZE size; | |
| 427 { | 422 { |
| 428 register bloc_ptr new_bloc; | 423 register bloc_ptr new_bloc; |
| 429 register heap_ptr heap; | 424 register heap_ptr heap; |
| 430 | 425 |
| 431 if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE)) | 426 if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE)) |
| 476 | 471 |
| 477 Store the new location of each bloc in its new_data field. | 472 Store the new location of each bloc in its new_data field. |
| 478 Do not touch the contents of blocs or break_value. */ | 473 Do not touch the contents of blocs or break_value. */ |
| 479 | 474 |
| 480 static int | 475 static int |
| 481 relocate_blocs (bloc, heap, address) | 476 relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address) |
| 482 bloc_ptr bloc; | |
| 483 heap_ptr heap; | |
| 484 POINTER address; | |
| 485 { | 477 { |
| 486 register bloc_ptr b = bloc; | 478 register bloc_ptr b = bloc; |
| 487 | 479 |
| 488 /* No need to ever call this if arena is frozen, bug somewhere! */ | 480 /* No need to ever call this if arena is frozen, bug somewhere! */ |
| 489 if (r_alloc_freeze_level) | 481 if (r_alloc_freeze_level) |
| 539 /* Reorder the bloc BLOC to go before bloc BEFORE in the doubly linked list. | 531 /* Reorder the bloc BLOC to go before bloc BEFORE in the doubly linked list. |
| 540 This is necessary if we put the memory of space of BLOC | 532 This is necessary if we put the memory of space of BLOC |
| 541 before that of BEFORE. */ | 533 before that of BEFORE. */ |
| 542 | 534 |
| 543 static void | 535 static void |
| 544 reorder_bloc (bloc, before) | 536 reorder_bloc (bloc_ptr bloc, bloc_ptr before) |
| 545 bloc_ptr bloc, before; | |
| 546 { | 537 { |
| 547 bloc_ptr prev, next; | 538 bloc_ptr prev, next; |
| 548 | 539 |
| 549 /* Splice BLOC out from where it is. */ | 540 /* Splice BLOC out from where it is. */ |
| 550 prev = bloc->prev; | 541 prev = bloc->prev; |
| 568 | 559 |
| 569 /* Update the records of which heaps contain which blocs, starting | 560 /* Update the records of which heaps contain which blocs, starting |
| 570 with heap HEAP and bloc BLOC. */ | 561 with heap HEAP and bloc BLOC. */ |
| 571 | 562 |
| 572 static void | 563 static void |
| 573 update_heap_bloc_correspondence (bloc, heap) | 564 update_heap_bloc_correspondence (bloc_ptr bloc, heap_ptr heap) |
| 574 bloc_ptr bloc; | |
| 575 heap_ptr heap; | |
| 576 { | 565 { |
| 577 register bloc_ptr b; | 566 register bloc_ptr b; |
| 578 | 567 |
| 579 /* Initialize HEAP's status to reflect blocs before BLOC. */ | 568 /* Initialize HEAP's status to reflect blocs before BLOC. */ |
| 580 if (bloc != NIL_BLOC && bloc->prev != NIL_BLOC && bloc->prev->heap == heap) | 569 if (bloc != NIL_BLOC && bloc->prev != NIL_BLOC && bloc->prev->heap == heap) |
| 632 | 621 |
| 633 /* Resize BLOC to SIZE bytes. This relocates the blocs | 622 /* Resize BLOC to SIZE bytes. This relocates the blocs |
| 634 that come after BLOC in memory. */ | 623 that come after BLOC in memory. */ |
| 635 | 624 |
| 636 static int | 625 static int |
| 637 resize_bloc (bloc, size) | 626 resize_bloc (bloc_ptr bloc, SIZE size) |
| 638 bloc_ptr bloc; | |
| 639 SIZE size; | |
| 640 { | 627 { |
| 641 register bloc_ptr b; | 628 register bloc_ptr b; |
| 642 heap_ptr heap; | 629 heap_ptr heap; |
| 643 POINTER address; | 630 POINTER address; |
| 644 SIZE old_size; | 631 SIZE old_size; |
| 731 | 718 |
| 732 /* Free BLOC from the chain of blocs, relocating any blocs above it. | 719 /* Free BLOC from the chain of blocs, relocating any blocs above it. |
| 733 This may return space to the system. */ | 720 This may return space to the system. */ |
| 734 | 721 |
| 735 static void | 722 static void |
| 736 free_bloc (bloc) | 723 free_bloc (bloc_ptr bloc) |
| 737 bloc_ptr bloc; | |
| 738 { | 724 { |
| 739 heap_ptr heap = bloc->heap; | 725 heap_ptr heap = bloc->heap; |
| 740 | 726 |
| 741 if (r_alloc_freeze_level) | 727 if (r_alloc_freeze_level) |
| 742 { | 728 { |
| 798 If we're out of memory, we should return zero, to imitate the other | 784 If we're out of memory, we should return zero, to imitate the other |
| 799 __morecore hook values - in particular, __default_morecore in the | 785 __morecore hook values - in particular, __default_morecore in the |
| 800 GNU malloc package. */ | 786 GNU malloc package. */ |
| 801 | 787 |
| 802 POINTER | 788 POINTER |
| 803 r_alloc_sbrk (size) | 789 r_alloc_sbrk (long int size) |
| 804 long size; | |
| 805 { | 790 { |
| 806 register bloc_ptr b; | 791 register bloc_ptr b; |
| 807 POINTER address; | 792 POINTER address; |
| 808 | 793 |
| 809 if (! r_alloc_initialized) | 794 if (! r_alloc_initialized) |
| 950 | 935 |
| 951 If we can't allocate the necessary memory, set *PTR to zero, and | 936 If we can't allocate the necessary memory, set *PTR to zero, and |
| 952 return zero. */ | 937 return zero. */ |
| 953 | 938 |
| 954 POINTER | 939 POINTER |
| 955 r_alloc (ptr, size) | 940 r_alloc (POINTER *ptr, SIZE size) |
| 956 POINTER *ptr; | |
| 957 SIZE size; | |
| 958 { | 941 { |
| 959 register bloc_ptr new_bloc; | 942 register bloc_ptr new_bloc; |
| 960 | 943 |
| 961 if (! r_alloc_initialized) | 944 if (! r_alloc_initialized) |
| 962 r_alloc_init (); | 945 r_alloc_init (); |
| 975 | 958 |
| 976 /* Free a bloc of relocatable storage whose data is pointed to by PTR. | 959 /* Free a bloc of relocatable storage whose data is pointed to by PTR. |
| 977 Store 0 in *PTR to show there's no block allocated. */ | 960 Store 0 in *PTR to show there's no block allocated. */ |
| 978 | 961 |
| 979 void | 962 void |
| 980 r_alloc_free (ptr) | 963 r_alloc_free (register POINTER *ptr) |
| 981 register POINTER *ptr; | |
| 982 { | 964 { |
| 983 register bloc_ptr dead_bloc; | 965 register bloc_ptr dead_bloc; |
| 984 | 966 |
| 985 if (! r_alloc_initialized) | 967 if (! r_alloc_initialized) |
| 986 r_alloc_init (); | 968 r_alloc_init (); |
| 1010 | 992 |
| 1011 If more memory cannot be allocated, then leave *PTR unchanged, and | 993 If more memory cannot be allocated, then leave *PTR unchanged, and |
| 1012 return zero. */ | 994 return zero. */ |
| 1013 | 995 |
| 1014 POINTER | 996 POINTER |
| 1015 r_re_alloc (ptr, size) | 997 r_re_alloc (POINTER *ptr, SIZE size) |
| 1016 POINTER *ptr; | |
| 1017 SIZE size; | |
| 1018 { | 998 { |
| 1019 register bloc_ptr bloc; | 999 register bloc_ptr bloc; |
| 1020 | 1000 |
| 1021 if (! r_alloc_initialized) | 1001 if (! r_alloc_initialized) |
| 1022 r_alloc_init (); | 1002 r_alloc_init (); |
| 1073 of non-relocatable heap if possible. The relocatable blocs are | 1053 of non-relocatable heap if possible. The relocatable blocs are |
| 1074 guaranteed to hold still until thawed, even if this means that | 1054 guaranteed to hold still until thawed, even if this means that |
| 1075 malloc must return a null pointer. */ | 1055 malloc must return a null pointer. */ |
| 1076 | 1056 |
| 1077 void | 1057 void |
| 1078 r_alloc_freeze (size) | 1058 r_alloc_freeze (long int size) |
| 1079 long size; | |
| 1080 { | 1059 { |
| 1081 if (! r_alloc_initialized) | 1060 if (! r_alloc_initialized) |
| 1082 r_alloc_init (); | 1061 r_alloc_init (); |
| 1083 | 1062 |
| 1084 /* If already frozen, we can't make any more room, so don't try. */ | 1063 /* If already frozen, we can't make any more room, so don't try. */ |
| 1091 if (size > 0) | 1070 if (size > 0) |
| 1092 r_alloc_sbrk (-size); | 1071 r_alloc_sbrk (-size); |
| 1093 } | 1072 } |
| 1094 | 1073 |
| 1095 void | 1074 void |
| 1096 r_alloc_thaw () | 1075 r_alloc_thaw (void) |
| 1097 { | 1076 { |
| 1098 | 1077 |
| 1099 if (! r_alloc_initialized) | 1078 if (! r_alloc_initialized) |
| 1100 r_alloc_init (); | 1079 r_alloc_init (); |
| 1101 | 1080 |
| 1120 #if defined (emacs) && defined (DOUG_LEA_MALLOC) | 1099 #if defined (emacs) && defined (DOUG_LEA_MALLOC) |
| 1121 | 1100 |
| 1122 /* Reinitialize the morecore hook variables after restarting a dumped | 1101 /* Reinitialize the morecore hook variables after restarting a dumped |
| 1123 Emacs. This is needed when using Doug Lea's malloc from GNU libc. */ | 1102 Emacs. This is needed when using Doug Lea's malloc from GNU libc. */ |
| 1124 void | 1103 void |
| 1125 r_alloc_reinit () | 1104 r_alloc_reinit (void) |
| 1126 { | 1105 { |
| 1127 /* Only do this if the hook has been reset, so that we don't get an | 1106 /* Only do this if the hook has been reset, so that we don't get an |
| 1128 infinite loop, in case Emacs was linked statically. */ | 1107 infinite loop, in case Emacs was linked statically. */ |
| 1129 if (__morecore != r_alloc_sbrk) | 1108 if (__morecore != r_alloc_sbrk) |
| 1130 { | 1109 { |
| 1233 Used by buffer-swap-text in Emacs to restore consistency after it | 1212 Used by buffer-swap-text in Emacs to restore consistency after it |
| 1234 swaps the buffer text between two buffer objects. The OLD pointer | 1213 swaps the buffer text between two buffer objects. The OLD pointer |
| 1235 is checked to ensure that memory corruption does not occur due to | 1214 is checked to ensure that memory corruption does not occur due to |
| 1236 misuse. */ | 1215 misuse. */ |
| 1237 void | 1216 void |
| 1238 r_alloc_reset_variable (old, new) | 1217 r_alloc_reset_variable (POINTER *old, POINTER *new) |
| 1239 POINTER *old, *new; | |
| 1240 { | 1218 { |
| 1241 bloc_ptr bloc = first_bloc; | 1219 bloc_ptr bloc = first_bloc; |
| 1242 | 1220 |
| 1243 /* Find the bloc that corresponds to the data pointed to by pointer. | 1221 /* Find the bloc that corresponds to the data pointed to by pointer. |
| 1244 find_bloc cannot be used, as it has internal consistency checks | 1222 find_bloc cannot be used, as it has internal consistency checks |
| 1264 ***********************************************************************/ | 1242 ***********************************************************************/ |
| 1265 | 1243 |
| 1266 /* Initialize various things for memory allocation. */ | 1244 /* Initialize various things for memory allocation. */ |
| 1267 | 1245 |
| 1268 static void | 1246 static void |
| 1269 r_alloc_init () | 1247 r_alloc_init (void) |
| 1270 { | 1248 { |
| 1271 if (r_alloc_initialized) | 1249 if (r_alloc_initialized) |
| 1272 return; | 1250 return; |
| 1273 r_alloc_initialized = 1; | 1251 r_alloc_initialized = 1; |
| 1274 | 1252 |
