summaryrefslogtreecommitdiff
path: root/lib/xalloc.h
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2008-05-15 02:01:46 +0200
committerBruno Haible <bruno@clisp.org>2008-05-15 02:01:46 +0200
commitf64a5d6252a22e5ec3c050f9f49b4d591ec82e78 (patch)
tree1c095909126a1d880a3c319ffd3890a949ae1968 /lib/xalloc.h
parent780af14c0e3cdd1542f95ad7af8839a19f6de7ef (diff)
downloadgnulib-f64a5d6252a22e5ec3c050f9f49b4d591ec82e78.tar.gz
Help GCC to do better code generation.
Diffstat (limited to 'lib/xalloc.h')
-rw-r--r--lib/xalloc.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/lib/xalloc.h b/lib/xalloc.h
index 40dcf4bd54..0f6879f012 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -37,6 +37,14 @@ extern "C" {
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
# endif
+# ifndef ATTRIBUTE_MALLOC
+# if __GNUC__ >= 3
+# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
+# else
+# define ATTRIBUTE_MALLOC
+# endif
+# endif
+
/* 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
@@ -44,13 +52,13 @@ extern "C" {
memory allocation failure. */
extern void xalloc_die (void) ATTRIBUTE_NORETURN;
-void *xmalloc (size_t s);
-void *xzalloc (size_t s);
-void *xcalloc (size_t n, size_t s);
+void *xmalloc (size_t s) ATTRIBUTE_MALLOC;
+void *xzalloc (size_t s) ATTRIBUTE_MALLOC;
+void *xcalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
void *xrealloc (void *p, size_t s);
void *x2realloc (void *p, size_t *pn);
-void *xmemdup (void const *p, size_t s);
-char *xstrdup (char const *str);
+void *xmemdup (void const *p, size_t s) ATTRIBUTE_MALLOC;
+char *xstrdup (char const *str) ATTRIBUTE_MALLOC;
/* Return 1 if an array of N objects, each of size S, cannot exist due
to size arithmetic overflow. S must be positive and N must be
@@ -97,10 +105,10 @@ char *xstrdup (char const *str);
# if HAVE_INLINE
# define static_inline static inline
# else
- void *xnmalloc (size_t n, size_t s);
+ void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
void *xnrealloc (void *p, size_t n, size_t s);
void *x2nrealloc (void *p, size_t *pn, size_t s);
- char *xcharalloc (size_t n);
+ char *xcharalloc (size_t n) ATTRIBUTE_MALLOC;;
# endif
# ifdef static_inline
@@ -108,6 +116,7 @@ char *xstrdup (char const *str);
/* Allocate an array of N objects, each with S bytes of memory,
dynamically, with error checking. S must be nonzero. */
+static_inline void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
static_inline void *
xnmalloc (size_t n, size_t s)
{
@@ -219,6 +228,7 @@ x2nrealloc (void *p, size_t *pn, size_t s)
/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
except it returns char *. */
+static_inline char *xcharalloc (size_t n) ATTRIBUTE_MALLOC;
static_inline char *
xcharalloc (size_t n)
{