summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog10
-rw-r--r--lib/xalloc.h29
-rw-r--r--modules/xalloc1
-rw-r--r--modules/xalloc-die1
4 files changed, 34 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 4903d51e9e..e0e2a30b41 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2020-10-19 Bruno Haible <bruno@clisp.org>
+
+ 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.
+
2020-10-18 Bruno Haible <bruno@clisp.org>
ssfmalloc: Add tests.
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
diff --git a/modules/xalloc b/modules/xalloc
index c6e3cfd9de..65007561b5 100644
--- a/modules/xalloc
+++ b/modules/xalloc
@@ -15,6 +15,7 @@ xalloc-oversized
configure.ac:
gl_XALLOC
+gl_MODULE_INDICATOR([xalloc])
Makefile.am:
lib_SOURCES += xmalloc.c
diff --git a/modules/xalloc-die b/modules/xalloc-die
index 23ade89e70..f53de5a5ac 100644
--- a/modules/xalloc-die
+++ b/modules/xalloc-die
@@ -14,6 +14,7 @@ stdint
xalloc-oversized
configure.ac:
+gl_MODULE_INDICATOR([xalloc-die])
Makefile.am:
lib_SOURCES += xalloc-die.c