xref: /Universal-ctags/gnulib/alloca.in.h (revision a939078a69878851c19820eb92e6cb95ba429546)
1*a939078aSHiroo HAYASHI /* Memory allocation on the stack.
2*a939078aSHiroo HAYASHI 
3*a939078aSHiroo HAYASHI    Copyright (C) 1995, 1999, 2001-2004, 2006-2021 Free Software Foundation,
4*a939078aSHiroo HAYASHI    Inc.
5*a939078aSHiroo HAYASHI 
6*a939078aSHiroo HAYASHI    This file is free software: you can redistribute it and/or modify
7*a939078aSHiroo HAYASHI    it under the terms of the GNU Lesser General Public License as
8*a939078aSHiroo HAYASHI    published by the Free Software Foundation; either version 2.1 of the
9*a939078aSHiroo HAYASHI    License, or (at your option) any later version.
10*a939078aSHiroo HAYASHI 
11*a939078aSHiroo HAYASHI    This file is distributed in the hope that it will be useful,
12*a939078aSHiroo HAYASHI    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*a939078aSHiroo HAYASHI    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*a939078aSHiroo HAYASHI    GNU Lesser General Public License for more details.
15*a939078aSHiroo HAYASHI 
16*a939078aSHiroo HAYASHI    You should have received a copy of the GNU Lesser General Public License
17*a939078aSHiroo HAYASHI    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
18*a939078aSHiroo HAYASHI 
19*a939078aSHiroo HAYASHI /* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
20*a939078aSHiroo HAYASHI    means there is a real alloca function.  */
21*a939078aSHiroo HAYASHI #ifndef _GL_ALLOCA_H
22*a939078aSHiroo HAYASHI #define _GL_ALLOCA_H
23*a939078aSHiroo HAYASHI 
24*a939078aSHiroo HAYASHI /* alloca (N) returns a pointer to N bytes of memory
25*a939078aSHiroo HAYASHI    allocated on the stack, which will last until the function returns.
26*a939078aSHiroo HAYASHI    Use of alloca should be avoided:
27*a939078aSHiroo HAYASHI      - inside arguments of function calls - undefined behaviour,
28*a939078aSHiroo HAYASHI      - in inline functions - the allocation may actually last until the
29*a939078aSHiroo HAYASHI        calling function returns,
30*a939078aSHiroo HAYASHI      - for huge N (say, N >= 65536) - you never know how large (or small)
31*a939078aSHiroo HAYASHI        the stack is, and when the stack cannot fulfill the memory allocation
32*a939078aSHiroo HAYASHI        request, the program just crashes.
33*a939078aSHiroo HAYASHI  */
34*a939078aSHiroo HAYASHI 
35*a939078aSHiroo HAYASHI #ifndef alloca
36*a939078aSHiroo HAYASHI   /* Some version of mingw have an <alloca.h> that causes trouble when
37*a939078aSHiroo HAYASHI      included after 'alloca' gets defined as a macro.  As a workaround,
38*a939078aSHiroo HAYASHI      include this <alloca.h> first and define 'alloca' as a macro afterwards
39*a939078aSHiroo HAYASHI      if needed.  */
40*a939078aSHiroo HAYASHI # if defined __GNUC__ && (defined _WIN32 && ! defined __CYGWIN__) && @HAVE_ALLOCA_H@
41*a939078aSHiroo HAYASHI #  include_next <alloca.h>
42*a939078aSHiroo HAYASHI # endif
43*a939078aSHiroo HAYASHI #endif
44*a939078aSHiroo HAYASHI #ifndef alloca
45*a939078aSHiroo HAYASHI # if defined __GNUC__ || (__clang_major__ >= 4)
46*a939078aSHiroo HAYASHI #  define alloca __builtin_alloca
47*a939078aSHiroo HAYASHI # elif defined _AIX
48*a939078aSHiroo HAYASHI #  define alloca __alloca
49*a939078aSHiroo HAYASHI # elif defined _MSC_VER
50*a939078aSHiroo HAYASHI #  include <malloc.h>
51*a939078aSHiroo HAYASHI #  define alloca _alloca
52*a939078aSHiroo HAYASHI # elif defined __DECC && defined __VMS
53*a939078aSHiroo HAYASHI #  define alloca __ALLOCA
54*a939078aSHiroo HAYASHI # elif defined __TANDEM && defined _TNS_E_TARGET
55*a939078aSHiroo HAYASHI #  ifdef  __cplusplus
56*a939078aSHiroo HAYASHI extern "C"
57*a939078aSHiroo HAYASHI #  endif
58*a939078aSHiroo HAYASHI void *_alloca (unsigned short);
59*a939078aSHiroo HAYASHI #  pragma intrinsic (_alloca)
60*a939078aSHiroo HAYASHI #  define alloca _alloca
61*a939078aSHiroo HAYASHI # elif defined __MVS__
62*a939078aSHiroo HAYASHI #  include <stdlib.h>
63*a939078aSHiroo HAYASHI # else
64*a939078aSHiroo HAYASHI #  include <stddef.h>
65*a939078aSHiroo HAYASHI #  ifdef  __cplusplus
66*a939078aSHiroo HAYASHI extern "C"
67*a939078aSHiroo HAYASHI #  endif
68*a939078aSHiroo HAYASHI void *alloca (size_t);
69*a939078aSHiroo HAYASHI # endif
70*a939078aSHiroo HAYASHI #endif
71*a939078aSHiroo HAYASHI 
72*a939078aSHiroo HAYASHI #endif /* _GL_ALLOCA_H */
73