pty: Activate the signature wrapper of forkpty.
[gnulib.git] / doc / alloca-opt.texi
1 @c Documentation of gnulib module 'alloca-opt'.
2
3 @c Copyright (C) 2004, 2007, 2009-2013 Free Software Foundation, Inc.
4
5 @c Permission is granted to copy, distribute and/or modify this document
6 @c under the terms of the GNU Free Documentation License, Version 1.3 or
7 @c any later version published by the Free Software Foundation; with no
8 @c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
9 @c Texts.  A copy of the license is included in the ``GNU Free
10 @c Documentation License'' file as part of this distribution.
11
12 The alloca-opt module provides for a function @code{alloca} which allocates
13 memory on the stack, where the system allows it. A memory block allocated with
14 @code{alloca} exists only until the function that calls @code{alloca} returns
15 or exits abruptly.
16
17 There are a few systems where this is not possible: HP-UX systems, and some
18 other platforms when the C++ compiler is used. On these platforms the
19 alloca-opt module provides no replacement, just a preprocessor macro
20 HAVE_ALLOCA.
21
22 The user can @code{#include <alloca.h>} on all platforms, and use
23 @code{alloca} on those platforms where the preprocessor macro HAVE_ALLOCA
24 evaluates to true. If HAVE_ALLOCA is false, the code should use a heap-based
25 memory allocation based on @code{malloc} or (in C++) @code{new}. Note that
26 the @code{#include <alloca.h>} must be the first one after the
27 autoconf-generated @file{config.h}, for AIX 3 compatibility. Thanks to IBM for
28 this nice restriction!
29
30 Note that GCC 3.1 and 3.2 can @emph{inline} functions that call @code{alloca}.
31 When this happens, the memory blocks allocated with @code{alloca} will not be
32 freed until @emph{the end of the calling function}. If this calling function
33 runs a loop calling the function that uses @code{alloca}, the program easily
34 gets a stack overflow and crashes. To protect against this compiler behaviour,
35 you can mark the function that uses @code{alloca} with the following attribute:
36
37 @smallexample
38 #ifdef __GNUC__
39 __attribute__ ((__noinline__))
40 #endif
41 @end smallexample