X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=doc%2Falloca-opt.texi;h=29499a2db37b8fa48f5a8e8ff75ccd0d572f3a6f;hb=c26924950a3a546112e35c99aad85c0855f4664a;hp=307a8f12f6925232dd539475ef063991173fd1a6;hpb=a897449aaae8e6c051f3b9daaf984de5c5e092f3;p=gnulib.git diff --git a/doc/alloca-opt.texi b/doc/alloca-opt.texi index 307a8f12f..29499a2db 100644 --- a/doc/alloca-opt.texi +++ b/doc/alloca-opt.texi @@ -1,25 +1,41 @@ @c Documentation of gnulib module 'alloca-opt'. -@c Copyright (C) 2004 Free Software Foundation, Inc. +@c Copyright (C) 2004, 2007 Free Software Foundation, Inc. @c Permission is granted to copy, distribute and/or modify this document -@c under the terms of the GNU Free Documentation License, Version 1.2 or +@c under the terms of the GNU Free Documentation License, Version 1.3 or @c any later version published by the Free Software Foundation; with no @c Invariant Sections, with no Front-Cover Texts, and with no Back-Cover @c Texts. A copy of the license is included in the ``GNU Free @c Documentation License'' file as part of this distribution. -The alloca-opt module provides for a function alloca() which allocates memory -on the stack, where the system allows it. A memory block allocated with alloca() -exists only until the function that calls alloca() returns or exits abruptly. +The alloca-opt module provides for a function @code{alloca} which allocates +memory on the stack, where the system allows it. A memory block allocated with +@code{alloca} exists only until the function that calls @code{alloca} returns +or exits abruptly. There are a few systems where this is not possible: HP-UX systems, and some -other platforms when the C++ compiler is used. On these platforms the alloca-opt -module provides no replacement, just a preprocessor macro HAVE_ALLOCA. +other platforms when the C++ compiler is used. On these platforms the +alloca-opt module provides no replacement, just a preprocessor macro +HAVE_ALLOCA. -The user can #include on all platforms, and use alloca() on those -platforms where the preprocessor macro HAVE_ALLOCA evaluates to true. If -HAVE_ALLOCA is false, the code should use a heap-based memory allocation -based on malloc() or - in C++ - 'new'. Note that the #include must be -the first one after the autoconf-generated config.h. Thanks to AIX for this nice -restriction! +The user can @code{#include } on all platforms, and use +@code{alloca} on those platforms where the preprocessor macro HAVE_ALLOCA +evaluates to true. If HAVE_ALLOCA is false, the code should use a heap-based +memory allocation based on @code{malloc} or - in C++ - @code{new}. Note that +the @code{#include } must be the first one after the +autoconf-generated @file{config.h}, for AIX 3 compatibility. Thanks to IBM for +this nice restriction! + +Note that GCC 3.1 and 3.2 can @emph{inline} functions that call @code{alloca}. +When this happens, the memory blocks allocated with @code{alloca} will not be +freed until @emph{the end of the calling function}. If this calling function +runs a loop calling the function that uses @code{alloca}, the program easily +gets a stack overflow and crashes. To protect against this compiler behaviour, +you can mark the function that uses @code{alloca} with the following attribute: + +@smallexample +#ifdef __GNUC__ +__attribute__ ((__noinline__)) +#endif +@end smallexample