Skip to content

Commit fe692dd

Browse files
committed
cdefs: Add a bunch more attribute defines
Allows the use of a handful of glibc-like attributes Signed-off-by: Keith Packard <[email protected]>
1 parent d779985 commit fe692dd

File tree

1 file changed

+46
-5
lines changed

1 file changed

+46
-5
lines changed

newlib/libc/include/sys/cdefs.h

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@
5959
#define __ptr_t void *
6060
#define __long_double_t long double
6161

62-
#define __attribute_malloc__
63-
#define __attribute_pure__
64-
#define __attribute_format_strfmon__(a,b)
65-
#define __flexarr [0]
66-
6762
#ifndef __BOUNDED_POINTERS__
6863
# define __bounded /* nothing */
6964
# define __unbounded /* nothing */
@@ -89,6 +84,51 @@
8984
#define __has_builtin(x) 0
9085
#endif
9186

87+
#if __has_attribute(__pure__)
88+
# define __attribute_pure__ __attribute__((__pure__))
89+
#else
90+
# define __attribute_pure__
91+
#endif
92+
93+
#if __has_attribute(__format__)
94+
# define __attribute_format_strfmon__(a,b) \
95+
__attribute__((__format__(__strfmon__, a, b)))
96+
#else
97+
# define __attribute_format_strfmon__(a,b)
98+
#endif
99+
100+
#if __has_attribute(__nonnull__)
101+
# define __attribute_nonnull__(params) __attribute__((__nonnull__ params))
102+
#else
103+
# define __attribute_nonnull__(params)
104+
#endif
105+
106+
#if __has_attribute(__returns_nonnull__)
107+
# define __returns_nonnull __attribute__((__returns_nonnull__))
108+
#else
109+
# define __returns_nonnull
110+
#endif
111+
112+
#if __has_attribute (__malloc__)
113+
# define __attribute_malloc__ __attribute__ ((__malloc__))
114+
#else
115+
# define __attribute_malloc__
116+
#endif
117+
118+
#if __has_attribute(__alloc_size__)
119+
# define __attribute_alloc_size__(params) __attribute__ ((__alloc_size__ params))
120+
#else
121+
# define __attribute_alloc_size__(params)
122+
#endif
123+
124+
#if __has_attribute (__alloc_align__)
125+
# define __attribute_alloc_align__(param) __attribute__ ((__alloc_align__ param))
126+
#else
127+
# define __attribute_alloc_align__(param)
128+
#endif
129+
130+
#define __flexarr []
131+
92132
#if defined(__cplusplus)
93133
#define __BEGIN_DECLS extern "C" {
94134
#define __END_DECLS }
@@ -402,6 +442,7 @@
402442
#endif
403443

404444
#define __malloc_like __malloc_like_with_free(free, 1)
445+
#define __attr_dealloc_free __malloc_like_with_free(__builtin_free, 1)
405446

406447
#ifndef __always_inline
407448
#if __GNUC_PREREQ__(3, 1)

0 commit comments

Comments
 (0)