Home | History | Annotate | Line # | Download | only in include
      1  1.1  christos /* Memory allocation on the stack.
      2  1.1  christos    Copyright (C) 1995, 1999, 2001-2005 Free Software Foundation, Inc.
      3  1.1  christos 
      4  1.1  christos    This program is free software; you can redistribute it and/or modify it
      5  1.1  christos    under the terms of the GNU General Public License as published
      6  1.1  christos    by the Free Software Foundation; either version 2, or (at your option)
      7  1.1  christos    any later version.
      8  1.1  christos 
      9  1.1  christos    This program is distributed in the hope that it will be useful,
     10  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  1.1  christos    General Public License for more details.
     13  1.1  christos 
     14  1.1  christos    You should have received a copy of the GNU General Public
     15  1.1  christos    License along with this program; if not, write to the Free Software
     16  1.1  christos    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
     17  1.1  christos    USA.  */
     18  1.1  christos 
     19  1.1  christos /* When this file is included, it may be preceded only by preprocessor
     20  1.1  christos    declarations.  Thanks to AIX.  Therefore we include it right after
     21  1.1  christos    "config.h", not later.  */
     22  1.1  christos 
     23  1.1  christos /* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
     24  1.1  christos    means there is a real alloca function.  */
     25  1.1  christos #ifndef _GNULIB_ALLOCA_H
     26  1.1  christos #define _GNULIB_ALLOCA_H
     27  1.1  christos 
     28  1.1  christos /* alloca(N) returns a pointer (void* or char*) to N bytes of memory
     29  1.1  christos    allocated on the stack, and which will last until the function returns.
     30  1.1  christos    Use of alloca should be avoided:
     31  1.1  christos      - inside arguments of function calls - undefined behaviour,
     32  1.1  christos      - in inline functions - the allocation may actually last until the
     33  1.1  christos        calling function returns,
     34  1.1  christos      - for huge N (say, N >= 65536) - you never know how large (or small)
     35  1.1  christos        the stack is, and when the stack cannot fulfill the memory allocation
     36  1.1  christos        request, the program just crashes.
     37  1.1  christos  */
     38  1.1  christos 
     39  1.2  christos #if defined(__GNUC__) || defined(__lint__)
     40  1.1  christos # ifndef alloca
     41  1.1  christos #  define alloca __builtin_alloca
     42  1.1  christos # endif
     43  1.1  christos #else
     44  1.1  christos # ifdef _MSC_VER
     45  1.1  christos #  include <malloc.h>
     46  1.1  christos #  define alloca _alloca
     47  1.1  christos # else
     48  1.1  christos #  if HAVE_ALLOCA_H
     49  1.1  christos #   include <alloca.h>
     50  1.1  christos #  else
     51  1.1  christos #   ifdef _AIX
     52  1.1  christos  #pragma alloca
     53  1.1  christos #   else
     54  1.1  christos #    ifdef __hpux /* This section must match that of bison generated files. */
     55  1.1  christos #     ifdef __cplusplus
     56  1.1  christos extern "C" void *alloca (unsigned int);
     57  1.1  christos #     else /* not __cplusplus */
     58  1.1  christos extern void *alloca ();
     59  1.1  christos #     endif /* not __cplusplus */
     60  1.1  christos #    else /* not __hpux */
     61  1.1  christos #     ifndef alloca
     62  1.1  christos extern char *alloca ();
     63  1.1  christos #     endif
     64  1.1  christos #    endif /* __hpux */
     65  1.1  christos #   endif
     66  1.1  christos #  endif
     67  1.1  christos # endif
     68  1.1  christos #endif
     69  1.1  christos 
     70  1.1  christos #endif /* _GNULIB_ALLOCA_H */
     71