annotate src/gmalloc.c @ 255:084402c475ba r20-5b26

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