Mercurial > emacs
annotate src/ralloc.c @ 112429:6e50030da731
Some copyright.el updates.
* lisp/emacs-lisp/copyright.el (copyright-find-copyright): New function,
split out from copyright-update-year.
(copyright-update): Don't mess with the GPL version if we don't own the
copyright. Update license regexp, and remove no longer needed
Esperanto stuff.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sat, 22 Jan 2011 14:09:09 -0800 |
parents | 56d3e9c28eb0 |
children |
rev | line source |
---|---|
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1 /* Block-relocating memory allocator. |
75227
e90d04cd455a
Update copyright for years from Emacs 21 to present (mainly adding
Glenn Morris <rgm@gnu.org>
parents:
73539
diff
changeset
|
2 Copyright (C) 1993, 1995, 2000, 2001, 2002, 2003, 2004, |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
106815
diff
changeset
|
3 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
118 | 4 |
5 This file is part of GNU Emacs. | |
6 | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
7 GNU Emacs is free software: you can redistribute it and/or modify |
118 | 8 it under the terms of the GNU General Public License as published by |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
10 (at your option) any later version. |
118 | 11 |
12 GNU Emacs is distributed in the hope that it will be useful, | |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
94963
8971ddf55736
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
79759
diff
changeset
|
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
118 | 19 |
20 /* NOTES: | |
21 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3136
diff
changeset
|
22 Only relocate the blocs necessary for SIZE in r_alloc_sbrk, |
118 | 23 rather than all of them. This means allowing for a possible |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
24 hole between the first bloc and the end of malloc storage. */ |
118 | 25 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
26 #ifdef emacs |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
27 |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4230
diff
changeset
|
28 #include <config.h> |
105669
68dd71358159
* alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
100951
diff
changeset
|
29 #include <setjmp.h> |
577 | 30 #include "lisp.h" /* Needed for VALBITS. */ |
61226 | 31 #include "blockinput.h" |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
32 |
29917 | 33 #include <unistd.h> |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
34 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
35 typedef POINTER_TYPE *POINTER; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
36 typedef size_t SIZE; |
1451
107c9b227e7f
[emacs]: Define POINTER and SIZE.
Richard M. Stallman <rms@gnu.org>
parents:
1403
diff
changeset
|
37 |
17845
ac6367122ee2
(mallopt): Declare, if appropriate.
Richard M. Stallman <rms@gnu.org>
parents:
14953
diff
changeset
|
38 #ifdef DOUG_LEA_MALLOC |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
39 #define M_TOP_PAD -2 |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
40 extern int mallopt (int, int); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
41 #else /* not DOUG_LEA_MALLOC */ |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
42 #ifndef SYSTEM_MALLOC |
31891
d8d68cbd1113
(__malloc_extra_blocks): Declare as __malloc_size_t.
Dave Love <fx@gnu.org>
parents:
31606
diff
changeset
|
43 extern size_t __malloc_extra_blocks; |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
44 #endif /* SYSTEM_MALLOC */ |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
45 #endif /* not DOUG_LEA_MALLOC */ |
10785
f3a45c2e57c2
(r_alloc_init): Set __malloc_extra_blocks.
Richard M. Stallman <rms@gnu.org>
parents:
10767
diff
changeset
|
46 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
47 #else /* not emacs */ |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
48 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
49 #include <stddef.h> |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
50 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
51 typedef size_t SIZE; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
52 typedef void *POINTER; |
1403
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
53 |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
54 #include <unistd.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
55 #include <malloc.h> |
f0ea279194f8
Removed #include "mem-limits.h".
Roland McGrath <roland@gnu.org>
parents:
1401
diff
changeset
|
56 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
57 #endif /* not emacs */ |
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
58 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
59 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
60 #include "getpagesize.h" |
118 | 61 |
62 #define NIL ((POINTER) 0) | |
63 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
64 /* A flag to indicate whether we have initialized ralloc yet. For |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
65 Emacs's sake, please do not make this local to malloc_init; on some |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
66 machines, the dumping procedure makes all static variables |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
67 read-only. On these machines, the word static is #defined to be |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
68 the empty string, meaning that r_alloc_initialized becomes an |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
69 automatic variable, and loses its value each time Emacs is started |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
70 up. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
71 |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
72 static int r_alloc_initialized = 0; |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
73 |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
74 static void r_alloc_init (void); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
75 |
118 | 76 |
577 | 77 /* Declarations for working with the malloc, ralloc, and system breaks. */ |
78 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
79 /* Function to set the real break value. */ |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109501
diff
changeset
|
80 POINTER (*real_morecore) (long int); |
118 | 81 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
82 /* The break value, as seen by malloc. */ |
118 | 83 static POINTER virtual_break_value; |
84 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
85 /* The address of the end of the last data in use by ralloc, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
86 including relocatable blocs as well as malloc data. */ |
118 | 87 static POINTER break_value; |
88 | |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
89 /* This is the size of a page. We round memory requests to this boundary. */ |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
90 static int page_size; |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
91 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
92 /* Whenever we get memory from the system, get this many extra bytes. This |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
93 must be a multiple of page_size. */ |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
94 static int extra_bytes; |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
95 |
118 | 96 /* Macros for rounding. Note that rounding to any value is possible |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
97 by changing the definition of PAGE. */ |
118 | 98 #define PAGE (getpagesize ()) |
4230
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
99 #define ALIGNED(addr) (((unsigned long int) (addr) & (page_size - 1)) == 0) |
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
100 #define ROUNDUP(size) (((unsigned long int) (size) + page_size - 1) \ |
df4d091e603e
(ALIGNED, ROUNDUP): Use `unsigned long int' instead of `unsigned int' for
Roland McGrath <roland@gnu.org>
parents:
3591
diff
changeset
|
101 & ~(page_size - 1)) |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
102 #define ROUND_TO_PAGE(addr) (addr & (~(page_size - 1))) |
118 | 103 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
104 #define MEM_ALIGN sizeof(double) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
105 #define MEM_ROUNDUP(addr) (((unsigned long int)(addr) + MEM_ALIGN - 1) \ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
106 & ~(MEM_ALIGN - 1)) |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
107 |
36187
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
108 /* The hook `malloc' uses for the function which gets more space |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
109 from the system. */ |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
110 |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
111 #ifndef SYSTEM_MALLOC |
109516
68ca98ae70fb
Make building under stricter warning flags somewhat cleaner.
Juanma Barranquero <lekktu@gmail.com>
parents:
109501
diff
changeset
|
112 extern POINTER (*__morecore) (long int); |
36187
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
113 #endif |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
114 |
72f30168f26c
(__morecore) [!SYSTEM_MALLOC]: Move declaration
Gerd Moellmann <gerd@gnu.org>
parents:
31891
diff
changeset
|
115 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
116 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
117 /*********************************************************************** |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
118 Implementation using sbrk |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
119 ***********************************************************************/ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
120 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
121 /* Data structures of heaps and blocs. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
122 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
123 /* The relocatable objects, or blocs, and the malloc data |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
124 both reside within one or more heaps. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
125 Each heap contains malloc data, running from `start' to `bloc_start', |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
126 and relocatable objects, running from `bloc_start' to `free'. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
127 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
128 Relocatable objects may relocate within the same heap |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
129 or may move into another heap; the heaps themselves may grow |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
130 but they never move. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
131 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
132 We try to make just one heap and make it larger as necessary. |
14036 | 133 But sometimes we can't do that, because we can't get contiguous |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
134 space to add onto the heap. When that happens, we start a new heap. */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
135 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
136 typedef struct heap |
118 | 137 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
138 struct heap *next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
139 struct heap *prev; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
140 /* Start of memory range of this heap. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
141 POINTER start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
142 /* End of memory range of this heap. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
143 POINTER end; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
144 /* Start of relocatable data in this heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
145 POINTER bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
146 /* Start of unused space in this heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
147 POINTER free; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
148 /* First bloc in this heap. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
149 struct bp *first_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
150 /* Last bloc in this heap. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
151 struct bp *last_bloc; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
152 } *heap_ptr; |
118 | 153 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
154 #define NIL_HEAP ((heap_ptr) 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
155 #define HEAP_PTR_SIZE (sizeof (struct heap)) |
118 | 156 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
157 /* This is the first heap object. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
158 If we need additional heap objects, each one resides at the beginning of |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
159 the space it covers. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
160 static struct heap heap_base; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
161 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
162 /* Head and tail of the list of heaps. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
163 static heap_ptr first_heap, last_heap; |
577 | 164 |
165 /* These structures are allocated in the malloc arena. | |
166 The linked list is kept in order of increasing '.data' members. | |
167 The data blocks abut each other; if b->next is non-nil, then | |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
168 b->data + b->size == b->next->data. |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
169 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
170 An element with variable==NIL denotes a freed block, which has not yet |
99767
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
171 been collected. They may only appear while r_alloc_freeze_level > 0, |
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
172 and will be freed when the arena is thawed. Currently, these blocs are |
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
173 not reusable, while the arena is frozen. Very inefficient. */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
174 |
118 | 175 typedef struct bp |
176 { | |
177 struct bp *next; | |
178 struct bp *prev; | |
179 POINTER *variable; | |
180 POINTER data; | |
181 SIZE size; | |
14036 | 182 POINTER new_data; /* temporarily used for relocation */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
183 struct heap *heap; /* Heap this bloc is in. */ |
118 | 184 } *bloc_ptr; |
185 | |
186 #define NIL_BLOC ((bloc_ptr) 0) | |
187 #define BLOC_PTR_SIZE (sizeof (struct bp)) | |
188 | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
189 /* Head and tail of the list of relocatable blocs. */ |
118 | 190 static bloc_ptr first_bloc, last_bloc; |
191 | |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
192 static int use_relocatable_buffers; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
193 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
194 /* If >0, no relocation whatsoever takes place. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
195 static int r_alloc_freeze_level; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
196 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
197 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
198 /* Functions to get and return memory from the system. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
199 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
200 /* Find the heap that ADDRESS falls within. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
201 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
202 static heap_ptr |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
203 find_heap (POINTER address) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
204 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
205 heap_ptr heap; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
206 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
207 for (heap = last_heap; heap; heap = heap->prev) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
208 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
209 if (heap->start <= address && address <= heap->end) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
210 return heap; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
211 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
212 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
213 return NIL_HEAP; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
214 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
215 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
216 /* Find SIZE bytes of space in a heap. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
217 Try to get them at ADDRESS (which must fall within some heap's range) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
218 if we can get that many within one heap. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
219 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
220 If enough space is not presently available in our reserve, this means |
14036 | 221 getting more page-aligned space from the system. If the returned space |
222 is not contiguous to the last heap, allocate a new heap, and append it | |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
223 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
224 obtain does not try to keep track of whether space is in use |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
225 or not in use. It just returns the address of SIZE bytes that |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
226 fall within a single heap. If you call obtain twice in a row |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
227 with the same arguments, you typically get the same value. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
228 to the heap list. It's the caller's responsibility to keep |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
229 track of what space is in use. |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
230 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
231 Return the address of the space if all went well, or zero if we couldn't |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
232 allocate the memory. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
233 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
234 static POINTER |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
235 obtain (POINTER address, SIZE size) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
236 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
237 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
238 SIZE already_available; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
239 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
240 /* Find the heap that ADDRESS falls within. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
241 for (heap = last_heap; heap; heap = heap->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
242 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
243 if (heap->start <= address && address <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
244 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
245 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
246 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
247 if (! heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
248 abort (); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
249 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
250 /* If we can't fit SIZE bytes in that heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
251 try successive later heaps. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
252 while (heap && (char *) address + size > (char *) heap->end) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
253 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
254 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
255 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
256 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
257 address = heap->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
258 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
259 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
260 /* If we can't fit them within any existing heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
261 get more space. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
262 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
263 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
264 POINTER new = (*real_morecore)(0); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
265 SIZE get; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
266 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
267 already_available = (char *)last_heap->end - (char *)address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
268 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
269 if (new != last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
270 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
271 /* Someone else called sbrk. Make a new heap. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
272 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
273 heap_ptr new_heap = (heap_ptr) MEM_ROUNDUP (new); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
274 POINTER bloc_start = (POINTER) MEM_ROUNDUP ((POINTER)(new_heap + 1)); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
275 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
276 if ((*real_morecore) ((char *) bloc_start - (char *) new) != new) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
277 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
278 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
279 new_heap->start = new; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
280 new_heap->end = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
281 new_heap->bloc_start = bloc_start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
282 new_heap->free = bloc_start; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
283 new_heap->next = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
284 new_heap->prev = last_heap; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
285 new_heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
286 new_heap->last_bloc = NIL_BLOC; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
287 last_heap->next = new_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
288 last_heap = new_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
289 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
290 address = bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
291 already_available = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
292 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
293 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
294 /* Add space to the last heap (which we may have just created). |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
295 Get some extra, so we can come here less often. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
296 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
297 get = size + extra_bytes - already_available; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
298 get = (char *) ROUNDUP ((char *)last_heap->end + get) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
299 - (char *) last_heap->end; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
300 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
301 if ((*real_morecore) (get) != last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
302 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
303 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
304 last_heap->end = (char *) last_heap->end + get; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
305 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
306 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
307 return address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
308 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
309 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
310 /* Return unused heap space to the system |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
311 if there is a lot of unused space now. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
312 This can make the last heap smaller; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
313 it can also eliminate the last heap entirely. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
314 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
315 static void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
316 relinquish (void) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
317 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
318 register heap_ptr h; |
73539
db045c86d29b
* ralloc.c (relinquish): Use a long for excess space counter to
Chong Yidong <cyd@stupidchicken.com>
parents:
68651
diff
changeset
|
319 long excess = 0; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
320 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
321 /* Add the amount of space beyond break_value |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
322 in all heaps which have extend beyond break_value at all. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
323 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
324 for (h = last_heap; h && break_value < h->end; h = h->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
325 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
326 excess += (char *) h->end - (char *) ((break_value < h->bloc_start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
327 ? h->bloc_start : break_value); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
328 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
329 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
330 if (excess > extra_bytes * 2 && (*real_morecore) (0) == last_heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
331 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
332 /* Keep extra_bytes worth of empty space. |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
333 And don't free anything unless we can free at least extra_bytes. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
334 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
335 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
336 if ((char *)last_heap->end - (char *)last_heap->bloc_start <= excess) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
337 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
338 /* This heap should have no blocs in it. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
339 if (last_heap->first_bloc != NIL_BLOC |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
340 || last_heap->last_bloc != NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
341 abort (); |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
342 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
343 /* Return the last heap, with its header, to the system. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
344 excess = (char *)last_heap->end - (char *)last_heap->start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
345 last_heap = last_heap->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
346 last_heap->next = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
347 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
348 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
349 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
350 excess = (char *) last_heap->end |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
351 - (char *) ROUNDUP ((char *)last_heap->end - excess); |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
352 last_heap->end = (char *) last_heap->end - excess; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
353 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
354 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
355 if ((*real_morecore) (- excess) == 0) |
19999
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
356 { |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
357 /* If the system didn't want that much memory back, adjust |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
358 the end of the last heap to reflect that. This can occur |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
359 if break_value is still within the original data segment. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
360 last_heap->end = (char *) last_heap->end + excess; |
19999
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
361 /* Make sure that the result of the adjustment is accurate. |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
362 It should be, for the else clause above; the other case, |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
363 which returns the entire last heap to the system, seems |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
364 unlikely to trigger this mode of failure. */ |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
365 if (last_heap->end != (*real_morecore) (0)) |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
366 abort (); |
cc8daec6d363
(relinquish): When returning memory to the system,
Karl Heuer <kwzh@gnu.org>
parents:
18757
diff
changeset
|
367 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
368 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
369 } |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
370 |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
371 /* Return the total size in use by relocating allocator, |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
372 above where malloc gets space. */ |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
373 |
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
374 long |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
375 r_alloc_size_in_use (void) |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
376 { |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
377 return (char *) break_value - (char *) virtual_break_value; |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
378 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
379 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
380 /* The meat - allocating, freeing, and relocating blocs. */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
381 |
577 | 382 /* Find the bloc referenced by the address in PTR. Returns a pointer |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
383 to that block. */ |
118 | 384 |
385 static bloc_ptr | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
386 find_bloc (POINTER *ptr) |
118 | 387 { |
388 register bloc_ptr p = first_bloc; | |
389 | |
390 while (p != NIL_BLOC) | |
391 { | |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
392 /* Consistency check. Don't return inconsistent blocs. |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
393 Don't abort here, as callers might be expecting this, but |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
394 callers that always expect a bloc to be returned should abort |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
395 if one isn't to avoid a memory corruption bug that is |
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
396 difficult to track down. */ |
118 | 397 if (p->variable == ptr && p->data == *ptr) |
398 return p; | |
399 | |
400 p = p->next; | |
401 } | |
402 | |
403 return p; | |
404 } | |
405 | |
406 /* Allocate a bloc of SIZE bytes and append it to the chain of blocs. | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
407 Returns a pointer to the new bloc, or zero if we couldn't allocate |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
408 memory for the new block. */ |
118 | 409 |
410 static bloc_ptr | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
411 get_bloc (SIZE size) |
118 | 412 { |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
413 register bloc_ptr new_bloc; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
414 register heap_ptr heap; |
118 | 415 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
416 if (! (new_bloc = (bloc_ptr) malloc (BLOC_PTR_SIZE)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
417 || ! (new_bloc->data = obtain (break_value, size))) |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
418 { |
95479
9588c3703f38
remove useless if-before-free tests
Jim Meyering <jim@meyering.net>
parents:
94963
diff
changeset
|
419 free (new_bloc); |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
420 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
421 return 0; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
422 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
423 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
424 break_value = (char *) new_bloc->data + size; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
425 |
118 | 426 new_bloc->size = size; |
427 new_bloc->next = NIL_BLOC; | |
1013
6bf2c4766d4c
* ralloc.c (get_bloc): When initializing new_bloc->variable, cast
Jim Blandy <jimb@redhat.com>
parents:
734
diff
changeset
|
428 new_bloc->variable = (POINTER *) NIL; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
429 new_bloc->new_data = 0; |
118 | 430 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
431 /* Record in the heap that this space is in use. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
432 heap = find_heap (new_bloc->data); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
433 heap->free = break_value; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
434 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
435 /* Maintain the correspondence between heaps and blocs. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
436 new_bloc->heap = heap; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
437 heap->last_bloc = new_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
438 if (heap->first_bloc == NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
439 heap->first_bloc = new_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
440 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
441 /* Put this bloc on the doubly-linked list of blocs. */ |
118 | 442 if (first_bloc) |
443 { | |
444 new_bloc->prev = last_bloc; | |
445 last_bloc->next = new_bloc; | |
446 last_bloc = new_bloc; | |
447 } | |
448 else | |
449 { | |
450 first_bloc = last_bloc = new_bloc; | |
451 new_bloc->prev = NIL_BLOC; | |
452 } | |
453 | |
454 return new_bloc; | |
455 } | |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
456 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
457 /* Calculate new locations of blocs in the list beginning with BLOC, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
458 relocating it to start at ADDRESS, in heap HEAP. If enough space is |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
459 not presently available in our reserve, call obtain for |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
460 more space. |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
461 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
462 Store the new location of each bloc in its new_data field. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
463 Do not touch the contents of blocs or break_value. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
464 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
465 static int |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
466 relocate_blocs (bloc_ptr bloc, heap_ptr heap, POINTER address) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
467 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
468 register bloc_ptr b = bloc; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
469 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
470 /* No need to ever call this if arena is frozen, bug somewhere! */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
471 if (r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
472 abort(); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
473 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
474 while (b) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
475 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
476 /* If bloc B won't fit within HEAP, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
477 move to the next heap and try again. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
478 while (heap && (char *) address + b->size > (char *) heap->end) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
479 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
480 heap = heap->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
481 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
482 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
483 address = heap->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
484 } |
118 | 485 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
486 /* If BLOC won't fit in any heap, |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
487 get enough new space to hold BLOC and all following blocs. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
488 if (heap == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
489 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
490 register bloc_ptr tb = b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
491 register SIZE s = 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
492 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
493 /* Add up the size of all the following blocs. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
494 while (tb != NIL_BLOC) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
495 { |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
496 if (tb->variable) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
497 s += tb->size; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
498 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
499 tb = tb->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
500 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
501 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
502 /* Get that space. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
503 address = obtain (address, s); |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
504 if (address == 0) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
505 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
506 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
507 heap = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
508 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
509 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
510 /* Record the new address of this bloc |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
511 and update where the next bloc can start. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
512 b->new_data = address; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
513 if (b->variable) |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
514 address = (char *) address + b->size; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
515 b = b->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
516 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
517 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
518 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
519 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
520 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
521 /* Update the records of which heaps contain which blocs, starting |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
522 with heap HEAP and bloc BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
523 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
524 static void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
525 update_heap_bloc_correspondence (bloc_ptr bloc, heap_ptr heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
526 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
527 register bloc_ptr b; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
528 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
529 /* Initialize HEAP's status to reflect blocs before BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
530 if (bloc != NIL_BLOC && bloc->prev != NIL_BLOC && bloc->prev->heap == heap) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
531 { |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
532 /* The previous bloc is in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
533 heap->last_bloc = bloc->prev; |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
534 heap->free = (char *) bloc->prev->data + bloc->prev->size; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
535 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
536 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
537 { |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
538 /* HEAP contains no blocs before BLOC. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
539 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
540 heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
541 heap->free = heap->bloc_start; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
542 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
543 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
544 /* Advance through blocs one by one. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
545 for (b = bloc; b != NIL_BLOC; b = b->next) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
546 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
547 /* Advance through heaps, marking them empty, |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
548 till we get to the one that B is in. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
549 while (heap) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
550 { |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
551 if (heap->bloc_start <= b->data && b->data <= heap->end) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
552 break; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
553 heap = heap->next; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
554 /* We know HEAP is not null now, |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
555 because there has to be space for bloc B. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
556 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
557 heap->last_bloc = NIL_BLOC; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
558 heap->free = heap->bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
559 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
560 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
561 /* Update HEAP's status for bloc B. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
562 heap->free = (char *) b->data + b->size; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
563 heap->last_bloc = b; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
564 if (heap->first_bloc == NIL_BLOC) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
565 heap->first_bloc = b; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
566 |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
567 /* Record that B is in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
568 b->heap = heap; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
569 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
570 |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
571 /* If there are any remaining heaps and no blocs left, |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
572 mark those heaps as empty. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
573 heap = heap->next; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
574 while (heap) |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
575 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
576 heap->first_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
577 heap->last_bloc = NIL_BLOC; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
578 heap->free = heap->bloc_start; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
579 heap = heap->next; |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
580 } |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
581 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
582 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
583 /* Resize BLOC to SIZE bytes. This relocates the blocs |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
584 that come after BLOC in memory. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
585 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
586 static int |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
587 resize_bloc (bloc_ptr bloc, SIZE size) |
118 | 588 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
589 register bloc_ptr b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
590 heap_ptr heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
591 POINTER address; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
592 SIZE old_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
593 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
594 /* No need to ever call this if arena is frozen, bug somewhere! */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
595 if (r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
596 abort(); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
597 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
598 if (bloc == NIL_BLOC || size == bloc->size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
599 return 1; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
600 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
601 for (heap = first_heap; heap != NIL_HEAP; heap = heap->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
602 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
603 if (heap->bloc_start <= bloc->data && bloc->data <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
604 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
605 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
606 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
607 if (heap == NIL_HEAP) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
608 abort (); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
609 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
610 old_size = bloc->size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
611 bloc->size = size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
612 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
613 /* Note that bloc could be moved into the previous heap. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
614 address = (bloc->prev ? (char *) bloc->prev->data + bloc->prev->size |
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
615 : (char *) first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
616 while (heap) |
118 | 617 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
618 if (heap->bloc_start <= address && address <= heap->end) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
619 break; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
620 heap = heap->prev; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
621 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
622 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
623 if (! relocate_blocs (bloc, heap, address)) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
624 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
625 bloc->size = old_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
626 return 0; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
627 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
628 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
629 if (size > old_size) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
630 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
631 for (b = last_bloc; b != bloc; b = b->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
632 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
633 if (!b->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
634 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
635 b->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
636 b->data = b->new_data; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
637 } |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
638 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
639 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
640 memmove (b->new_data, b->data, b->size); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
641 *b->variable = b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
642 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
643 } |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
644 if (!bloc->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
645 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
646 bloc->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
647 bloc->data = bloc->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
648 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
649 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
650 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
651 memmove (bloc->new_data, bloc->data, old_size); |
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
652 memset (bloc->new_data + old_size, 0, size - old_size); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
653 *bloc->variable = bloc->data = bloc->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
654 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
655 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
656 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
657 { |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
658 for (b = bloc; b != NIL_BLOC; b = b->next) |
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
659 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
660 if (!b->variable) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
661 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
662 b->size = 0; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
663 b->data = b->new_data; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
664 } |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
665 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
666 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
667 memmove (b->new_data, b->data, b->size); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
668 *b->variable = b->data = b->new_data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
669 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
670 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
671 } |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
672 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
673 update_heap_bloc_correspondence (bloc, heap); |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
674 |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
675 break_value = (last_bloc ? (char *) last_bloc->data + last_bloc->size |
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
676 : (char *) first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
677 return 1; |
1595
ac1be1d32868
* ralloc.c (relocate_some_blocs): Handle BLOC == NIL_BLOC.
Jim Blandy <jimb@redhat.com>
parents:
1473
diff
changeset
|
678 } |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
679 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
680 /* Free BLOC from the chain of blocs, relocating any blocs above it. |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
681 This may return space to the system. */ |
118 | 682 |
683 static void | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
684 free_bloc (bloc_ptr bloc) |
118 | 685 { |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
686 heap_ptr heap = bloc->heap; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
687 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
688 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
689 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
690 bloc->variable = (POINTER *) NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
691 return; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
692 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
693 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
694 resize_bloc (bloc, 0); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
695 |
118 | 696 if (bloc == first_bloc && bloc == last_bloc) |
697 { | |
698 first_bloc = last_bloc = NIL_BLOC; | |
699 } | |
700 else if (bloc == last_bloc) | |
701 { | |
702 last_bloc = bloc->prev; | |
703 last_bloc->next = NIL_BLOC; | |
704 } | |
705 else if (bloc == first_bloc) | |
706 { | |
707 first_bloc = bloc->next; | |
708 first_bloc->prev = NIL_BLOC; | |
709 } | |
710 else | |
711 { | |
712 bloc->next->prev = bloc->prev; | |
713 bloc->prev->next = bloc->next; | |
714 } | |
715 | |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
716 /* Update the records of which blocs are in HEAP. */ |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
717 if (heap->first_bloc == bloc) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
718 { |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
719 if (bloc->next != 0 && bloc->next->heap == heap) |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
720 heap->first_bloc = bloc->next; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
721 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
722 heap->first_bloc = heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
723 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
724 if (heap->last_bloc == bloc) |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
725 { |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
726 if (bloc->prev != 0 && bloc->prev->heap == heap) |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
727 heap->last_bloc = bloc->prev; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
728 else |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
729 heap->first_bloc = heap->last_bloc = NIL_BLOC; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
730 } |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
731 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
732 relinquish (); |
118 | 733 free (bloc); |
734 } | |
735 | |
577 | 736 /* Interface routines. */ |
737 | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
738 /* Obtain SIZE bytes of storage from the free pool, or the system, as |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
739 necessary. If relocatable blocs are in use, this means relocating |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
740 them. This function gets plugged into the GNU malloc's __morecore |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
741 hook. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
742 |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
743 We provide hysteresis, never relocating by less than extra_bytes. |
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
744 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
745 If we're out of memory, we should return zero, to imitate the other |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
746 __morecore hook values - in particular, __default_morecore in the |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
747 GNU malloc package. */ |
118 | 748 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
749 POINTER |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
750 r_alloc_sbrk (long int size) |
118 | 751 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
752 register bloc_ptr b; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
753 POINTER address; |
118 | 754 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
755 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
756 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
757 |
118 | 758 if (! use_relocatable_buffers) |
1401 | 759 return (*real_morecore) (size); |
118 | 760 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
761 if (size == 0) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
762 return virtual_break_value; |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
763 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
764 if (size > 0) |
118 | 765 { |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
766 /* Allocate a page-aligned space. GNU malloc would reclaim an |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
767 extra space if we passed an unaligned one. But we could |
14036 | 768 not always find a space which is contiguous to the previous. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
769 POINTER new_bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
770 heap_ptr h = first_heap; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
771 SIZE get = ROUNDUP (size); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
772 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
773 address = (POINTER) ROUNDUP (virtual_break_value); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
774 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
775 /* Search the list upward for a heap which is large enough. */ |
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
776 while ((char *) h->end < (char *) MEM_ROUNDUP ((char *)address + get)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
777 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
778 h = h->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
779 if (h == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
780 break; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
781 address = (POINTER) ROUNDUP (h->start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
782 } |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
783 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
784 /* If not found, obtain more space. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
785 if (h == NIL_HEAP) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
786 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
787 get += extra_bytes + page_size; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
788 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
789 if (! obtain (address, get)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
790 return 0; |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
791 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
792 if (first_heap == last_heap) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
793 address = (POINTER) ROUNDUP (virtual_break_value); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
794 else |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
795 address = (POINTER) ROUNDUP (last_heap->start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
796 h = last_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
797 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
798 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
799 new_bloc_start = (POINTER) MEM_ROUNDUP ((char *)address + get); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
800 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
801 if (first_heap->bloc_start < new_bloc_start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
802 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
803 /* This is no clean solution - no idea how to do it better. */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
804 if (r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
805 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
806 |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
807 /* There is a bug here: if the above obtain call succeeded, but the |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
808 relocate_blocs call below does not succeed, we need to free |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
809 the memory that we got with obtain. */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
810 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
811 /* Move all blocs upward. */ |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
812 if (! relocate_blocs (first_bloc, h, new_bloc_start)) |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
813 return 0; |
577 | 814 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
815 /* Note that (POINTER)(h+1) <= new_bloc_start since |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
816 get >= page_size, so the following does not destroy the heap |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
817 header. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
818 for (b = last_bloc; b != NIL_BLOC; b = b->prev) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
819 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
820 memmove (b->new_data, b->data, b->size); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
821 *b->variable = b->data = b->new_data; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
822 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
823 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
824 h->bloc_start = new_bloc_start; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
825 |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
826 update_heap_bloc_correspondence (first_bloc, h); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
827 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
828 if (h != first_heap) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
829 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
830 /* Give up managing heaps below the one the new |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
831 virtual_break_value points to. */ |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
832 first_heap->prev = NIL_HEAP; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
833 first_heap->next = h->next; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
834 first_heap->start = h->start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
835 first_heap->end = h->end; |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
836 first_heap->free = h->free; |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
837 first_heap->first_bloc = h->first_bloc; |
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
838 first_heap->last_bloc = h->last_bloc; |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
839 first_heap->bloc_start = h->bloc_start; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
840 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
841 if (first_heap->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
842 first_heap->next->prev = first_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
843 else |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
844 last_heap = first_heap; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
845 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
846 |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
847 memset (address, 0, size); |
118 | 848 } |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
849 else /* size < 0 */ |
118 | 850 { |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
851 SIZE excess = (char *)first_heap->bloc_start |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
852 - ((char *)virtual_break_value + size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
853 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
854 address = virtual_break_value; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
855 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
856 if (r_alloc_freeze_level == 0 && excess > 2 * extra_bytes) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
857 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
858 excess -= extra_bytes; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
859 first_heap->bloc_start |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
860 = (POINTER) MEM_ROUNDUP ((char *)first_heap->bloc_start - excess); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
861 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
862 relocate_blocs (first_bloc, first_heap, first_heap->bloc_start); |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
863 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
864 for (b = first_bloc; b != NIL_BLOC; b = b->next) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
865 { |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
866 memmove (b->new_data, b->data, b->size); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
867 *b->variable = b->data = b->new_data; |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
868 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
869 } |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
870 |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
871 if ((char *)virtual_break_value + size < (char *)first_heap->start) |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
872 { |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
873 /* We found an additional space below the first heap */ |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
874 first_heap->start = (POINTER) ((char *)virtual_break_value + size); |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
875 } |
118 | 876 } |
877 | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
878 virtual_break_value = (POINTER) ((char *)address + size); |
9666
d50850d0c8f8
(struct heap): New fields first_bloc, last_bloc.
Richard M. Stallman <rms@gnu.org>
parents:
9596
diff
changeset
|
879 break_value = (last_bloc |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
880 ? (char *) last_bloc->data + last_bloc->size |
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
881 : (char *) first_heap->bloc_start); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
882 if (size < 0) |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
883 relinquish (); |
1473
6359d8850fa3
(relinquish): Adjust page_break_value by amount of memory actually given back.
Richard M. Stallman <rms@gnu.org>
parents:
1451
diff
changeset
|
884 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
885 return address; |
118 | 886 } |
887 | |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
888 |
118 | 889 /* Allocate a relocatable bloc of storage of size SIZE. A pointer to |
890 the data is returned in *PTR. PTR is thus the address of some variable | |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
891 which will use the data area. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
892 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
893 The allocation of 0 bytes is valid. |
99767
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
894 In case r_alloc_freeze_level is set, a best fit of unused blocs could be |
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
895 done before allocating a new area. Not yet done. |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
896 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
897 If we can't allocate the necessary memory, set *PTR to zero, and |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
898 return zero. */ |
118 | 899 |
900 POINTER | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
901 r_alloc (POINTER *ptr, SIZE size) |
118 | 902 { |
903 register bloc_ptr new_bloc; | |
904 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
905 if (! r_alloc_initialized) |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
906 r_alloc_init (); |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
907 |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
908 new_bloc = get_bloc (MEM_ROUNDUP (size)); |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
909 if (new_bloc) |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
910 { |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
911 new_bloc->variable = ptr; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
912 *ptr = new_bloc->data; |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
913 } |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
914 else |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
915 *ptr = 0; |
118 | 916 |
917 return *ptr; | |
918 } | |
919 | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
920 /* Free a bloc of relocatable storage whose data is pointed to by PTR. |
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
921 Store 0 in *PTR to show there's no block allocated. */ |
118 | 922 |
923 void | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
924 r_alloc_free (register POINTER *ptr) |
118 | 925 { |
926 register bloc_ptr dead_bloc; | |
927 | |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
928 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
929 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
930 |
118 | 931 dead_bloc = find_bloc (ptr); |
932 if (dead_bloc == NIL_BLOC) | |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
933 abort (); /* Double free? PTR not originally used to allocate? */ |
118 | 934 |
935 free_bloc (dead_bloc); | |
1390
92df75f4167f
(check_memory_limits): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents:
1249
diff
changeset
|
936 *ptr = 0; |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
937 |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
938 #ifdef emacs |
10682
5659c0885145
(r_alloc_size_in_use): New function.
Richard M. Stallman <rms@gnu.org>
parents:
10432
diff
changeset
|
939 refill_memory_reserve (); |
10747
c6a68e4ee53a
(r_alloc_free): Call refill_memory_reserve only if emacs.
Richard M. Stallman <rms@gnu.org>
parents:
10682
diff
changeset
|
940 #endif |
118 | 941 } |
942 | |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
943 /* Given a pointer at address PTR to relocatable data, resize it to SIZE. |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
944 Do this by shifting all blocks above this one up in memory, unless |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
945 SIZE is less than or equal to the current bloc size, in which case |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
946 do nothing. |
118 | 947 |
99767
0d5b71c55b3c
Fix typos in comments.
Juanma Barranquero <lekktu@gmail.com>
parents:
95479
diff
changeset
|
948 In case r_alloc_freeze_level is set, a new bloc is allocated, and the |
14036 | 949 memory copied to it. Not very efficient. We could traverse the |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
950 bloc_list for a best fit of free blocs first. |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
951 |
1249
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
952 Change *PTR to reflect the new bloc, and return this value. |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
953 |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
954 If more memory cannot be allocated, then leave *PTR unchanged, and |
761b9b4fd3ed
* ralloc.c: Since the users of the relocating allocation code
Jim Blandy <jimb@redhat.com>
parents:
1121
diff
changeset
|
955 return zero. */ |
118 | 956 |
957 POINTER | |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
958 r_re_alloc (POINTER *ptr, SIZE size) |
118 | 959 { |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
960 register bloc_ptr bloc; |
118 | 961 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
962 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
963 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
964 |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
965 if (!*ptr) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
966 return r_alloc (ptr, size); |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
967 if (!size) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
968 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
969 r_alloc_free (ptr); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
970 return r_alloc (ptr, 0); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
971 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
972 |
1087
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
973 bloc = find_bloc (ptr); |
6c410cc87574
* ralloc.c (r_re_alloc): Instead of allocating a new bloc at the
Jim Blandy <jimb@redhat.com>
parents:
1013
diff
changeset
|
974 if (bloc == NIL_BLOC) |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
975 abort (); /* Already freed? PTR not originally used to allocate? */ |
118 | 976 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
977 if (size < bloc->size) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
978 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
979 /* Wouldn't it be useful to actually resize the bloc here? */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
980 /* I think so too, but not if it's too expensive... */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
981 if ((bloc->size - MEM_ROUNDUP (size) >= page_size) |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
982 && r_alloc_freeze_level == 0) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
983 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
984 resize_bloc (bloc, MEM_ROUNDUP (size)); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
985 /* Never mind if this fails, just do nothing... */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
986 /* It *should* be infallible! */ |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
987 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
988 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
989 else if (size > bloc->size) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
990 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
991 if (r_alloc_freeze_level) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
992 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
993 bloc_ptr new_bloc; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
994 new_bloc = get_bloc (MEM_ROUNDUP (size)); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
995 if (new_bloc) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
996 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
997 new_bloc->variable = ptr; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
998 *ptr = new_bloc->data; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
999 bloc->variable = (POINTER *) NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1000 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1001 else |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1002 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1003 } |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1004 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1005 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1006 if (! resize_bloc (bloc, MEM_ROUNDUP (size))) |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1007 return NIL; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1008 } |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1009 } |
118 | 1010 return *ptr; |
1011 } | |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1012 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1013 /* Disable relocations, after making room for at least SIZE bytes |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1014 of non-relocatable heap if possible. The relocatable blocs are |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1015 guaranteed to hold still until thawed, even if this means that |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1016 malloc must return a null pointer. */ |
9596
134f7085c56b
(heap_base): Move static var to top level.
Richard M. Stallman <rms@gnu.org>
parents:
9459
diff
changeset
|
1017 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1018 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1019 r_alloc_freeze (long int size) |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1020 { |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1021 if (! r_alloc_initialized) |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1022 r_alloc_init (); |
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1023 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1024 /* If already frozen, we can't make any more room, so don't try. */ |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1025 if (r_alloc_freeze_level > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1026 size = 0; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1027 /* If we can't get the amount requested, half is better than nothing. */ |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1028 while (size > 0 && r_alloc_sbrk (size) == 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1029 size /= 2; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1030 ++r_alloc_freeze_level; |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1031 if (size > 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1032 r_alloc_sbrk (-size); |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1033 } |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1034 |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1035 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1036 r_alloc_thaw (void) |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1037 { |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1038 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1039 if (! r_alloc_initialized) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1040 r_alloc_init (); |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1041 |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1042 if (--r_alloc_freeze_level < 0) |
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1043 abort (); |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1044 |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1045 /* This frees all unused blocs. It is not too inefficient, as the resize |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
1046 and memcpy is done only once. Afterwards, all unreferenced blocs are |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1047 already shrunk to zero size. */ |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1048 if (!r_alloc_freeze_level) |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1049 { |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1050 bloc_ptr *b = &first_bloc; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1051 while (*b) |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1052 if (!(*b)->variable) |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1053 free_bloc (*b); |
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1054 else |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1055 b = &(*b)->next; |
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1056 } |
8951
b628561b185b
(r_alloc_freeze_level): New variable.
Karl Heuer <kwzh@gnu.org>
parents:
5063
diff
changeset
|
1057 } |
11146
9a14b32f5d71
(r_re_alloc): Correct realloc behavior--allow shrinking
Richard M. Stallman <rms@gnu.org>
parents:
10785
diff
changeset
|
1058 |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1059 |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1060 #if defined (emacs) && defined (DOUG_LEA_MALLOC) |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1061 |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1062 /* Reinitialize the morecore hook variables after restarting a dumped |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1063 Emacs. This is needed when using Doug Lea's malloc from GNU libc. */ |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1064 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1065 r_alloc_reinit (void) |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1066 { |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1067 /* Only do this if the hook has been reset, so that we don't get an |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1068 infinite loop, in case Emacs was linked statically. */ |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1069 if (__morecore != r_alloc_sbrk) |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1070 { |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1071 real_morecore = __morecore; |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1072 __morecore = r_alloc_sbrk; |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1073 } |
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1074 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1075 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1076 #endif /* emacs && DOUG_LEA_MALLOC */ |
18757
9d6149f4c762
(r_alloc_reinit): New function.
Richard M. Stallman <rms@gnu.org>
parents:
17845
diff
changeset
|
1077 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1078 #ifdef DEBUG |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1079 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1080 #include <assert.h> |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1081 |
10767
2954efb1d06c
(r_alloc_check): Return void.
Richard M. Stallman <rms@gnu.org>
parents:
10766
diff
changeset
|
1082 void |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1083 r_alloc_check () |
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1084 { |
10766 | 1085 int found = 0; |
1086 heap_ptr h, ph = 0; | |
1087 bloc_ptr b, pb = 0; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1088 |
10766 | 1089 if (!r_alloc_initialized) |
1090 return; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1091 |
10766 | 1092 assert (first_heap); |
1093 assert (last_heap->end <= (POINTER) sbrk (0)); | |
1094 assert ((POINTER) first_heap < first_heap->start); | |
1095 assert (first_heap->start <= virtual_break_value); | |
1096 assert (virtual_break_value <= first_heap->end); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1097 |
10766 | 1098 for (h = first_heap; h; h = h->next) |
1099 { | |
1100 assert (h->prev == ph); | |
1101 assert ((POINTER) ROUNDUP (h->end) == h->end); | |
14953
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1102 #if 0 /* ??? The code in ralloc.c does not really try to ensure |
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1103 the heap start has any sort of alignment. |
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1104 Perhaps it should. */ |
10766 | 1105 assert ((POINTER) MEM_ROUNDUP (h->start) == h->start); |
14953
36e4b3043730
(r_alloc_check): Don't check alignment of h->start.
Richard M. Stallman <rms@gnu.org>
parents:
14186
diff
changeset
|
1106 #endif |
10766 | 1107 assert ((POINTER) MEM_ROUNDUP (h->bloc_start) == h->bloc_start); |
1108 assert (h->start <= h->bloc_start && h->bloc_start <= h->end); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1109 |
10766 | 1110 if (ph) |
1111 { | |
1112 assert (ph->end < h->start); | |
1113 assert (h->start <= (POINTER)h && (POINTER)(h+1) <= h->bloc_start); | |
1114 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1115 |
10766 | 1116 if (h->bloc_start <= break_value && break_value <= h->end) |
1117 found = 1; | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1118 |
10766 | 1119 ph = h; |
1120 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1121 |
10766 | 1122 assert (found); |
1123 assert (last_heap == ph); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1124 |
10766 | 1125 for (b = first_bloc; b; b = b->next) |
1126 { | |
1127 assert (b->prev == pb); | |
1128 assert ((POINTER) MEM_ROUNDUP (b->data) == b->data); | |
1129 assert ((SIZE) MEM_ROUNDUP (b->size) == b->size); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1130 |
10766 | 1131 ph = 0; |
1132 for (h = first_heap; h; h = h->next) | |
1133 { | |
1134 if (h->bloc_start <= b->data && b->data + b->size <= h->end) | |
1135 break; | |
1136 ph = h; | |
1137 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1138 |
10766 | 1139 assert (h); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1140 |
10766 | 1141 if (pb && pb->data + pb->size != b->data) |
1142 { | |
1143 assert (ph && b->data == h->bloc_start); | |
1144 while (ph) | |
1145 { | |
1146 if (ph->bloc_start <= pb->data | |
1147 && pb->data + pb->size <= ph->end) | |
1148 { | |
1149 assert (pb->data + pb->size + b->size > ph->end); | |
1150 break; | |
1151 } | |
1152 else | |
1153 { | |
1154 assert (ph->bloc_start + b->size > ph->end); | |
1155 } | |
1156 ph = ph->prev; | |
1157 } | |
1158 } | |
1159 pb = b; | |
1160 } | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1161 |
10766 | 1162 assert (last_bloc == pb); |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1163 |
10766 | 1164 if (last_bloc) |
1165 assert (last_bloc->data + last_bloc->size == break_value); | |
1166 else | |
1167 assert (first_heap->bloc_start == break_value); | |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1168 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1169 |
9459
a1569f00a6a6
Install Hiroshi Nakano's rewrite to allow multiple heaps, for implementations
Karl Heuer <kwzh@gnu.org>
parents:
8951
diff
changeset
|
1170 #endif /* DEBUG */ |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1171 |
100673
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1172 /* Update the internal record of which variable points to some data to NEW. |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1173 Used by buffer-swap-text in Emacs to restore consistency after it |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1174 swaps the buffer text between two buffer objects. The OLD pointer |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1175 is checked to ensure that memory corruption does not occur due to |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1176 misuse. */ |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1177 void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1178 r_alloc_reset_variable (POINTER *old, POINTER *new) |
100673
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1179 { |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1180 bloc_ptr bloc = first_bloc; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1181 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1182 /* Find the bloc that corresponds to the data pointed to by pointer. |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1183 find_bloc cannot be used, as it has internal consistency checks |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1184 which fail when the variable needs reseting. */ |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1185 while (bloc != NIL_BLOC) |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1186 { |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1187 if (bloc->data == *new) |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1188 break; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1189 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1190 bloc = bloc->next; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1191 } |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1192 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1193 if (bloc == NIL_BLOC || bloc->variable != old) |
100674
dbba9cb0e6ce
Add comments to explain checks and aborts, to assist future debugging.
Jason Rumney <jasonr@gnu.org>
parents:
100673
diff
changeset
|
1194 abort (); /* Already freed? OLD not originally used to allocate? */ |
100673
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1195 |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1196 /* Update variable to point to the new location. */ |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1197 bloc->variable = new; |
01f68a925d12
* ralloc.c (r_alloc_reset_variable): New function.
Jason Rumney <jasonr@gnu.org>
parents:
99767
diff
changeset
|
1198 } |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1199 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1200 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1201 /*********************************************************************** |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1202 Initialization |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1203 ***********************************************************************/ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1204 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1205 /* Initialize various things for memory allocation. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1206 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1207 static void |
109126
aec1143e8d85
Convert (most) functions in src to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
106815
diff
changeset
|
1208 r_alloc_init (void) |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1209 { |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1210 if (r_alloc_initialized) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1211 return; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1212 r_alloc_initialized = 1; |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1213 |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1214 page_size = PAGE; |
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1215 #ifndef SYSTEM_MALLOC |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1216 real_morecore = __morecore; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1217 __morecore = r_alloc_sbrk; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1218 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1219 first_heap = last_heap = &heap_base; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1220 first_heap->next = first_heap->prev = NIL_HEAP; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1221 first_heap->start = first_heap->bloc_start |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1222 = virtual_break_value = break_value = (*real_morecore) (0); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1223 if (break_value == NIL) |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1224 abort (); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1225 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1226 extra_bytes = ROUNDUP (50000); |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1227 #endif |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1228 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1229 #ifdef DOUG_LEA_MALLOC |
61225
1e515cc6ca0c
* alloc.c (allocate_string_data): Call BLOCK_INPUT before calling
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1230 BLOCK_INPUT; |
1e515cc6ca0c
* alloc.c (allocate_string_data): Call BLOCK_INPUT before calling
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1231 mallopt (M_TOP_PAD, 64 * 4096); |
1e515cc6ca0c
* alloc.c (allocate_string_data): Call BLOCK_INPUT before calling
Jan Djärv <jan.h.d@swipnet.se>
parents:
52401
diff
changeset
|
1232 UNBLOCK_INPUT; |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1233 #else |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1234 #ifndef SYSTEM_MALLOC |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1235 /* Give GNU malloc's morecore some hysteresis |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1236 so that we move all the relocatable blocks much less often. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1237 __malloc_extra_blocks = 64; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1238 #endif |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1239 #endif |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1240 |
31509
6bc82db7d305
(r_alloc_init): Conditionalize on SYSTEM_MALLOC, not REL_ALLOC_MMAP.
Dave Love <fx@gnu.org>
parents:
31504
diff
changeset
|
1241 #ifndef SYSTEM_MALLOC |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1242 first_heap->end = (POINTER) ROUNDUP (first_heap->start); |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1243 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1244 /* The extra call to real_morecore guarantees that the end of the |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1245 address space is a multiple of page_size, even if page_size is |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1246 not really the page size of the system running the binary in |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1247 which page_size is stored. This allows a binary to be built on a |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1248 system with one page size and run on a system with a smaller page |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1249 size. */ |
31473
055accd6bf1d
(obtain, relinquish, relinquish, r_alloc_size_in_use)
Gerd Moellmann <gerd@gnu.org>
parents:
31468
diff
changeset
|
1250 (*real_morecore) ((char *) first_heap->end - (char *) first_heap->start); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1251 |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1252 /* Clear the rest of the last page; this memory is in our address space |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1253 even though it is after the sbrk value. */ |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1254 /* Doubly true, with the additional call that explicitly adds the |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1255 rest of that page to the address space. */ |
109165
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
1256 memset (first_heap->start, 0, |
750db9f3e6d8
Replace bcopy, bzero, bcmp by memcpy, memmove, memset, memcmp
Andreas Schwab <schwab@linux-m68k.org>
parents:
109126
diff
changeset
|
1257 (char *) first_heap->end - (char *) first_heap->start); |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1258 virtual_break_value = break_value = first_heap->bloc_start = first_heap->end; |
31498
17d4a8f3df67
Don't include string.h (redundant).
Dave Love <fx@gnu.org>
parents:
31473
diff
changeset
|
1259 #endif |
49600
23a1cea22d13
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
36187
diff
changeset
|
1260 |
31414
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1261 use_relocatable_buffers = 1; |
76dcf201d009
(POINTER, SIZE) [emacs]: Define in terms of
Gerd Moellmann <gerd@gnu.org>
parents:
30061
diff
changeset
|
1262 } |
52401 | 1263 |