Don't unconditionally use alloca in gaih_inet
[platform/upstream/glibc.git] / include / alloca.h
1 #ifndef _ALLOCA_H
2
3 #include <stdlib/alloca.h>
4 #include <stackinfo.h>
5
6 #undef  __alloca
7
8 /* Now define the internal interfaces.  */
9 extern void *__alloca (size_t __size);
10
11 #ifdef  __GNUC__
12 # define __alloca(size) __builtin_alloca (size)
13 #endif /* GCC.  */
14
15 extern int __libc_use_alloca (size_t size) __attribute__ ((const));
16 extern int __libc_alloca_cutoff (size_t size) __attribute__ ((const));
17 libc_hidden_proto (__libc_alloca_cutoff)
18
19 #define __MAX_ALLOCA_CUTOFF     65536
20
21 #include <allocalim.h>
22
23 #if _STACK_GROWS_DOWN
24 # define extend_alloca(buf, len, newlen) \
25   (__typeof (buf)) ({ size_t __newlen = (newlen);                             \
26                       char *__newbuf = __alloca (__newlen);                   \
27                       if (__newbuf + __newlen == (char *) buf)                \
28                         len += __newlen;                                      \
29                       else                                                    \
30                         len = __newlen;                                       \
31                       __newbuf; })
32 #elif _STACK_GROWS_UP
33 # define extend_alloca(buf, len, newlen) \
34   (__typeof (buf)) ({ size_t __newlen = (newlen);                             \
35                       char *__newbuf = __alloca (__newlen);                   \
36                       char *__buf = (buf);                                    \
37                       if (__buf + __newlen == __newbuf)                       \
38                         {                                                     \
39                           len += __newlen;                                    \
40                           __newbuf = __buf;                                   \
41                         }                                                     \
42                       else                                                    \
43                         len = __newlen;                                       \
44                       __newbuf; })
45 #else
46 # define extend_alloca(buf, len, newlen) \
47   __alloca (((len) = (newlen)))
48 #endif
49
50 #if defined stackinfo_get_sp && defined stackinfo_sub_sp
51 # define alloca_account(size, avar) \
52   ({ void *old__ = stackinfo_get_sp ();                                       \
53      void *m__ = __alloca (size);                                             \
54      avar += stackinfo_sub_sp (old__);                                        \
55      m__; })
56 # define extend_alloca_account(buf, len, newlen, avar) \
57   ({ void *old__ = stackinfo_get_sp ();                                       \
58      void *m__ = extend_alloca (buf, len, newlen);                            \
59      avar += stackinfo_sub_sp (old__);                                        \
60      m__; })
61 #else
62 # define alloca_account(size, avar) \
63   ({ size_t s__ = (size);                                                     \
64      avar += s__;                                                             \
65      __alloca (s__); })
66 # define extend_alloca_account(buf, len, newlen, avar) \
67   ({ size_t s__ = (newlen);                                                   \
68      avar += s__;                                                             \
69      extend_alloca (buf, len, s__); })
70 #endif
71
72 #endif