diff options
Diffstat (limited to 'gl/xalloc.h')
-rw-r--r-- | gl/xalloc.h | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/gl/xalloc.h b/gl/xalloc.h index 57a13e0..6122cc5 100644 --- a/gl/xalloc.h +++ b/gl/xalloc.h | |||
@@ -1,7 +1,8 @@ | |||
1 | /* xalloc.h -- malloc with out-of-memory checking | 1 | /* xalloc.h -- malloc with out-of-memory checking |
2 | 2 | ||
3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, | 3 | Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
4 | 1999, 2000, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. | 4 | 2000, 2003, 2004, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, |
5 | Inc. | ||
5 | 6 | ||
6 | This program is free software: you can redistribute it and/or modify | 7 | This program is free software: you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | 8 | it under the terms of the GNU General Public License as published by |
@@ -105,10 +106,10 @@ char *xstrdup (char const *str) ATTRIBUTE_MALLOC; | |||
105 | # if HAVE_INLINE | 106 | # if HAVE_INLINE |
106 | # define static_inline static inline | 107 | # define static_inline static inline |
107 | # else | 108 | # else |
108 | void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC; | 109 | void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC; |
109 | void *xnrealloc (void *p, size_t n, size_t s); | 110 | void *xnrealloc (void *p, size_t n, size_t s); |
110 | void *x2nrealloc (void *p, size_t *pn, size_t s); | 111 | void *x2nrealloc (void *p, size_t *pn, size_t s); |
111 | char *xcharalloc (size_t n) ATTRIBUTE_MALLOC; | 112 | char *xcharalloc (size_t n) ATTRIBUTE_MALLOC; |
112 | # endif | 113 | # endif |
113 | 114 | ||
114 | # ifdef static_inline | 115 | # ifdef static_inline |
@@ -161,9 +162,9 @@ xnrealloc (void *p, size_t n, size_t s) | |||
161 | void | 162 | void |
162 | append_int (int value) | 163 | append_int (int value) |
163 | { | 164 | { |
164 | if (used == allocated) | 165 | if (used == allocated) |
165 | p = x2nrealloc (p, &allocated, sizeof *p); | 166 | p = x2nrealloc (p, &allocated, sizeof *p); |
166 | p[used++] = value; | 167 | p[used++] = value; |
167 | } | 168 | } |
168 | 169 | ||
169 | This causes x2nrealloc to allocate a block of some nonzero size the | 170 | This causes x2nrealloc to allocate a block of some nonzero size the |
@@ -181,12 +182,12 @@ xnrealloc (void *p, size_t n, size_t s) | |||
181 | void | 182 | void |
182 | append_int (int value) | 183 | append_int (int value) |
183 | { | 184 | { |
184 | if (used == allocated) | 185 | if (used == allocated) |
185 | { | 186 | { |
186 | p = x2nrealloc (p, &allocated1, sizeof *p); | 187 | p = x2nrealloc (p, &allocated1, sizeof *p); |
187 | allocated = allocated1; | 188 | allocated = allocated1; |
188 | } | 189 | } |
189 | p[used++] = value; | 190 | p[used++] = value; |
190 | } | 191 | } |
191 | 192 | ||
192 | */ | 193 | */ |
@@ -199,25 +200,25 @@ x2nrealloc (void *p, size_t *pn, size_t s) | |||
199 | if (! p) | 200 | if (! p) |
200 | { | 201 | { |
201 | if (! n) | 202 | if (! n) |
202 | { | 203 | { |
203 | /* The approximate size to use for initial small allocation | 204 | /* The approximate size to use for initial small allocation |
204 | requests, when the invoking code specifies an old size of | 205 | requests, when the invoking code specifies an old size of |
205 | zero. 64 bytes is the largest "small" request for the | 206 | zero. 64 bytes is the largest "small" request for the |
206 | GNU C library malloc. */ | 207 | GNU C library malloc. */ |
207 | enum { DEFAULT_MXFAST = 64 }; | 208 | enum { DEFAULT_MXFAST = 64 }; |
208 | 209 | ||
209 | n = DEFAULT_MXFAST / s; | 210 | n = DEFAULT_MXFAST / s; |
210 | n += !n; | 211 | n += !n; |
211 | } | 212 | } |
212 | } | 213 | } |
213 | else | 214 | else |
214 | { | 215 | { |
215 | /* Set N = ceil (1.5 * N) so that progress is made if N == 1. | 216 | /* Set N = ceil (1.5 * N) so that progress is made if N == 1. |
216 | Check for overflow, so that N * S stays in size_t range. | 217 | Check for overflow, so that N * S stays in size_t range. |
217 | The check is slightly conservative, but an exact check isn't | 218 | The check is slightly conservative, but an exact check isn't |
218 | worth the trouble. */ | 219 | worth the trouble. */ |
219 | if ((size_t) -1 / 3 * 2 / s <= n) | 220 | if ((size_t) -1 / 3 * 2 / s <= n) |
220 | xalloc_die (); | 221 | xalloc_die (); |
221 | n += (n + 1) / 2; | 222 | n += (n + 1) / 2; |
222 | } | 223 | } |
223 | 224 | ||