New upstream version 2.3.4
This commit is contained in:
parent
e7bdd1c6c6
commit
de72f6f588
556 changed files with 90432 additions and 53391 deletions
77
gl/malloca.h
77
gl/malloca.h
|
@ -1,19 +1,19 @@
|
|||
/* Safe automatic memory allocation.
|
||||
Copyright (C) 2003-2007, 2009-2013 Free Software Foundation, Inc.
|
||||
Copyright (C) 2003-2007, 2009-2023 Free Software Foundation, Inc.
|
||||
Written by Bruno Haible <bruno@clisp.org>, 2003.
|
||||
|
||||
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 3, or (at your option)
|
||||
any later version.
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _MALLOCA_H
|
||||
#define _MALLOCA_H
|
||||
|
@ -21,6 +21,9 @@
|
|||
#include <alloca.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "xalloc-oversized.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -48,20 +51,6 @@ extern "C" {
|
|||
# define safe_alloca(N) ((void) (N), NULL)
|
||||
#endif
|
||||
|
||||
/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
|
||||
memory allocated on the stack, that must be freed using freea() before
|
||||
the function returns. Upon failure, it returns NULL. */
|
||||
#if HAVE_ALLOCA
|
||||
# define malloca(N) \
|
||||
((N) < 4032 - sa_increment \
|
||||
? (void *) ((char *) alloca ((N) + sa_increment) + sa_increment) \
|
||||
: mmalloca (N))
|
||||
#else
|
||||
# define malloca(N) \
|
||||
mmalloca (N)
|
||||
#endif
|
||||
extern void * mmalloca (size_t n);
|
||||
|
||||
/* Free a block of memory allocated through malloca(). */
|
||||
#if HAVE_ALLOCA
|
||||
extern void freea (void *p);
|
||||
|
@ -69,19 +58,30 @@ extern void freea (void *p);
|
|||
# define freea free
|
||||
#endif
|
||||
|
||||
/* malloca(N) is a safe variant of alloca(N). It allocates N bytes of
|
||||
memory allocated on the stack, that must be freed using freea() before
|
||||
the function returns. Upon failure, it returns NULL. */
|
||||
#if HAVE_ALLOCA
|
||||
# define malloca(N) \
|
||||
((N) < 4032 - (2 * sa_alignment_max - 1) \
|
||||
? (void *) (((uintptr_t) (char *) alloca ((N) + 2 * sa_alignment_max - 1) \
|
||||
+ (2 * sa_alignment_max - 1)) \
|
||||
& ~(uintptr_t)(2 * sa_alignment_max - 1)) \
|
||||
: mmalloca (N))
|
||||
#else
|
||||
# define malloca(N) \
|
||||
mmalloca (N)
|
||||
#endif
|
||||
extern void *mmalloca (size_t n)
|
||||
_GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC (freea, 1)
|
||||
_GL_ATTRIBUTE_ALLOC_SIZE ((1));
|
||||
|
||||
/* nmalloca(N,S) is an overflow-safe variant of malloca (N * S).
|
||||
It allocates an array of N objects, each with S bytes of memory,
|
||||
on the stack. S must be positive and N must be nonnegative.
|
||||
on the stack. N and S should be nonnegative and free of side effects.
|
||||
The array must be freed using freea() before the function returns. */
|
||||
#if 1
|
||||
/* Cf. the definition of xalloc_oversized. */
|
||||
# define nmalloca(n, s) \
|
||||
((n) > (size_t) (sizeof (ptrdiff_t) <= sizeof (size_t) ? -1 : -2) / (s) \
|
||||
? NULL \
|
||||
: malloca ((n) * (s)))
|
||||
#else
|
||||
extern void * nmalloca (size_t n, size_t s);
|
||||
#endif
|
||||
#define nmalloca(n, s) \
|
||||
(xalloc_oversized (n, s) ? NULL : malloca ((n) * (size_t) (s)))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -92,7 +92,7 @@ extern void * nmalloca (size_t n, size_t s);
|
|||
/* ------------------- Auxiliary, non-public definitions ------------------- */
|
||||
|
||||
/* Determine the alignment of a type at compile time. */
|
||||
#if defined __GNUC__ || defined __IBM__ALIGNOF__
|
||||
#if defined __GNUC__ || defined __clang__ || defined __IBM__ALIGNOF__
|
||||
# define sa_alignof __alignof__
|
||||
#elif defined __cplusplus
|
||||
template <class type> struct sa_alignof_helper { char __slot1; type __slot2; };
|
||||
|
@ -115,19 +115,12 @@ enum
|
|||
among all elementary types. */
|
||||
sa_alignment_long = sa_alignof (long),
|
||||
sa_alignment_double = sa_alignof (double),
|
||||
#if HAVE_LONG_LONG_INT
|
||||
sa_alignment_longlong = sa_alignof (long long),
|
||||
#endif
|
||||
sa_alignment_longdouble = sa_alignof (long double),
|
||||
sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1)
|
||||
#if HAVE_LONG_LONG_INT
|
||||
| (sa_alignment_longlong - 1)
|
||||
#endif
|
||||
| (sa_alignment_longdouble - 1)
|
||||
) + 1,
|
||||
/* The increment that guarantees room for a magic word must be >= sizeof (int)
|
||||
and a multiple of sa_alignment_max. */
|
||||
sa_increment = ((sizeof (int) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max
|
||||
) + 1
|
||||
};
|
||||
|
||||
#endif /* _MALLOCA_H */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue