comparison lib/xalloc.h @ 14351:724011432f7b

Consistent macro naming for macros that use GCC __attribute__. * lib/di-set.h (_GL_ATTRIBUTE_NONNULL): Renamed from _ATTRIBUTE_NONNULL_. * lib/ino-map.h (_GL_ATTRIBUTE_NONNULL): Likewise. * lib/hash.h (_GL_ATTRIBUTE_WUR): Renamed from ATTRIBUTE_WUR. * lib/ignore-value.h (_GL_ATTRIBUTE_DEPRECATED): Renamed from ATTRIBUTE_DEPRECATED. * lib/openat.h (_GL_ATTRIBUTE_NORETURN): Renamed from ATTRIBUTE_NORETURN. * lib/sigpipe-die.h (_GL_ATTRIBUTE_NORETURN): Likewise. * lib/xmemdup0.h (_GL_ATTRIBUTE_NORETURN): Likewise. * lib/xstrtol.h (_GL_ATTRIBUTE_NORETURN): Likewise. * lib/xalloc.h (_GL_ATTRIBUTE_NORETURN): Likewise. (_GL_ATTRIBUTE_MALLOC): Renamed from ATTRIBUTE_MALLOC. (_GL_ATTRIBUTE_ALLOC_SIZE): Renamed from ATTRIBUTE_ALLOC_SIZE. * lib/version-etc.h (_GL_ATTRIBUTE_SENTINEL): Renamed from ATTRIBUTE_SENTINEL. * lib/safe-alloc.h (_GL_ATTRIBUTE_RETURN_CHECK): Renamed from ATTRIBUTE_RETURN_CHECK. * tests/test-ignore-value.c (_GL_ATTRIBUTE_RETURN_CHECK): Likewise. * tests/test-argmatch.c (_GL_ATTRIBUTE_NORETURN): Renamed from ATTRIBUTE_NORETURN. * tests/test-exclude.c (_GL_ATTRIBUTE_NORETURN): Likewise. Reported by Paul Eggert.
author Bruno Haible <bruno@clisp.org>
date Sun, 13 Feb 2011 23:44:28 +0100
parents 4cf3b58aaf12
children b3b2f9e830e9
comparison
equal deleted inserted replaced
14350:4cf3b58aaf12 14351:724011432f7b
25 extern "C" { 25 extern "C" {
26 # endif 26 # endif
27 27
28 28
29 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8) 29 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
30 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 30 # define _GL_ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
31 # else 31 # else
32 # define ATTRIBUTE_NORETURN /* empty */ 32 # define _GL_ATTRIBUTE_NORETURN /* empty */
33 # endif 33 # endif
34 34
35 # if __GNUC__ >= 3 35 # if __GNUC__ >= 3
36 # define ATTRIBUTE_MALLOC __attribute__ ((__malloc__)) 36 # define _GL_ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
37 # else 37 # else
38 # define ATTRIBUTE_MALLOC 38 # define _GL_ATTRIBUTE_MALLOC
39 # endif 39 # endif
40 40
41 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) 41 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
42 # define ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args)) 42 # define _GL_ATTRIBUTE_ALLOC_SIZE(args) __attribute__ ((__alloc_size__ args))
43 # else 43 # else
44 # define ATTRIBUTE_ALLOC_SIZE(args) 44 # define _GL_ATTRIBUTE_ALLOC_SIZE(args)
45 # endif 45 # endif
46 46
47 /* This function is always triggered when memory is exhausted. 47 /* This function is always triggered when memory is exhausted.
48 It must be defined by the application, either explicitly 48 It must be defined by the application, either explicitly
49 or by using gnulib's xalloc-die module. This is the 49 or by using gnulib's xalloc-die module. This is the
50 function to call when one wants the program to die because of a 50 function to call when one wants the program to die because of a
51 memory allocation failure. */ 51 memory allocation failure. */
52 extern void xalloc_die (void) ATTRIBUTE_NORETURN; 52 extern void xalloc_die (void) _GL_ATTRIBUTE_NORETURN;
53 53
54 void *xmalloc (size_t s) 54 void *xmalloc (size_t s)
55 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((1)); 55 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
56 void *xzalloc (size_t s) 56 void *xzalloc (size_t s)
57 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((1)); 57 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
58 void *xcalloc (size_t n, size_t s) 58 void *xcalloc (size_t n, size_t s)
59 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((1, 2)); 59 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
60 void *xrealloc (void *p, size_t s) 60 void *xrealloc (void *p, size_t s)
61 ATTRIBUTE_ALLOC_SIZE ((2)); 61 _GL_ATTRIBUTE_ALLOC_SIZE ((2));
62 void *x2realloc (void *p, size_t *pn); 62 void *x2realloc (void *p, size_t *pn);
63 void *xmemdup (void const *p, size_t s) 63 void *xmemdup (void const *p, size_t s)
64 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((2)); 64 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((2));
65 char *xstrdup (char const *str) 65 char *xstrdup (char const *str)
66 ATTRIBUTE_MALLOC; 66 _GL_ATTRIBUTE_MALLOC;
67 67
68 /* Return 1 if an array of N objects, each of size S, cannot exist due 68 /* Return 1 if an array of N objects, each of size S, cannot exist due
69 to size arithmetic overflow. S must be positive and N must be 69 to size arithmetic overflow. S must be positive and N must be
70 nonnegative. This is a macro, not an inline function, so that it 70 nonnegative. This is a macro, not an inline function, so that it
71 works correctly even when SIZE_MAX < N. 71 works correctly even when SIZE_MAX < N.
109 109
110 # if HAVE_INLINE 110 # if HAVE_INLINE
111 # define static_inline static inline 111 # define static_inline static inline
112 # else 112 # else
113 void *xnmalloc (size_t n, size_t s) 113 void *xnmalloc (size_t n, size_t s)
114 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((1, 2)); 114 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
115 void *xnrealloc (void *p, size_t n, size_t s) 115 void *xnrealloc (void *p, size_t n, size_t s)
116 ATTRIBUTE_ALLOC_SIZE ((2, 3)); 116 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
117 void *x2nrealloc (void *p, size_t *pn, size_t s); 117 void *x2nrealloc (void *p, size_t *pn, size_t s);
118 char *xcharalloc (size_t n) 118 char *xcharalloc (size_t n)
119 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((1)); 119 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
120 # endif 120 # endif
121 121
122 # ifdef static_inline 122 # ifdef static_inline
123 123
124 /* Allocate an array of N objects, each with S bytes of memory, 124 /* Allocate an array of N objects, each with S bytes of memory,
125 dynamically, with error checking. S must be nonzero. */ 125 dynamically, with error checking. S must be nonzero. */
126 126
127 static_inline void *xnmalloc (size_t n, size_t s) 127 static_inline void *xnmalloc (size_t n, size_t s)
128 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((1, 2)); 128 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1, 2));
129 static_inline void * 129 static_inline void *
130 xnmalloc (size_t n, size_t s) 130 xnmalloc (size_t n, size_t s)
131 { 131 {
132 if (xalloc_oversized (n, s)) 132 if (xalloc_oversized (n, s))
133 xalloc_die (); 133 xalloc_die ();
136 136
137 /* Change the size of an allocated block of memory P to an array of N 137 /* Change the size of an allocated block of memory P to an array of N
138 objects each of S bytes, with error checking. S must be nonzero. */ 138 objects each of S bytes, with error checking. S must be nonzero. */
139 139
140 static_inline void *xnrealloc (void *p, size_t n, size_t s) 140 static_inline void *xnrealloc (void *p, size_t n, size_t s)
141 ATTRIBUTE_ALLOC_SIZE ((2, 3)); 141 _GL_ATTRIBUTE_ALLOC_SIZE ((2, 3));
142 static_inline void * 142 static_inline void *
143 xnrealloc (void *p, size_t n, size_t s) 143 xnrealloc (void *p, size_t n, size_t s)
144 { 144 {
145 if (xalloc_oversized (n, s)) 145 if (xalloc_oversized (n, s))
146 xalloc_die (); 146 xalloc_die ();
238 238
239 /* Return a pointer to a new buffer of N bytes. This is like xmalloc, 239 /* Return a pointer to a new buffer of N bytes. This is like xmalloc,
240 except it returns char *. */ 240 except it returns char *. */
241 241
242 static_inline char *xcharalloc (size_t n) 242 static_inline char *xcharalloc (size_t n)
243 ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE ((1)); 243 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_ALLOC_SIZE ((1));
244 static_inline char * 244 static_inline char *
245 xcharalloc (size_t n) 245 xcharalloc (size_t n)
246 { 246 {
247 return XNMALLOC (n, char); 247 return XNMALLOC (n, char);
248 } 248 }