Imported Upstream version 1.4.12
This commit is contained in:
parent
1d1585cd09
commit
4ab9f0d24c
291 changed files with 27277 additions and 11364 deletions
29
gl/xalloc.h
29
gl/xalloc.h
|
@ -1,12 +1,12 @@
|
|||
/* xalloc.h -- malloc with out-of-memory checking
|
||||
|
||||
Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
|
||||
1999, 2000, 2003, 2004, 2006 Free Software Foundation, Inc.
|
||||
1999, 2000, 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
|
@ -14,8 +14,7 @@
|
|||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef XALLOC_H_
|
||||
# define XALLOC_H_
|
||||
|
@ -29,7 +28,7 @@ extern "C" {
|
|||
|
||||
|
||||
# ifndef __attribute__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
|
||||
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
|
||||
# define __attribute__(x)
|
||||
# endif
|
||||
# endif
|
||||
|
@ -139,10 +138,10 @@ xnrealloc (void *p, size_t n, size_t s)
|
|||
allocating an initial block with a nonzero size, or by allocating a
|
||||
larger block.
|
||||
|
||||
In the following implementation, nonzero sizes are doubled so that
|
||||
repeated reallocations have O(N log N) overall cost rather than
|
||||
O(N**2) cost, but the specification for this function does not
|
||||
guarantee that sizes are doubled.
|
||||
In the following implementation, nonzero sizes are increased by a
|
||||
factor of approximately 1.5 so that repeated reallocations have
|
||||
O(N) overall cost rather than O(N**2) cost, but the
|
||||
specification for this function does not guarantee that rate.
|
||||
|
||||
Here is an example of use:
|
||||
|
||||
|
@ -204,9 +203,13 @@ x2nrealloc (void *p, size_t *pn, size_t s)
|
|||
}
|
||||
else
|
||||
{
|
||||
if (((size_t) -1) / 2 / s < n)
|
||||
/* Set N = ceil (1.5 * N) so that progress is made if N == 1.
|
||||
Check for overflow, so that N * S stays in size_t range.
|
||||
The check is slightly conservative, but an exact check isn't
|
||||
worth the trouble. */
|
||||
if ((size_t) -1 / 3 * 2 / s <= n)
|
||||
xalloc_die ();
|
||||
n *= 2;
|
||||
n += (n + 1) / 2;
|
||||
}
|
||||
|
||||
*pn = n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue