NEWS: Fix spelling mistake: "%ob" -> "%Ob".
[glibc.git] / include / alloca.h
blobfd90664f0a17cd6df5f1d82eaa79c89c24f35b25
1 #ifndef _ALLOCA_H
3 #include <stdlib/alloca.h>
5 # ifndef _ISOMAC
7 #include <stackinfo.h>
9 #undef __alloca
11 /* Now define the internal interfaces. */
12 extern void *__alloca (size_t __size);
14 #ifdef __GNUC__
15 # define __alloca(size) __builtin_alloca (size)
16 #endif /* GCC. */
18 extern int __libc_use_alloca (size_t size) __attribute__ ((const));
19 extern int __libc_alloca_cutoff (size_t size) __attribute__ ((const));
20 libc_hidden_proto (__libc_alloca_cutoff)
22 #define __MAX_ALLOCA_CUTOFF 65536
24 #include <allocalim.h>
26 #ifndef stackinfo_alloca_round
27 # define stackinfo_alloca_round(l) (((l) + 15) & -16)
28 #endif
30 #if _STACK_GROWS_DOWN
31 # define extend_alloca(buf, len, newlen) \
32 (__typeof (buf)) ({ size_t __newlen = stackinfo_alloca_round (newlen); \
33 char *__newbuf = __alloca (__newlen); \
34 if (__newbuf + __newlen == (char *) (buf)) \
35 len += __newlen; \
36 else \
37 len = __newlen; \
38 __newbuf; })
39 #elif _STACK_GROWS_UP
40 # define extend_alloca(buf, len, newlen) \
41 (__typeof (buf)) ({ size_t __newlen = stackinfo_alloca_round (newlen); \
42 char *__newbuf = __alloca (__newlen); \
43 char *__buf = (char *) (buf); \
44 if (__buf + len == __newbuf) \
45 { \
46 len += __newlen; \
47 __newbuf = __buf; \
48 } \
49 else \
50 len = __newlen; \
51 __newbuf; })
52 #else
53 # define extend_alloca(buf, len, newlen) \
54 __alloca (((len) = (newlen)))
55 #endif
57 #if defined stackinfo_get_sp && defined stackinfo_sub_sp
58 # define alloca_account(size, avar) \
59 ({ void *old__ = stackinfo_get_sp (); \
60 void *m__ = __alloca (size); \
61 avar += stackinfo_sub_sp (old__); \
62 m__; })
63 # define extend_alloca_account(buf, len, newlen, avar) \
64 ({ void *old__ = stackinfo_get_sp (); \
65 void *m__ = extend_alloca (buf, len, newlen); \
66 avar += stackinfo_sub_sp (old__); \
67 m__; })
68 #else
69 # define alloca_account(size, avar) \
70 ({ size_t s__ = (size); \
71 avar += s__; \
72 __alloca (s__); })
73 # define extend_alloca_account(buf, len, newlen, avar) \
74 ({ size_t s__ = (newlen); \
75 avar += s__; \
76 extend_alloca (buf, len, s__); })
77 #endif
79 # endif /* !_ISOMAC */
80 #endif