summaryrefslogtreecommitdiffstats
path: root/gl/xalloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'gl/xalloc.h')
-rw-r--r--gl/xalloc.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/gl/xalloc.h b/gl/xalloc.h
index 40dcf4b..57a13e0 100644
--- a/gl/xalloc.h
+++ b/gl/xalloc.h
@@ -37,6 +37,14 @@ extern "C" {
37# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 37# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
38# endif 38# endif
39 39
40# ifndef ATTRIBUTE_MALLOC
41# if __GNUC__ >= 3
42# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
43# else
44# define ATTRIBUTE_MALLOC
45# endif
46# endif
47
40/* This function is always triggered when memory is exhausted. 48/* This function is always triggered when memory is exhausted.
41 It must be defined by the application, either explicitly 49 It must be defined by the application, either explicitly
42 or by using gnulib's xalloc-die module. This is the 50 or by using gnulib's xalloc-die module. This is the
@@ -44,13 +52,13 @@ extern "C" {
44 memory allocation failure. */ 52 memory allocation failure. */
45extern void xalloc_die (void) ATTRIBUTE_NORETURN; 53extern void xalloc_die (void) ATTRIBUTE_NORETURN;
46 54
47void *xmalloc (size_t s); 55void *xmalloc (size_t s) ATTRIBUTE_MALLOC;
48void *xzalloc (size_t s); 56void *xzalloc (size_t s) ATTRIBUTE_MALLOC;
49void *xcalloc (size_t n, size_t s); 57void *xcalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
50void *xrealloc (void *p, size_t s); 58void *xrealloc (void *p, size_t s);
51void *x2realloc (void *p, size_t *pn); 59void *x2realloc (void *p, size_t *pn);
52void *xmemdup (void const *p, size_t s); 60void *xmemdup (void const *p, size_t s) ATTRIBUTE_MALLOC;
53char *xstrdup (char const *str); 61char *xstrdup (char const *str) ATTRIBUTE_MALLOC;
54 62
55/* Return 1 if an array of N objects, each of size S, cannot exist due 63/* Return 1 if an array of N objects, each of size S, cannot exist due
56 to size arithmetic overflow. S must be positive and N must be 64 to size arithmetic overflow. S must be positive and N must be
@@ -97,10 +105,10 @@ char *xstrdup (char const *str);
97# if HAVE_INLINE 105# if HAVE_INLINE
98# define static_inline static inline 106# define static_inline static inline
99# else 107# else
100 void *xnmalloc (size_t n, size_t s); 108 void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
101 void *xnrealloc (void *p, size_t n, size_t s); 109 void *xnrealloc (void *p, size_t n, size_t s);
102 void *x2nrealloc (void *p, size_t *pn, size_t s); 110 void *x2nrealloc (void *p, size_t *pn, size_t s);
103 char *xcharalloc (size_t n); 111 char *xcharalloc (size_t n) ATTRIBUTE_MALLOC;
104# endif 112# endif
105 113
106# ifdef static_inline 114# ifdef static_inline
@@ -108,6 +116,7 @@ char *xstrdup (char const *str);
108/* Allocate an array of N objects, each with S bytes of memory, 116/* Allocate an array of N objects, each with S bytes of memory,
109 dynamically, with error checking. S must be nonzero. */ 117 dynamically, with error checking. S must be nonzero. */
110 118
119static_inline void *xnmalloc (size_t n, size_t s) ATTRIBUTE_MALLOC;
111static_inline void * 120static_inline void *
112xnmalloc (size_t n, size_t s) 121xnmalloc (size_t n, size_t s)
113{ 122{
@@ -219,6 +228,7 @@ x2nrealloc (void *p, size_t *pn, size_t s)
219/* Return a pointer to a new buffer of N bytes. This is like xmalloc, 228/* Return a pointer to a new buffer of N bytes. This is like xmalloc,
220 except it returns char *. */ 229 except it returns char *. */
221 230
231static_inline char *xcharalloc (size_t n) ATTRIBUTE_MALLOC;
222static_inline char * 232static_inline char *
223xcharalloc (size_t n) 233xcharalloc (size_t n)
224{ 234{