From 3cbefde37656f2d3655e020e5922d33f44834187 Mon Sep 17 00:00:00 2001 From: Doug Luce Date: Thu, 18 Jun 2015 11:07:16 -0700 Subject: [PATCH] Add alloca() discovery to configure.ac The build failed on FreeBSD as there is no alloca.h. This patch is lifted from the autoconf documentation. --- builtin.c | 21 ++++++++++++++++----- configure.ac | 2 ++ util.c | 18 +++++++++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/builtin.c b/builtin.c index 1e3f0854..4d538eac 100644 --- a/builtin.c +++ b/builtin.c @@ -1,10 +1,22 @@ #define _BSD_SOURCE #define _XOPEN_SOURCE #include -#ifdef WIN32 - #include -#else - #include +#include +#include +#ifdef HAVE_ALLOCA_H +# include +#elif !defined alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _MSC_VER +# include +# define alloca _alloca +# elif !defined HAVE_ALLOCA +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +# endif #endif #include #include @@ -13,7 +25,6 @@ #ifdef HAVE_ONIGURUMA #include #endif -#include #include #include #include "builtin.h" diff --git a/configure.ac b/configure.ac index bf236194..ccbe8dcb 100644 --- a/configure.ac +++ b/configure.ac @@ -123,6 +123,8 @@ AM_CONDITIONAL([ENABLE_DOCS], [test "x$enable_docs" != xno]) AM_CONDITIONAL([ENABLE_ERROR_INJECTION], [test "x$enable_error_injection" = xyes]) AM_CONDITIONAL([ENABLE_ALL_STATIC], [test "x$enable_all_static" = xyes]) +AC_FUNC_ALLOCA + AC_FIND_FUNC([isatty], [c], [#include ], [0]) AC_FIND_FUNC([_isatty], [c], [#include ], [0]) AC_FIND_FUNC([strptime], [c], [#include ], [0, 0, 0]) diff --git a/util.c b/util.c index f7e3f917..30419269 100644 --- a/util.c +++ b/util.c @@ -10,8 +10,24 @@ #include #include #include -#include #include +#include +#include +#ifdef HAVE_ALLOCA_H +# include +#elif !defined alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _MSC_VER +# include +# define alloca _alloca +# elif !defined HAVE_ALLOCA +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +# endif +#endif #ifndef WIN32 #include #endif