From e27d7cbd2d8dfb62ff98d7ab137be1eca37a496d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 22 Jan 2013 14:09:41 +0900 Subject: [PATCH] Handle alloca "correctly". Use AC_FUNC_ALLOCA and the #ifdef mess suggested by the autoconf docs (hidden in qfalloca.h). --- config.d/header_files.m4 | 38 +---------------- include/qfalloca.h | 62 ++++++++++++++++++++++++++++ libs/audio/renderer/flac.c | 2 + libs/audio/renderer/midi.c | 2 + libs/audio/renderer/wav.c | 2 + libs/console/server.c | 2 + libs/gamecode/pr_parse.c | 2 + libs/models/brush/glsl_model_brush.c | 2 + libs/models/iqm/sw_model_iqm.c | 2 + libs/models/trace.c | 2 + libs/models/winding.c | 2 + libs/ruamoko/rua_obj.c | 2 + libs/ruamoko/rua_string.c | 2 + libs/util/qfplist.c | 2 + libs/util/quakefs.c | 2 + libs/util/quakeio.c | 2 + libs/util/sys.c | 2 + libs/video/renderer/gl/gl_rsurf.c | 2 + libs/video/renderer/gl/gl_sky_clip.c | 5 +-- libs/video/renderer/glsl/glsl_bsp.c | 2 + libs/video/renderer/r_light.c | 2 + libs/video/renderer/sw/sw_rbsp.c | 2 + libs/video/renderer/sw32/sw32_rbsp.c | 2 + libs/video/targets/old_keys.c | 5 +-- qw/source/cl_main.c | 2 + qw/source/sv_pr_cpqw.c | 2 + tools/qfcc/source/dags.c | 2 + tools/qfcc/source/dot_expr.c | 2 + tools/qfcc/source/linker.c | 2 + tools/qfcc/source/obj_type.c | 5 +-- tools/qfcc/source/statements.c | 2 + tools/qflight/source/vis.c | 2 + 32 files changed, 124 insertions(+), 45 deletions(-) create mode 100644 include/qfalloca.h diff --git a/config.d/header_files.m4 b/config.d/header_files.m4 index e9fbf58f8..afb4cd37f 100644 --- a/config.d/header_files.m4 +++ b/config.d/header_files.m4 @@ -7,7 +7,7 @@ AC_HEADER_STDC AC_HEADER_MAJOR AC_HEADER_SYS_WAIT AC_CHECK_HEADERS( - alloca.h arpa/inet.h asm/io.h assert.h conio.h \ + arpa/inet.h asm/io.h assert.h conio.h \ ctype.h ddraw.h dinput.h direct.h dirent.h dlfcn.h dmedia/audio.h \ dmedia/cdaudio.h dpmi.h dsound.h errno.h fcntl.h io.h \ ifaddrs.h libc.h limits.h linux/cdrom.h linux/joystick.h \ @@ -30,41 +30,7 @@ else AC_CHECK_HEADERS(fnmatch.h) fi -if test "x$ac_cv_header_alloca_h" = xno; then - AC_MSG_CHECKING(for alloca in stdlib.h) - AC_TRY_COMPILE( - [#include ], - [void *(*foo)(size_t) = alloca;], - have_alloca_proto=yes - AC_MSG_RESULT(yes), - have_alloca_proto=no - AC_MSG_RESULT(no) - ) -else - AC_MSG_CHECKING(for alloca in alloca.h) - AC_TRY_COMPILE( - [#include ] - [#include ], - [void *(*foo)(size_t) = alloca;], - have_alloca_proto=yes - AC_MSG_RESULT(yes), - have_alloca_proto=no - AC_MSG_RESULT(no) - ) -fi - -if test "x$have_alloca_proto" = xyes; then - AC_DEFINE(HAVE_ALLOCA_PROTO) -fi -AH_VERBATIM([HAVE_ALLOCA_PROTO], -[/* Define this if alloca is prototyped */ -#undef HAVE_ALLOCA_PROTO -#ifndef HAVE_ALLOCA_PROTO -#ifndef QFASM -#include -void *alloca (size_t size); -#endif -#endif]) +AC_FUNC_ALLOCA AC_MSG_CHECKING(for fnmatch in fnmatch.h) AC_TRY_COMPILE( diff --git a/include/qfalloca.h b/include/qfalloca.h new file mode 100644 index 000000000..50fffdf95 --- /dev/null +++ b/include/qfalloca.h @@ -0,0 +1,62 @@ +/* + qfalloca.h + + alloca declaration + + Copyright (C) 2013 Bill Currie + + Author: Bill Currie + Date: 2013/01/22 + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ + +#ifndef __qfalloca_h +#define __qfalloca_h + +#include "config.h" + +#ifdef STDC_HEADERS +# include +# include +#else +# ifdef HAVE_STDLIB_H +# include +# endif +#endif +#ifdef HAVE_ALLOCA_H +# include +#elif !defined alloca +# ifdef __GNUC__ +# define alloca __builtin_alloca +# elif defined _AIX +# define alloca __alloca +# elif defined _MSC_VER +# include +# define alloca _alloca +# elif !defined HAVE_ALLOCA +# ifdef __cplusplus +extern "C" +# endif +void *alloca (size_t); +# endif +#endif + +#endif//__qfalloca_h diff --git a/libs/audio/renderer/flac.c b/libs/audio/renderer/flac.c index 3d84ebf7c..665c68b3e 100644 --- a/libs/audio/renderer/flac.c +++ b/libs/audio/renderer/flac.c @@ -41,6 +41,8 @@ #include #include +#include "qfalloca.h" + /* FLAC 1.1.3 has FLAC_API_VERSION_CURRENT == 8 */ #if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8 #define LEGACY_FLAC diff --git a/libs/audio/renderer/midi.c b/libs/audio/renderer/midi.c index 20e3b8670..4a32b9f98 100644 --- a/libs/audio/renderer/midi.c +++ b/libs/audio/renderer/midi.c @@ -37,6 +37,8 @@ #include #include +#include "qfalloca.h" + #include "QF/cvar.h" #include "QF/sound.h" #include "QF/sys.h" diff --git a/libs/audio/renderer/wav.c b/libs/audio/renderer/wav.c index 4f19abe8e..756b4566e 100644 --- a/libs/audio/renderer/wav.c +++ b/libs/audio/renderer/wav.c @@ -36,6 +36,8 @@ #endif #include +#include "qfalloca.h" + #include "QF/cvar.h" #include "QF/sound.h" #include "QF/sys.h" diff --git a/libs/console/server.c b/libs/console/server.c index 04ce4614d..5bf9061ec 100644 --- a/libs/console/server.c +++ b/libs/console/server.c @@ -56,6 +56,8 @@ #include #include +#include "qfalloca.h" + #include "QF/cbuf.h" #include "QF/cmd.h" #include "QF/console.h" diff --git a/libs/gamecode/pr_parse.c b/libs/gamecode/pr_parse.c index 52cd0db19..b7e1dcdb3 100644 --- a/libs/gamecode/pr_parse.c +++ b/libs/gamecode/pr_parse.c @@ -37,6 +37,8 @@ #include #include +#include "qfalloca.h" + #if defined(_WIN32) && defined(HAVE_MALLOC_H) #include #endif diff --git a/libs/models/brush/glsl_model_brush.c b/libs/models/brush/glsl_model_brush.c index 8de370981..8827844da 100644 --- a/libs/models/brush/glsl_model_brush.c +++ b/libs/models/brush/glsl_model_brush.c @@ -41,6 +41,8 @@ # include #endif +#include "qfalloca.h" + #include "QF/cvar.h" #include "QF/dstring.h" #include "QF/image.h" diff --git a/libs/models/iqm/sw_model_iqm.c b/libs/models/iqm/sw_model_iqm.c index 7e54fb720..2a32ecca0 100644 --- a/libs/models/iqm/sw_model_iqm.c +++ b/libs/models/iqm/sw_model_iqm.c @@ -39,6 +39,8 @@ # include #endif +#include "qfalloca.h" + #include "QF/dstring.h" #include "QF/image.h" #include "QF/qendian.h" diff --git a/libs/models/trace.c b/libs/models/trace.c index b852bbbc6..1fcecb47b 100644 --- a/libs/models/trace.c +++ b/libs/models/trace.c @@ -38,6 +38,8 @@ # include #endif +#include "qfalloca.h" + #include "QF/model.h" #include "QF/sys.h" #include "QF/winding.h" diff --git a/libs/models/winding.c b/libs/models/winding.c index 03cc3e421..d065224f7 100644 --- a/libs/models/winding.c +++ b/libs/models/winding.c @@ -32,6 +32,8 @@ #endif #include +#include "qfalloca.h" + #include "QF/sys.h" #include "QF/winding.h" diff --git a/libs/ruamoko/rua_obj.c b/libs/ruamoko/rua_obj.c index 66aa049c6..ed3a1d78b 100644 --- a/libs/ruamoko/rua_obj.c +++ b/libs/ruamoko/rua_obj.c @@ -42,6 +42,8 @@ #include #endif +#include "qfalloca.h" + #include "QF/cvar.h" #include "QF/dstring.h" #include "QF/hash.h" diff --git a/libs/ruamoko/rua_string.c b/libs/ruamoko/rua_string.c index 838893942..7f233e362 100644 --- a/libs/ruamoko/rua_string.c +++ b/libs/ruamoko/rua_string.c @@ -39,6 +39,8 @@ #endif #include +#include "qfalloca.h" + #if defined(_WIN32) && defined(HAVE_MALLOC_H) #include #endif diff --git a/libs/util/qfplist.c b/libs/util/qfplist.c index b98c3a791..03a85b5b2 100644 --- a/libs/util/qfplist.c +++ b/libs/util/qfplist.c @@ -36,6 +36,8 @@ #include #endif +#include "qfalloca.h" + #include "QF/dstring.h" #include "QF/hash.h" #include "QF/qfplist.h" diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index 9d73c2bb1..105ff096b 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -73,6 +73,8 @@ #include +#include "qfalloca.h" + #include "QF/cmd.h" #include "QF/cvar.h" #include "QF/dstring.h" diff --git a/libs/util/quakeio.c b/libs/util/quakeio.c index 22eb9a8a0..08e675e6e 100644 --- a/libs/util/quakeio.c +++ b/libs/util/quakeio.c @@ -59,6 +59,8 @@ #include #include +#include "qfalloca.h" + #include "QF/dstring.h" #include "QF/qendian.h" #include "QF/quakefs.h" diff --git a/libs/util/sys.c b/libs/util/sys.c index e9e3633a3..35d739e29 100644 --- a/libs/util/sys.c +++ b/libs/util/sys.c @@ -75,6 +75,8 @@ #include #endif +#include "qfalloca.h" + #include "QF/cmd.h" #include "QF/cvar.h" #include "QF/dstring.h" diff --git a/libs/video/renderer/gl/gl_rsurf.c b/libs/video/renderer/gl/gl_rsurf.c index 87ba5f3dd..032934dbd 100644 --- a/libs/video/renderer/gl/gl_rsurf.c +++ b/libs/video/renderer/gl/gl_rsurf.c @@ -39,6 +39,8 @@ # include #endif +#include "qfalloca.h" + #include #include diff --git a/libs/video/renderer/gl/gl_sky_clip.c b/libs/video/renderer/gl/gl_sky_clip.c index 755a00e8d..613e8b177 100644 --- a/libs/video/renderer/gl/gl_sky_clip.c +++ b/libs/video/renderer/gl/gl_sky_clip.c @@ -38,9 +38,6 @@ #ifdef HAVE_STRINGS_H # include #endif -#ifdef HAVE_ALLOCA_H -# include -#endif #if defined(_WIN32) && defined(HAVE_MALLOC_H) #include @@ -49,6 +46,8 @@ #include #include +#include "qfalloca.h" + #include "QF/cvar.h" #include "QF/render.h" #include "QF/sys.h" diff --git a/libs/video/renderer/glsl/glsl_bsp.c b/libs/video/renderer/glsl/glsl_bsp.c index ae5c3ea81..182000a06 100644 --- a/libs/video/renderer/glsl/glsl_bsp.c +++ b/libs/video/renderer/glsl/glsl_bsp.c @@ -42,6 +42,8 @@ #endif #include +#include "qfalloca.h" + #include "QF/cvar.h" #include "QF/dstring.h" #include "QF/image.h" diff --git a/libs/video/renderer/r_light.c b/libs/video/renderer/r_light.c index 6faad5e1e..bd242e7bc 100644 --- a/libs/video/renderer/r_light.c +++ b/libs/video/renderer/r_light.c @@ -38,6 +38,8 @@ #include #include +#include "qfalloca.h" + #include "QF/cvar.h" #include "QF/render.h" diff --git a/libs/video/renderer/sw/sw_rbsp.c b/libs/video/renderer/sw/sw_rbsp.c index 49d7e8fee..17fcbf5bb 100644 --- a/libs/video/renderer/sw/sw_rbsp.c +++ b/libs/video/renderer/sw/sw_rbsp.c @@ -31,6 +31,8 @@ #include #include +#include "qfalloca.h" + #include "QF/render.h" #include "QF/sys.h" diff --git a/libs/video/renderer/sw32/sw32_rbsp.c b/libs/video/renderer/sw32/sw32_rbsp.c index 1a4d8c1be..017268dbb 100644 --- a/libs/video/renderer/sw32/sw32_rbsp.c +++ b/libs/video/renderer/sw32/sw32_rbsp.c @@ -34,6 +34,8 @@ #include #include +#include "qfalloca.h" + #include "QF/render.h" #include "QF/sys.h" diff --git a/libs/video/targets/old_keys.c b/libs/video/targets/old_keys.c index 6ec5dfd35..99b87f4c4 100644 --- a/libs/video/targets/old_keys.c +++ b/libs/video/targets/old_keys.c @@ -37,9 +37,6 @@ #ifdef HAVE_STRINGS_H # include #endif -#ifdef HAVE_ALLOCA_H -# include -#endif #if defined(_WIN32) && defined(HAVE_MALLOC_H) #include @@ -48,6 +45,8 @@ #include #include +#include "qfalloca.h" + #include "QF/hash.h" #include "QF/qtypes.h" #include "QF/sys.h" diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 9f406e3d1..dd73f987a 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -61,6 +61,8 @@ #include #include +#include "qfalloca.h" + #include "QF/cbuf.h" #include "QF/idparse.h" #include "QF/cdaudio.h" diff --git a/qw/source/sv_pr_cpqw.c b/qw/source/sv_pr_cpqw.c index 78710b4a0..3037db482 100644 --- a/qw/source/sv_pr_cpqw.c +++ b/qw/source/sv_pr_cpqw.c @@ -32,6 +32,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif #include +#include "qfalloca.h" + #include "QF/cmd.h" #include "QF/dstring.h" #include "QF/quakefs.h" diff --git a/tools/qfcc/source/dags.c b/tools/qfcc/source/dags.c index 4dd1674a7..23783f11d 100644 --- a/tools/qfcc/source/dags.c +++ b/tools/qfcc/source/dags.c @@ -40,6 +40,8 @@ #include #include +#include "qfalloca.h" + #include "QF/alloc.h" #include "QF/dstring.h" #include "QF/mathlib.h" diff --git a/tools/qfcc/source/dot_expr.c b/tools/qfcc/source/dot_expr.c index fa710df59..aaf5b8706 100644 --- a/tools/qfcc/source/dot_expr.c +++ b/tools/qfcc/source/dot_expr.c @@ -44,6 +44,8 @@ #include #include +#include "qfalloca.h" + #include "expr.h" #include "symtab.h" #include "type.h" diff --git a/tools/qfcc/source/linker.c b/tools/qfcc/source/linker.c index e691baa0e..21687f52c 100644 --- a/tools/qfcc/source/linker.c +++ b/tools/qfcc/source/linker.c @@ -50,6 +50,8 @@ #include #include +#include "qfalloca.h" + #include "QF/alloc.h" #include "QF/dstring.h" #include "QF/hash.h" diff --git a/tools/qfcc/source/obj_type.c b/tools/qfcc/source/obj_type.c index 20e9230fe..2b77a864f 100644 --- a/tools/qfcc/source/obj_type.c +++ b/tools/qfcc/source/obj_type.c @@ -37,9 +37,8 @@ #ifdef HAVE_STRINGS_H # include #endif -#ifdef HAVE_ALLOCA_H -# include -#endif + +#include "qfalloca.h" #include "compat.h" diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index 0300ccfb7..b547379b5 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -39,6 +39,8 @@ #include +#include "qfalloca.h" + #include "QF/alloc.h" #include "QF/va.h" diff --git a/tools/qflight/source/vis.c b/tools/qflight/source/vis.c index cba4cd971..44ed4ecca 100644 --- a/tools/qflight/source/vis.c +++ b/tools/qflight/source/vis.c @@ -42,6 +42,8 @@ # include #endif +#include "qfalloca.h" + #include "QF/bspfile.h" #include "QF/mathlib.h"