From f9b730cd59dbc3af26dc7964dd931cffdfdc481b Mon Sep 17 00:00:00 2001 From: Jesse Thilo Date: Tue, 13 Apr 1999 19:53:42 +0000 Subject: [PATCH] Don't declare calloc() and realloc() if not necessary. --- acconfig.h | 8 ++++++++ acinclude.m4 | 47 +++++++++++++++++++++++++++++++++++++++++++++++ configure.in | 1 + src/allocate.c | 10 +++++++++- 4 files changed, 65 insertions(+), 1 deletion(-) diff --git a/acconfig.h b/acconfig.h index fd8cc099..ccbb40c8 100644 --- a/acconfig.h +++ b/acconfig.h @@ -31,6 +31,14 @@ /* The location of the semantic parser (bison.hairy). */ #undef XPFILE1 + +/* Define as 1 if realloc must be declared even if is + included. */ +#undef NEED_DECLARATION_REALLOC + +/* Define as 1 if calloc must be declared even if is + included. */ +#undef NEED_DECLARATION_CALLOC @BOTTOM@ #if defined(PROTOTYPES) || defined(__cplusplus) diff --git a/acinclude.m4 b/acinclude.m4 index 6d72b703..8c909d2b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -11,3 +11,50 @@ AC_DEFUN(BISON_DEFINE_FILE, [ )` AC_DEFINE_UNQUOTED($1, "$ac_expanded") ]) + +dnl See whether we need a declaration for a function. +dnl BISON_NEED_DECLARATION(FUNCTION [, EXTRA-HEADER-FILES]) +AC_DEFUN(BISON_NEED_DECLARATION, +[AC_MSG_CHECKING([whether $1 must be declared]) +AC_CACHE_VAL(bison_cv_decl_needed_$1, +[AC_TRY_COMPILE([ +#include +#ifdef HAVE_STRING_H +#include +#else +#ifdef HAVE_STRINGS_H +#include +#endif +#endif +#ifdef HAVE_STDLIB_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif +#ifndef HAVE_RINDEX +#define rindex strrchr +#endif +#ifndef HAVE_INDEX +#define index strchr +#endif +$2], +[char *(*pfn) = (char *(*)) $1], +eval "bison_cv_decl_needed_$1=no", eval "bison_cv_decl_needed_$1=yes")]) +if eval "test \"`echo '$bison_cv_decl_needed_'$1`\" = yes"; then + AC_MSG_RESULT(yes) + bison_tr_decl=NEED_DECLARATION_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` + AC_DEFINE_UNQUOTED($bison_tr_decl) +else + AC_MSG_RESULT(no) +fi +])dnl + +dnl Check multiple functions to see whether each needs a declaration. +dnl BISON_NEED_DECLARATIONS(FUNCTION... [, EXTRA-HEADER-FILES]) +AC_DEFUN(BISON_NEED_DECLARATIONS, +[for ac_func in $1 +do +BISON_NEED_DECLARATION($ac_func, $2) +done +]) diff --git a/configure.in b/configure.in index ab54e81e..2cd7d676 100644 --- a/configure.in +++ b/configure.in @@ -31,6 +31,7 @@ AM_C_PROTOTYPES dnl Checks for library functions. AC_FUNC_ALLOCA AC_CHECK_FUNCS(mkstemp setlocale) +BISON_NEED_DECLARATIONS(calloc realloc) AM_GNU_GETTEXT diff --git a/src/allocate.c b/src/allocate.c index 1175e791..fdc83856 100644 --- a/src/allocate.c +++ b/src/allocate.c @@ -22,13 +22,21 @@ Boston, MA 02111-1307, USA. */ #include #include "system.h" +#ifdef NEED_DECLARATION_CALLOC #if defined (__STDC__) || defined (_MSC_VER) extern void *calloc (); -extern void *realloc (); #else extern char *calloc (); +#endif +#endif /* NEED_DECLARATION_CALLOC */ + +#ifdef NEED_DECLARATION_REALLOC +#if defined (__STDC__) || defined (_MSC_VER) +extern void *realloc (); +#else extern char *realloc (); #endif +#endif /* NEED_DECLARATION_REALLOC */ char *xmalloc PARAMS((register unsigned)); char *xrealloc PARAMS((register char *, register unsigned)); -- 2.45.2