annotate src/gmalloc.c @ 525:77fb0aa0e69f

[xemacs-hg @ 2001-05-09 14:31:52 by wmperry] Fix disappearing GTK scrollbar problem...
author wmperry
date Wed, 09 May 2001 14:31:56 +0000
parents 3d3049ae1304
children e9a3f8b4de53
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Synched up with: Not synched up with FSF 19.28, even though I
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 thought I did so. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 /* Get the configuration files if we're being compiled for Emacs. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 #ifdef emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 # include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 # include "getpagesize.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 # ifndef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 # define HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 # endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 #if defined (__STDC__) && !defined (STDC_HEADERS)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 /* The ANSI standard says that defining __STDC__ to a non-zero value means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 that the compiler conforms to that standard. The standard requires
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 certain header files and library functions to be present. Therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 if your compiler defines __STDC__ to non-0 but does not have ANSI headers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 and the ANSI library routines, then your compiler is buggy. Conversely,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 an ANSI-conforming environment (which has both the ANSI headers and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 library routines, i.e., stdlib.h and `memmove') does not necessarily
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 define the STDC_HEADERS flag. Lucid Emacs requires an ANSI compiler.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Therefore, there is no need to consult the abominable STDC_HEADERS flag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 -- jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 # define STDC_HEADERS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 /* DO NOT EDIT THIS FILE -- it is automagically generated. -*- C -*- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 /* Bwaa-haa-haa! Not a chance that this is actually true! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 /* The malloc headers and source files from the C library follow here. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 /* Declarations for `malloc' and friends.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 Written May 1989 by Mike Haertel.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 This library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 This library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 The author may be reached (Email) at the address mike@ai.mit.edu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 #ifndef _MALLOC_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 #define _MALLOC_H 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 #ifdef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 #include <string.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 #include <limits.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #ifdef HAVE_UNISTD_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 #include <unistd.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #endif /* _MALLOC_INTERNAL. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 #ifdef __cplusplus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 extern "C"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 #undef __P
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #define __P(args) args
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 #undef __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #define __ptr_t void *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 #include <stddef.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 #define __malloc_size_t size_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 #ifndef NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #define NULL 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 /* XEmacs: I thought this should be int under SunOS, but that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 apparently fails. Curses on all this shit. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 #define __free_ret_t void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 /* XEmacs: I tried commenting these out and including stdlib.h,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 but that fails badly. Urk! This sucks. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /* Allocate SIZE bytes of memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 extern __ptr_t malloc __P ((size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 /* Re-allocate the previously allocated block
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 in __ptr_t, making the new block SIZE bytes long. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 extern __ptr_t realloc __P ((__ptr_t __ptr, size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 /* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 extern __ptr_t calloc __P ((size_t __nmemb, size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 /* Free a block allocated by `malloc', `realloc' or `calloc'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 extern __free_ret_t free __P ((__ptr_t __ptr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 /* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 extern __ptr_t memalign __P ((size_t __alignment, size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 /* Allocate SIZE bytes on a page boundary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 extern __ptr_t valloc __P ((size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 #ifdef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 /* The allocator divides the heap into blocks of fixed size; large
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 requests receive one or more whole blocks, and small requests
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 receive a fragment of a block. Fragment sizes are powers of two,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 and all fragments of a block are the same size. When all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 fragments in a block have been freed, the block itself is freed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 #define INT_BIT (CHAR_BIT * sizeof(int))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 #define BLOCKLOG (INT_BIT > 16 ? 12 : 9)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 #define BLOCKSIZE (1 << BLOCKLOG)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 #define BLOCKIFY(SIZE) (((SIZE) + BLOCKSIZE - 1) / BLOCKSIZE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 /* Determine the amount of memory spanned by the initial heap table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 (not an absolute limit). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 #define HEAP (INT_BIT > 16 ? 4194304 : 65536)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 /* Number of contiguous free blocks allowed to build up at the end of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 memory before they will be returned to the system. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 #define FINAL_FREE_BLOCKS 8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 /* Data structure giving per-block information. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 typedef union
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 /* Heap information for a busy block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 /* Zero for a large block, or positive giving the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 logarithm to the base two of the fragment size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 int type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 union
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 __malloc_size_t nfree; /* Free frags in a fragmented block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 __malloc_size_t first; /* First free fragment of the block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 } frag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 /* Size (in blocks) of a large cluster. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 __malloc_size_t size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 } info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 } busy;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 /* Heap information for a free block
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (that may be the first of a free cluster). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 __malloc_size_t size; /* Size (in blocks) of a free cluster. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 __malloc_size_t next; /* Index of next free cluster. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 __malloc_size_t prev; /* Index of previous free cluster. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 } free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 } malloc_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 /* Pointer to first block of the heap. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 extern char *_heapbase;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 /* Table indexed by block number giving per-block information. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 extern malloc_info *_heapinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 /* Address to block number and vice versa. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 #define BLOCK(A) (((char *) (A) - _heapbase) / BLOCKSIZE + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #define ADDRESS(B) ((__ptr_t) (((B) - 1) * BLOCKSIZE + _heapbase))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 /* Current search index for the heap table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 extern __malloc_size_t _heapindex;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 /* Limit of valid info table indices. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 extern __malloc_size_t _heaplimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 /* Doubly linked lists of free fragments. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 struct list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 struct list *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 struct list *prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 /* Free list headers for each fragment size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 extern struct list _fraghead[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 /* List of blocks allocated with `memalign' (or `valloc'). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 struct alignlist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 struct alignlist *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 __ptr_t aligned; /* The address that memaligned returned. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 __ptr_t exact; /* The address that malloc returned. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 extern struct alignlist *_aligned_blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 /* Instrumentation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 extern __malloc_size_t _chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 extern __malloc_size_t _bytes_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 extern __malloc_size_t _chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 extern __malloc_size_t _bytes_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* Internal version of `free' used in `morecore' (malloc.c). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 extern void _free_internal __P ((__ptr_t __ptr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 #endif /* _MALLOC_INTERNAL. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 /* Underlying allocation function; successive calls should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 return contiguous pieces of memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 extern __ptr_t (*__morecore) __P ((ptrdiff_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 /* Default value of `__morecore'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 extern __ptr_t __default_morecore __P ((ptrdiff_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 /* If not NULL, this function is called after each time
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 `__morecore' is called to increase the data size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 extern void (*__after_morecore_hook) __P ((void));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 /* Nonzero if `malloc' has been called and done its initialization. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 /* extern int __malloc_initialized; */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 /* Hooks for debugging versions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 extern void (*__free_hook) __P ((__ptr_t __ptr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 extern __ptr_t (*__malloc_hook) __P ((size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 extern __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 /* Return values for `mprobe': these are the kinds of inconsistencies that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 `mcheck' enables detection of. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 enum mcheck_status
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 MCHECK_DISABLED = -1, /* Consistency checking is not turned on. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 MCHECK_OK, /* Block is fine. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 MCHECK_FREE, /* Block freed twice. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 MCHECK_HEAD, /* Memory before the block was clobbered. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 MCHECK_TAIL /* Memory after the block was clobbered. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 /* Activate a standard collection of debugging hooks. This must be called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 before `malloc' is ever called. ABORTFUNC is called with an error code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (see enum above) when an inconsistency is detected. If ABORTFUNC is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 null, the standard function prints on stderr and then calls `abort'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 extern int mcheck __P ((void (*__abortfunc) __P ((enum mcheck_status))));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 /* Check for aberrations in a particular malloc'd block. You must have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 called `mcheck' already. These are the same checks that `mcheck' does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 when you free or reallocate a block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 extern enum mcheck_status mprobe __P ((__ptr_t __ptr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 /* Activate a standard collection of tracing hooks. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 extern void mtrace __P ((void));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 extern void muntrace __P ((void));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 /* Statistics available to the user. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 struct mstats
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 __malloc_size_t bytes_total; /* Total size of the heap. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 __malloc_size_t chunks_used; /* Chunks allocated by the user. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 __malloc_size_t bytes_used; /* Byte total of user-allocated chunks. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 __malloc_size_t chunks_free; /* Chunks in the free list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 __malloc_size_t bytes_free; /* Byte total of chunks in the free list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 /* Pick up the current statistics. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 extern struct mstats mstats __P ((void));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 /* Call WARNFUN with a warning message when memory usage is high. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 extern void memory_warnings __P ((__ptr_t __start,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
274 void (*__warnfun) __P ((const char *))));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 #if 0 /* unused in this file, and conflicting prototypes anyway */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 /* Relocating allocator. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 /* Allocate SIZE bytes, and store the address in *HANDLEPTR. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 extern __ptr_t r_alloc __P ((__ptr_t *__handleptr, size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 /* Free the storage allocated in HANDLEPTR. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 extern void r_alloc_free __P ((__ptr_t *__handleptr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 /* Adjust the block at HANDLEPTR to be SIZE bytes long. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 extern __ptr_t r_re_alloc __P ((__ptr_t *__handleptr, size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 #endif /* 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 #ifdef __cplusplus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 #endif /* malloc.h */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 /* Allocate memory on a page boundary.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 This library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 This library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 The author may be reached (Email) at the address mike@ai.mit.edu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 #if defined (__GNU_LIBRARY__) || defined (_LIBC)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 #include <stddef.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 #include <sys/cdefs.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 #if ! (defined (__GLIBC__) && (__GLIBC__ >= 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 extern size_t __getpagesize __P ((void));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 #include "getpagesize.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 #define __getpagesize() getpagesize()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 static __malloc_size_t pagesize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 valloc (__malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 if (pagesize == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 pagesize = __getpagesize ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 return memalign (pagesize, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 /* Memory allocator `malloc'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 Written May 1989 by Mike Haertel.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 This library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 This library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 The author may be reached (Email) at the address mike@ai.mit.edu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 /* How to really get more memory. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
370 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 /* once dumped, free() & realloc() on static heap space will fail */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 #define PURE_DATA(x) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 ((static_heap_dumped && (char*)x >= static_heap_base \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 && (char*)x <= (static_heap_base + static_heap_size) ) ? 1 : 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 extern int initialized;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 extern int purify_flag;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 extern char* static_heap_base;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 extern char* static_heap_ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 extern char* static_heap_dumped;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 extern unsigned long static_heap_size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 extern __ptr_t more_static_core __P ((ptrdiff_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 __ptr_t (*__morecore) __P ((ptrdiff_t __size)) = more_static_core;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 __ptr_t (*__morecore) __P ((ptrdiff_t __size)) = __default_morecore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 #define PURE_DATA(x) 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 /* Debugging hook for `malloc'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 __ptr_t (*__malloc_hook) __P ((__malloc_size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 /* Pointer to the base of the first block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 char *_heapbase;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 /* Block information table. Allocated with align/__free (not malloc/free). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 malloc_info *_heapinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 /* Number of info entries. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 static __malloc_size_t heapsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 /* Search index in the info table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 __malloc_size_t _heapindex;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 /* Limit of valid info table indices. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 __malloc_size_t _heaplimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 /* Free lists for each fragment size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 struct list _fraghead[BLOCKLOG];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 /* Instrumentation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 __malloc_size_t _chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 __malloc_size_t _bytes_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 __malloc_size_t _chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 __malloc_size_t _bytes_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 /* Are you experienced? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 int __malloc_initialized;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 void (*__after_morecore_hook) __P ((void));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 /* Aligned allocation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 static __ptr_t align __P ((__malloc_size_t));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 static __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 align (__malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 __ptr_t result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 unsigned long int adj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 result = (*__morecore) (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 adj = (unsigned long int) ((unsigned long int) ((char *) result -
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (char *) NULL)) % BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 if (adj != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 adj = BLOCKSIZE - adj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 (void) (*__morecore) (adj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 result = (char *) result + adj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 if (__after_morecore_hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (*__after_morecore_hook) ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 /* Set everything up and remember that we have. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 static int initialize __P ((void));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 initialize ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
449 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 if (static_heap_dumped && __morecore == more_static_core)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 __morecore = __default_morecore;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 heapsize = HEAP / BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 _heapinfo = (malloc_info *) align (heapsize * sizeof (malloc_info));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 if (_heapinfo == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 memset (_heapinfo, 0, heapsize * sizeof (malloc_info));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 memset (_fraghead, 0, BLOCKLOG * sizeof (struct list));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 _heapinfo[0].free.size = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 _heapinfo[0].free.next = _heapinfo[0].free.prev = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 _heapindex = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 _heaplimit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 _heapbase = (char *) _heapinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 /* Account for the _heapinfo block itself in the statistics. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 _bytes_used = heapsize * sizeof (malloc_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 _chunks_used = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 _chunks_free=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 _bytes_free=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 _aligned_blocks=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 __malloc_initialized = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 /* Get neatly aligned memory, initializing or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 growing the heap info table as necessary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 static __ptr_t morecore __P ((__malloc_size_t));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 static __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 morecore (__malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 __ptr_t result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 malloc_info *newinfo, *oldinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 __malloc_size_t newsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 result = align (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 /* Check if we need to grow the info table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 if ((__malloc_size_t) BLOCK ((char *) result + size) > heapsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 newsize = heapsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 while ((__malloc_size_t) BLOCK ((char *) result + size) > newsize)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 newsize *= 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 newinfo = (malloc_info *) align (newsize * sizeof (malloc_info));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 if (newinfo == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 (*__morecore) (-(int)size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 memcpy (newinfo, _heapinfo, heapsize * sizeof (malloc_info));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 memset (&newinfo[heapsize], 0,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 (newsize - heapsize) * sizeof (malloc_info));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 oldinfo = _heapinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 newinfo[BLOCK (oldinfo)].busy.type = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 newinfo[BLOCK (oldinfo)].busy.info.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 = BLOCKIFY (heapsize * sizeof (malloc_info));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 _heapinfo = newinfo;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 /* Account for the _heapinfo block itself in the statistics. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 _bytes_used += newsize * sizeof (malloc_info);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 ++_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 _free_internal (oldinfo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 heapsize = newsize;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 _heaplimit = BLOCK ((char *) result + size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 /* Allocate memory from the heap. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 malloc (__malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 __ptr_t result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 __malloc_size_t block, blocks, lastblocks, start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 __malloc_size_t i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 struct list *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 /* ANSI C allows `malloc (0)' to either return NULL, or to return a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 valid address you can realloc and free (though not dereference).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 It turns out that some extant code (sunrpc, at least Ultrix's version)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 expects `malloc (0)' to return non-NULL and breaks otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 Be compatible. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 #ifdef HAVE_X_WINDOWS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 /* there is at least one Xt bug where calloc(n,x) is blindly called
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 where n can be 0, and yet if 0 is returned, Xt barfs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 if (size == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 size = sizeof (struct list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 if (size == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 if (__malloc_hook != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 return (*__malloc_hook) (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 if (!__malloc_initialized)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 if (!initialize ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 #ifdef SUNOS_LOCALTIME_BUG
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 /* Workaround for localtime() allocating 8 bytes and writing 9 bug... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 if (size < 16)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 size = 16;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 if (size < sizeof (struct list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 size = sizeof (struct list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 /* Determine the allocation policy based on the request size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 if (size <= BLOCKSIZE / 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 /* Small allocation to receive a fragment of a block.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 Determine the logarithm to base two of the fragment size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 __malloc_size_t log = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 --size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 while ((size /= 2) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 ++log;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 /* Look in the fragment lists for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 free fragment of the desired size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 next = _fraghead[log].next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 if (next != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 /* There are free fragments of this size.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 Pop a fragment out of the fragment list and return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 Update the block's nfree and first counters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 result = (__ptr_t) next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 next->prev->next = next->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 if (next->next != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 next->next->prev = next->prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 block = BLOCK (result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 if (--_heapinfo[block].busy.info.frag.nfree != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 _heapinfo[block].busy.info.frag.first = (unsigned long int)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 ((unsigned long int) ((char *) next->next - (char *) NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 % BLOCKSIZE) >> log;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 /* Update the statistics. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 ++_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 _bytes_used += 1 << log;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 --_chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 _bytes_free -= 1 << log;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 /* No free fragments of the desired size, so get a new block
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 and break it into fragments, returning the first. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 result = malloc (BLOCKSIZE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 /* Link all fragments but the first into the free list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> log); ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 next = (struct list *) ((char *) result + (i << log));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 next->next = _fraghead[log].next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 next->prev = &_fraghead[log];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 next->prev->next = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 if (next->next != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 next->next->prev = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 /* Initialize the nfree and first counters for this block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 block = BLOCK (result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 _heapinfo[block].busy.type = log;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 _heapinfo[block].busy.info.frag.nfree = i - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 _heapinfo[block].busy.info.frag.first = i - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 _chunks_free += (BLOCKSIZE >> log) - 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 _bytes_free += BLOCKSIZE - (1 << log);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 _bytes_used -= BLOCKSIZE - (1 << log);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 /* Large allocation to receive one or more blocks.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 Search the free list in a circle starting at the last place visited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 If we loop completely around without finding a large enough
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 space we will have to get more memory from the system. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 blocks = BLOCKIFY (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 start = block = _heapindex;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 while (_heapinfo[block].free.size < blocks)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 block = _heapinfo[block].free.next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 if (block == start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 /* Need to get more from the system. Check to see if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 the new core will be contiguous with the final free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 block; if so we don't need to get as much. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 block = _heapinfo[0].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 lastblocks = _heapinfo[block].free.size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 if (_heaplimit != 0 && block + lastblocks == _heaplimit &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 (*__morecore) (0) == ADDRESS (block + lastblocks) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 (morecore ((blocks - lastblocks) * BLOCKSIZE)) != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 /* Which block we are extending (the `final free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 block' referred to above) might have changed, if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 it got combined with a freed info table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 block = _heapinfo[0].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 _heapinfo[block].free.size += (blocks - lastblocks);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 _bytes_free += (blocks - lastblocks) * BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 result = morecore (blocks * BLOCKSIZE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 block = BLOCK (result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 _heapinfo[block].busy.type = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 _heapinfo[block].busy.info.size = blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 ++_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 _bytes_used += blocks * BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 /* At this point we have found a suitable free list entry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 Figure out how to remove what we need from the list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 result = ADDRESS (block);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 if (_heapinfo[block].free.size > blocks)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 /* The block we found has a bit left over,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 so relink the tail end back into the free list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 _heapinfo[block + blocks].free.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 = _heapinfo[block].free.size - blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 _heapinfo[block + blocks].free.next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 = _heapinfo[block].free.next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 _heapinfo[block + blocks].free.prev
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 = _heapinfo[block].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 _heapinfo[_heapinfo[block].free.prev].free.next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 = _heapinfo[_heapinfo[block].free.next].free.prev
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 = _heapindex = block + blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 /* The block exactly matches our requirements,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 so just remove it from the list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 _heapinfo[_heapinfo[block].free.next].free.prev
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 = _heapinfo[block].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 _heapinfo[_heapinfo[block].free.prev].free.next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 = _heapindex = _heapinfo[block].free.next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 --_chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 _heapinfo[block].busy.type = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 _heapinfo[block].busy.info.size = blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 ++_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 _bytes_used += blocks * BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 _bytes_free -= blocks * BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 #ifndef _LIBC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 /* On some ANSI C systems, some libc functions call _malloc, _free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 and _realloc. Make them use the GNU functions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 __ptr_t _malloc (__malloc_size_t size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 _malloc (__malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 return malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 void _free (__ptr_t ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 _free (__ptr_t ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 free (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 __ptr_t _realloc (__ptr_t ptr, __malloc_size_t size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 _realloc (__ptr_t ptr, __malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 return realloc (ptr, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 /* Free a block of memory allocated by `malloc'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 Copyright 1990, 1991, 1992, 1994 Free Software Foundation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 Written May 1989 by Mike Haertel.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 This library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 This library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 The author may be reached (Email) at the address mike@ai.mit.edu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 /* Debugging hook for free. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 void (*__free_hook) __P ((__ptr_t __ptr));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 /* List of blocks allocated by memalign. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 struct alignlist *_aligned_blocks = NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 /* Return memory to the heap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 Like `free' but don't call a __free_hook if there is one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 _free_internal (__ptr_t ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 int type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 __malloc_size_t block, blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 __malloc_size_t i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 struct list *prev, *next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 block = BLOCK (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 type = _heapinfo[block].busy.type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 /* Get as many statistics as early as we can. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 --_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 _bytes_used -= _heapinfo[block].busy.info.size * BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 _bytes_free += _heapinfo[block].busy.info.size * BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 /* Find the free cluster previous to this one in the free list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 Start searching at the last block referenced; this may benefit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 programs with locality of allocation. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 i = _heapindex;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 if (i > block)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 while (i > block)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 i = _heapinfo[i].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 i = _heapinfo[i].free.next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 while (i > 0 && i < block);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 i = _heapinfo[i].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 /* Determine how to link this block into the free list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 if (block == i + _heapinfo[i].free.size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 /* Coalesce this block with its predecessor. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 _heapinfo[i].free.size += _heapinfo[block].busy.info.size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 block = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 /* Really link this block back into the free list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 _heapinfo[block].free.size = _heapinfo[block].busy.info.size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 _heapinfo[block].free.next = _heapinfo[i].free.next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 _heapinfo[block].free.prev = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 _heapinfo[i].free.next = block;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 _heapinfo[_heapinfo[block].free.next].free.prev = block;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 ++_chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 /* Now that the block is linked in, see if we can coalesce it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 with its successor (by deleting its successor from the list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 and adding in its size). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 if (block + _heapinfo[block].free.size == _heapinfo[block].free.next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 _heapinfo[block].free.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 += _heapinfo[_heapinfo[block].free.next].free.size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 _heapinfo[block].free.next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 = _heapinfo[_heapinfo[block].free.next].free.next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 _heapinfo[_heapinfo[block].free.next].free.prev = block;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 --_chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 /* Now see if we can return stuff to the system. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 blocks = _heapinfo[block].free.size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 if (blocks >= FINAL_FREE_BLOCKS && block + blocks == _heaplimit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 && (*__morecore) (0) == ADDRESS (block + blocks))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 __malloc_size_t bytes = blocks * BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 _heaplimit -= blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (*__morecore) (-(int)bytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 _heapinfo[_heapinfo[block].free.prev].free.next
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 = _heapinfo[block].free.next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 _heapinfo[_heapinfo[block].free.next].free.prev
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 = _heapinfo[block].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 block = _heapinfo[block].free.prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 --_chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 _bytes_free -= bytes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 /* Set the next search to begin at this block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 _heapindex = block;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 /* Do some of the statistics. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 --_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 _bytes_used -= 1 << type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 ++_chunks_free;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 _bytes_free += 1 << type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 /* Get the address of the first free fragment in this block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 prev = (struct list *) ((char *) ADDRESS (block) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 (_heapinfo[block].busy.info.frag.first << type));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 if (_heapinfo[block].busy.info.frag.nfree == (BLOCKSIZE >> type) - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 /* If all fragments of this block are free, remove them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 from the fragment list and free the whole block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 next = prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 for (i = 1; i < (__malloc_size_t) (BLOCKSIZE >> type); ++i)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 next = next->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 prev->prev->next = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 if (next != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 next->prev = prev->prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 _heapinfo[block].busy.type = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 _heapinfo[block].busy.info.size = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 /* Keep the statistics accurate. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 ++_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 _bytes_used += BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 _chunks_free -= BLOCKSIZE >> type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 _bytes_free -= BLOCKSIZE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 free (ADDRESS (block));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 else if (_heapinfo[block].busy.info.frag.nfree != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 /* If some fragments of this block are free, link this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 fragment into the fragment list after the first free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 fragment of this block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 next = (struct list *) ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 next->next = prev->next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 next->prev = prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 prev->next = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 if (next->next != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 next->next->prev = next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 ++_heapinfo[block].busy.info.frag.nfree;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 /* No fragments of this block are free, so link this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 fragment into the fragment list and announce that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 it is the first free fragment of this block. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 prev = (struct list *) ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 _heapinfo[block].busy.info.frag.nfree = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 _heapinfo[block].busy.info.frag.first = (unsigned long int)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 ((unsigned long int) ((char *) ptr - (char *) NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 % BLOCKSIZE >> type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 prev->next = _fraghead[type].next;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 prev->prev = &_fraghead[type];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 prev->prev->next = prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 if (prev->next != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 prev->next->prev = prev;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 /* Return memory to the heap. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 __free_ret_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 free (__ptr_t ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 struct alignlist *l;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 if (ptr == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 if (PURE_DATA(ptr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 for (l = _aligned_blocks; l != NULL; l = l->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 if (l->aligned == ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 l->aligned = NULL; /* Mark the slot in the list as free. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 ptr = l->exact;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 if (__free_hook != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (*__free_hook) (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 _free_internal (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 /* Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 This file is part of the GNU C Library.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 The GNU C Library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 The GNU C Library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 #ifdef _LIBC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 #include <ansidecl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 #include <gnu-stabs.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 #undef cfree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 function_alias(cfree, free, void, (ptr),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 DEFUN(cfree, (ptr), PTR ptr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 void cfree (__ptr_t ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 cfree (__ptr_t ptr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 free (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 /* Change the size of a block allocated by `malloc'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 Copyright 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 Written May 1989 by Mike Haertel.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 This library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 This library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 The author may be reached (Email) at the address mike@ai.mit.edu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 #ifndef min
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 #define min(A, B) ((A) < (B) ? (A) : (B))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 /* Debugging hook for realloc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 __ptr_t (*__realloc_hook) __P ((__ptr_t __ptr, __malloc_size_t __size));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 /* Resize the given region to the new size, returning a pointer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 to the (possibly moved) region. This is optimized for speed;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 some benchmarks seem to indicate that greater compactness is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 achieved by unconditionally allocating and copying to a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 new region. This module has incestuous knowledge of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 internals of both free and malloc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 realloc (__ptr_t ptr, __malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 __ptr_t result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 int type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 __malloc_size_t block, blocks, oldlimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1039 if (PURE_DATA (ptr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 memcpy(result, ptr, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 else if (size == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 free (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 return malloc (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 else if (ptr == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 return malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 if (__realloc_hook != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 return (*__realloc_hook) (ptr, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 block = BLOCK (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 type = _heapinfo[block].busy.type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 /* Maybe reallocate a large block to a small fragment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 if (size <= BLOCKSIZE / 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 if (result != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 memcpy (result, ptr, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 _free_internal (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 /* The new size is a large allocation as well;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 see if we can hold it in place. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 blocks = BLOCKIFY (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 if (blocks < _heapinfo[block].busy.info.size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 /* The new size is smaller; return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 excess memory to the free list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 _heapinfo[block + blocks].busy.type = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 _heapinfo[block + blocks].busy.info.size
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 = _heapinfo[block].busy.info.size - blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 _heapinfo[block].busy.info.size = blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 /* We have just created a new chunk by splitting a chunk in two.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 Now we will free this chunk; increment the statistics counter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 so it doesn't become wrong when _free_internal decrements it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 ++_chunks_used;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 _free_internal (ADDRESS (block + blocks));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 result = ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 else if (blocks == _heapinfo[block].busy.info.size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 /* No size change necessary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 result = ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 /* Won't fit, so allocate a new region that will.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 Free the old region first in case there is sufficient
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 adjacent free space to grow without moving. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 blocks = _heapinfo[block].busy.info.size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 /* Prevent free from actually returning memory to the system. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 oldlimit = _heaplimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 _heaplimit = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105 free (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 _heaplimit = oldlimit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 /* Now we're really in trouble. We have to unfree
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 the thing we just freed. Unfortunately it might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 have been coalesced with its neighbors. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 if (_heapindex == block)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (void) malloc (blocks * BLOCKSIZE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 __ptr_t previous = malloc ((block - _heapindex) * BLOCKSIZE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 (void) malloc (blocks * BLOCKSIZE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 free (previous);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 if (ptr != result)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 memmove (result, ptr, blocks * BLOCKSIZE);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 /* Old size is a fragment; type is logarithm
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 to base two of the fragment size. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 if (size > (__malloc_size_t) (1 << (type - 1)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 size <= (__malloc_size_t) (1 << type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 /* The new size is the same kind of fragment. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 result = ptr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 /* The new size is different; allocate a new space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 and copy the lesser of the new size and the old. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 memcpy (result, ptr, min (size, (__malloc_size_t) 1 << type));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 free (ptr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 /* Copyright (C) 1991, 1992, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 This library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 This library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 Boston, MA 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 The author may be reached (Email) at the address mike@ai.mit.edu,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 or (US mail) as Mike Haertel c/o Free Software Foundation, Inc. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 /* Allocate an array of NMEMB elements each SIZE bytes long.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 The entire array is initialized to zeros. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 calloc (__malloc_size_t nmemb, __malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 __ptr_t result = malloc (nmemb * size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 if (result != NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (void) memset (result, 0, nmemb * size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 /* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 This file is part of the GNU C Library.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 The GNU C Library is free software; you can redistribute it and/or modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 it under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 The GNU C Library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 GNU General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 along with the GNU C Library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 the Free the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 /* #ifndef __GNU_LIBRARY__ */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 #define __sbrk sbrk
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 /* #endif */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 #ifdef GMALLOC_NEEDS_SBRK_DECL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 /* some versions of OSF1 need this */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 extern __ptr_t __sbrk __P ((ssize_t increment));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 #ifdef __GNU_LIBRARY__
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 /* It is best not to declare this and cast its result on foreign operating
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 systems with potentially hostile include files. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 #if !(defined(linux) && defined(sparc))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 extern __ptr_t __sbrk __P ((int increment));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 #ifndef NULL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 #define NULL 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 /* Allocate INCREMENT more bytes of data space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 and return the start of data space, or NULL on errors.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 If INCREMENT is negative, shrink data space. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 __ptr_t
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 442
diff changeset
1235 __default_morecore (ptrdiff_t increment)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 {
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 442
diff changeset
1237 __ptr_t result = (__ptr_t) __sbrk (increment);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 if (result == (__ptr_t) -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 /* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 This library is free software; you can redistribute it and/or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 modify it under the terms of the GNU Library General Public License as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 published by the Free Software Foundation; either version 2 of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 License, or (at your option) any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 This library is distributed in the hope that it will be useful,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 but WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 Library General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 along with this library; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 #ifndef _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 #define _MALLOC_INTERNAL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 #include <malloc.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 __ptr_t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 memalign (__malloc_size_t alignment, __malloc_size_t size)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 __ptr_t result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 unsigned long int adj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 size = ((size + alignment - 1) / alignment) * alignment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 result = malloc (size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 if (result == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 adj = (unsigned long int) ((unsigned long int) ((char *) result -
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 (char *) NULL)) % alignment;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 if (adj != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 struct alignlist *l;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 for (l = _aligned_blocks; l != NULL; l = l->next)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 if (l->aligned == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 /* This slot is free. Use it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 if (l == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 l = (struct alignlist *) malloc (sizeof (struct alignlist));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 if (l == NULL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 free (result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 l->next = _aligned_blocks;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 _aligned_blocks = l;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 l->exact = result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 result = l->aligned = (char *) result + alignment - adj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 }