alloca.in.h 2.4 KB

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