path: root/
diff options
authorKirill Smelkov <>2014-03-27 14:22:50 (GMT)
committerJunio C Hamano <>2014-03-27 18:54:01 (GMT)
commit61f76a3612db199a9eb9090c2605d8fc35ffc41c (patch)
treefc5e216179e5fd11343f0b59b77b3da354ece5c9 /
parent12cd81743dc4645ef909b0c38582f5714c9a8ff7 (diff)
Portable alloca for Git
In the next patch we'll have to use alloca() for performance reasons, but since alloca is non-standardized and is not portable, let's have a trick with compatibility wrappers: 1. at configure time, determine, do we have working alloca() through alloca.h, and define #define HAVE_ALLOCA_H if yes. 2. in code #ifdef HAVE_ALLOCA_H # include <alloca.h> # define xalloca(size) (alloca(size)) # define xalloca_free(p) do {} while(0) #else # define xalloca(size) (xmalloc(size)) # define xalloca_free(p) (free(p)) #endif and use it like func() { p = xalloca(size); ... xalloca_free(p); } This way, for systems, where alloca is available, we'll have optimal on-stack allocations with fast executions. On the other hand, on systems, where alloca is not available, this gracefully fallbacks to xmalloc/free. Both autoconf and config.mak.uname configurations were updated. For autoconf, we are not bothering considering cases, when no alloca.h is available, but alloca() works some other way - its simply alloca.h is available and works or not, everything else is deep legacy. For config.mak.uname, I've tried to make my almost-sure guess for where alloca() is available, but since I only have access to Linux it is the only change I can be sure about myself, with relevant to other changed systems people Cc'ed. NOTE SunOS and Windows had explicit -DHAVE_ALLOCA_H in their configurations. I've changed that to now-common HAVE_ALLOCA_H=YesPlease which should be correct. Cc: Brandon Casey <> Cc: Marius Storm-Olsen <> Cc: Johannes Sixt <> Cc: Johannes Schindelin <> Cc: Ramsay Jones <> Cc: Gerrit Pape <> Cc: Petr Salinger <> Cc: Jonathan Nieder <> Acked-by: Thomas Schwinge <> (GNU Hurd changes) Signed-off-by: Kirill Smelkov <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to '')
1 files changed, 8 insertions, 0 deletions
diff --git a/ b/
index 2f43393..0eae704 100644
--- a/
+++ b/
@@ -272,6 +272,14 @@ AS_HELP_STRING([], [ARG can be also prefix for libpcre library and hea
+# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
+case $ac_cv_working_alloca_h in
+ yes) HAVE_ALLOCA_H=YesPlease;;
+ *) HAVE_ALLOCA_H='';;
# Define NO_CURL if you do not have curl installed. git-http-pull and
# git-http-push are not built, and you cannot use http:// and https://
# transports.