Handle alloca "correctly".

Use AC_FUNC_ALLOCA and the #ifdef mess suggested by the autoconf docs
(hidden in qfalloca.h).
This commit is contained in:
Bill Currie 2013-01-22 14:09:41 +09:00
parent f1aefc969d
commit e27d7cbd2d
32 changed files with 124 additions and 45 deletions

View file

@ -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 <stdlib.h>],
[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 <stdlib.h>]
[#include <alloca.h>],
[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 <stdlib.h>
void *alloca (size_t size);
#endif
#endif])
AC_FUNC_ALLOCA
AC_MSG_CHECKING(for fnmatch in fnmatch.h)
AC_TRY_COMPILE(

62
include/qfalloca.h Normal file
View file

@ -0,0 +1,62 @@
/*
qfalloca.h
alloca declaration
Copyright (C) 2013 Bill Currie <bill@taniwha.org>
Author: Bill Currie <bill@taniwha.org>
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 <stdlib.h>
# include <stddef.h>
#else
# ifdef HAVE_STDLIB_H
# include <stdlib.h>
# endif
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif !defined alloca
# ifdef __GNUC__
# define alloca __builtin_alloca
# elif defined _AIX
# define alloca __alloca
# elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
# elif !defined HAVE_ALLOCA
# ifdef __cplusplus
extern "C"
# endif
void *alloca (size_t);
# endif
#endif
#endif//__qfalloca_h

View file

@ -41,6 +41,8 @@
#include <stdlib.h>
#include <FLAC/export.h>
#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

View file

@ -37,6 +37,8 @@
#include <stdlib.h>
#include <wildmidi_lib.h>
#include "qfalloca.h"
#include "QF/cvar.h"
#include "QF/sound.h"
#include "QF/sys.h"

View file

@ -36,6 +36,8 @@
#endif
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/cvar.h"
#include "QF/sound.h"
#include "QF/sys.h"

View file

@ -56,6 +56,8 @@
#include <signal.h>
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/cbuf.h"
#include "QF/cmd.h"
#include "QF/console.h"

View file

@ -37,6 +37,8 @@
#include <stdarg.h>
#include <stdio.h>
#include "qfalloca.h"
#if defined(_WIN32) && defined(HAVE_MALLOC_H)
#include <malloc.h>
#endif

View file

@ -41,6 +41,8 @@
# include <strings.h>
#endif
#include "qfalloca.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/image.h"

View file

@ -39,6 +39,8 @@
# include <strings.h>
#endif
#include "qfalloca.h"
#include "QF/dstring.h"
#include "QF/image.h"
#include "QF/qendian.h"

View file

@ -38,6 +38,8 @@
# include <strings.h>
#endif
#include "qfalloca.h"
#include "QF/model.h"
#include "QF/sys.h"
#include "QF/winding.h"

View file

@ -32,6 +32,8 @@
#endif
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/sys.h"
#include "QF/winding.h"

View file

@ -42,6 +42,8 @@
#include <malloc.h>
#endif
#include "qfalloca.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/hash.h"

View file

@ -39,6 +39,8 @@
#endif
#include <stdlib.h>
#include "qfalloca.h"
#if defined(_WIN32) && defined(HAVE_MALLOC_H)
#include <malloc.h>
#endif

View file

@ -36,6 +36,8 @@
#include <malloc.h>
#endif
#include "qfalloca.h"
#include "QF/dstring.h"
#include "QF/hash.h"
#include "QF/qfplist.h"

View file

@ -73,6 +73,8 @@
#include <limits.h>
#include "qfalloca.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/dstring.h"

View file

@ -59,6 +59,8 @@
#include <stdlib.h>
#include <errno.h>
#include "qfalloca.h"
#include "QF/dstring.h"
#include "QF/qendian.h"
#include "QF/quakefs.h"

View file

@ -75,6 +75,8 @@
#include <direct.h>
#endif
#include "qfalloca.h"
#include "QF/cmd.h"
#include "QF/cvar.h"
#include "QF/dstring.h"

View file

@ -39,6 +39,8 @@
# include <strings.h>
#endif
#include "qfalloca.h"
#include <math.h>
#include <stdio.h>

View file

@ -38,9 +38,6 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#endif
#if defined(_WIN32) && defined(HAVE_MALLOC_H)
#include <malloc.h>
@ -49,6 +46,8 @@
#include <stdarg.h>
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/cvar.h"
#include "QF/render.h"
#include "QF/sys.h"

View file

@ -42,6 +42,8 @@
#endif
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/cvar.h"
#include "QF/dstring.h"
#include "QF/image.h"

View file

@ -38,6 +38,8 @@
#include <math.h>
#include <stdio.h>
#include "qfalloca.h"
#include "QF/cvar.h"
#include "QF/render.h"

View file

@ -31,6 +31,8 @@
#include <math.h>
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/render.h"
#include "QF/sys.h"

View file

@ -34,6 +34,8 @@
#include <math.h>
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/render.h"
#include "QF/sys.h"

View file

@ -37,9 +37,6 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#endif
#if defined(_WIN32) && defined(HAVE_MALLOC_H)
#include <malloc.h>
@ -48,6 +45,8 @@
#include <ctype.h>
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/hash.h"
#include "QF/qtypes.h"
#include "QF/sys.h"

View file

@ -61,6 +61,8 @@
#include <errno.h>
#include <setjmp.h>
#include "qfalloca.h"
#include "QF/cbuf.h"
#include "QF/idparse.h"
#include "QF/cdaudio.h"

View file

@ -32,6 +32,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#endif
#include <ctype.h>
#include "qfalloca.h"
#include "QF/cmd.h"
#include "QF/dstring.h"
#include "QF/quakefs.h"

View file

@ -40,6 +40,8 @@
#include <stdlib.h>
#include <ctype.h>
#include "qfalloca.h"
#include "QF/alloc.h"
#include "QF/dstring.h"
#include "QF/mathlib.h"

View file

@ -44,6 +44,8 @@
#include <QF/quakeio.h>
#include <QF/va.h>
#include "qfalloca.h"
#include "expr.h"
#include "symtab.h"
#include "type.h"

View file

@ -50,6 +50,8 @@
#include <fcntl.h>
#include <errno.h>
#include "qfalloca.h"
#include "QF/alloc.h"
#include "QF/dstring.h"
#include "QF/hash.h"

View file

@ -37,9 +37,8 @@
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#endif
#include "qfalloca.h"
#include "compat.h"

View file

@ -39,6 +39,8 @@
#include <stdlib.h>
#include "qfalloca.h"
#include "QF/alloc.h"
#include "QF/va.h"

View file

@ -42,6 +42,8 @@
# include <malloc.h>
#endif
#include "qfalloca.h"
#include "QF/bspfile.h"
#include "QF/mathlib.h"