diff options
author | Bruno Haible <bruno@clisp.org> | 2020-10-20 01:12:51 +0200 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2020-10-20 01:12:51 +0200 |
commit | 52ab50a7ebc469b542bca0063430db71aefb67af (patch) | |
tree | cd22a670246910ea7ff8f7aa1a021d0bfcd8f8fa /lib/xalloc.h | |
parent | 2d386f229aba9ecda85736b931e2964d7922d90e (diff) | |
download | gnulib-52ab50a7ebc469b542bca0063430db71aefb67af.tar.gz |
xalloc-die: Fix link error with Solaris cc (regression 2020-07-27).
* lib/xalloc.h (xalloc_die): Don't declare if GNULIB_XALLOC_DIE is 0.
(xmalloc, xzalloc, xcalloc, xrealloc, x2realloc, xmemdup, xstrdup,
XMALLOC, XNMALLOC, XZALLOC, XCALLOC, xnmalloc, xnrealloc, x2nrealloc,
xcharalloc): Don't declare/define if GNULIB_XALLOC is 0.
* modules/xalloc (configure.ac): Define GNULIB_XALLOC.
* modules/xalloc-die (configure.ac): Define GNULIB_XALLOC_DIE.
Diffstat (limited to 'lib/xalloc.h')
-rw-r--r-- | lib/xalloc.h | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/xalloc.h b/lib/xalloc.h index 24273ffbe3..d4f96bfe0f 100644 --- a/lib/xalloc.h +++ b/lib/xalloc.h @@ -31,11 +31,14 @@ _GL_INLINE_HEADER_BEGIN # define XALLOC_INLINE _GL_INLINE #endif + #ifdef __cplusplus extern "C" { #endif +#if GNULIB_XALLOC_DIE + /* This function is always triggered when memory is exhausted. It must be defined by the application, either explicitly or by using gnulib's xalloc-die module. This is the @@ -43,6 +46,10 @@ extern "C" { memory allocation failure. */ /*extern*/ _Noreturn void xalloc_die (void); +#endif /* GNULIB_XALLOC_DIE */ + +#if GNULIB_XALLOC + void *xmalloc (size_t s) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1)); void *xzalloc (size_t s) @@ -64,23 +71,23 @@ char *xstrdup (char const *str) /* Allocate an object of type T dynamically, with error checking. */ /* extern t *XMALLOC (typename t); */ -#define XMALLOC(t) ((t *) xmalloc (sizeof (t))) +# define XMALLOC(t) ((t *) xmalloc (sizeof (t))) /* Allocate memory for N elements of type T, with error checking. */ /* extern t *XNMALLOC (size_t n, typename t); */ -#define XNMALLOC(n, t) \ - ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) +# define XNMALLOC(n, t) \ + ((t *) (sizeof (t) == 1 ? xmalloc (n) : xnmalloc (n, sizeof (t)))) /* Allocate an object of type T dynamically, with error checking, and zero it. */ /* extern t *XZALLOC (typename t); */ -#define XZALLOC(t) ((t *) xzalloc (sizeof (t))) +# define XZALLOC(t) ((t *) xzalloc (sizeof (t))) /* Allocate memory for N elements of type T, with error checking, and zero it. */ /* extern t *XCALLOC (size_t n, typename t); */ -#define XCALLOC(n, t) \ - ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) +# define XCALLOC(n, t) \ + ((t *) (sizeof (t) == 1 ? xzalloc (n) : xcalloc (n, sizeof (t)))) /* Allocate an array of N objects, each with S bytes of memory, @@ -211,8 +218,15 @@ xcharalloc (size_t n) return XNMALLOC (n, char); } +#endif /* GNULIB_XALLOC */ + + #ifdef __cplusplus } +#endif + + +#if GNULIB_XALLOC && defined __cplusplus /* C++ does not allow conversions from void * to other pointer types without a cast. Use templates to work around the problem when @@ -248,7 +262,8 @@ xmemdup (T const *p, size_t s) return (T *) xmemdup ((void const *) p, s); } -#endif +#endif /* GNULIB_XALLOC && C++ */ + _GL_INLINE_HEADER_END |