bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-gnulib] Re: fnmatch.c includes alloca.h conditionally?


From: Paul Eggert
Subject: Re: [Bug-gnulib] Re: fnmatch.c includes alloca.h conditionally?
Date: Wed, 05 May 2004 13:11:52 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Derek Robert Price <derek@ximbiot.com> writes:

> Mostly this looks great to me, but you left out the HAVE_ALLOCA
> definitions from my patch.  I've attached a revised version.

Sorry, I neglected that.  However, wouldn't it be better to define
HAVE_ALLOCA in config.h, where most other code expects it?  It's a
small point, but I'd rather have HAVE_ALLOCA be a configure-time
setting.  The patch proposed below does this.

> The revised version also updates vasnprintf.c to include <alloca.h>
> unconditionally (its module is listed as dependent on the alloca
> module already).  This way, vasnprintf can have HAVE_ALLOCA defined
> properly relative to Bruno's concerns about only using alloca when
> it is a built-in & fast.

Your patch didn't include any changes to vasnprintf.c.  However, is
such a change needed?  Its #include <alloca.h> is conditional only on
"#ifndef IN_LIBINTL", and IN_LIBINTL shouldn't be defined in GNU
applications.

> Incidentally, lib/getdate.y only includes <alloca.h> and never calls
> alloca()

getdate.y calls alloca indirectly, because the Bison-generated code calls it.

> 2004-05-04  Paul Eggert  <eggert@cs.ucla.edu>
>         Derek Price  <derek@ximbiot.com>
>
>     * lib/alloca.c: Include <alloca.h>, to get our interface.

Hmm, the leading tabs got mangled in your email.

Here's a revision of the proposed patch, as described above.

2004-05-05  Paul Eggert  <eggert@cs.ucla.edu>
            Derek Price  <derek@ximbiot.com>

        * lib/alloca.c: Include <alloca.h>, to get our interface.
        * lib/alloca_.h: Use __alloca on AIX, so that we don't have to
        include <alloca.h> first.  Use C89 prototype for alloca; this
        requires including <stddef.h> for size_t.  Use extern "C" if C++.
        Use #elif for simplicity, since we can assume C89 now.
        Don't try to source the system alloca.h since it will not be found
        and to prevent recursively including its replacement.
        * m4/alloca.m4 (gl_FUNC_ALLOCA): Define HAVE_ALLOCA_H always,
        for backward compatibility with older code.  We need our own
        alloca.h if _AIX is defined.  Define HAVE_ALLOCA if we discover
        it under some other name, and our alloca.h will define it.

        * lib/fnmatch.c: Include <alloca.h> instead of opencoding.
        * lib/regex.c: Likewise.
        * modules/getdate: Depend on alloca.
        * modules/setenv: Likewise.

Index: lib/alloca.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/alloca.c,v
retrieving revision 1.13
diff -p -u -r1.13 alloca.c
--- lib/alloca.c        24 Nov 2003 21:38:44 -0000      1.13
+++ lib/alloca.c        5 May 2004 20:07:01 -0000
@@ -25,6 +25,8 @@
 # include <config.h>
 #endif
 
+#include <alloca.h>
+
 #include <string.h>
 #include <stdlib.h>
 
Index: lib/alloca_.h
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/alloca_.h,v
retrieving revision 1.4
diff -p -u -r1.4 alloca_.h
--- lib/alloca_.h       9 Aug 2003 08:57:49 -0000       1.4
+++ lib/alloca_.h       5 May 2004 20:07:01 -0000
@@ -1,5 +1,7 @@
 /* Memory allocation on the stack.
-   Copyright (C) 1995, 1999, 2001-2003 Free Software Foundation, Inc.
+
+   Copyright (C) 1995, 1999, 2001, 2002, 2003, 2004 Free Software
+   Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published
@@ -23,8 +25,8 @@
 #ifndef _ALLOCA_H
 # define _ALLOCA_H
 
-/* alloca(N) returns a pointer (void* or char*) to N bytes of memory
-   allocated on the stack, and which will last until the function returns.
+/* alloca (N) returns a pointer to N bytes of memory
+   allocated on the stack, which will last until the function returns.
    Use of alloca should be avoided:
      - inside arguments of function calls - undefined behaviour,
      - in inline functions - the allocation may actually last until the
@@ -34,35 +36,19 @@
        request, the program just crashes.
  */
 
-# ifdef __GNUC__
-#  ifndef alloca
-#   define alloca __builtin_alloca
-#  endif
-# else
-#  ifdef _MSC_VER
-#   include <malloc.h>
-#   define alloca _alloca
-#  else
-#   if HAVE_ALLOCA_H
-#    include <alloca.h>
-#   else
-#    ifdef _AIX
- #    pragma alloca
-#    else
-#     ifdef __hpux /* This section must match that of bison generated files. */
-#      ifdef __cplusplus
-extern "C" void *alloca (unsigned int);
-#      else /* not __cplusplus */
-extern void *alloca ();
-#      endif /* not __cplusplus */
-#     else /* not __hpux */
-#      ifndef alloca
-extern char *alloca ();
-#      endif
-#     endif /* __hpux */
-#    endif
-#   endif
-#  endif
+#ifdef __GNUC__
+# define alloca __builtin_alloca
+#elif defined _AIX
+# define alloca __alloca 
+#elif defined _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
+#else
+# include <stddef.h>
+# ifdef  __cplusplus
+extern "C"
 # endif
+void *alloca (size_t);
+#endif
 
 #endif /* _ALLOCA_H */
Index: lib/fnmatch.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/fnmatch.c,v
retrieving revision 1.26
diff -p -u -r1.26 fnmatch.c
--- lib/fnmatch.c       14 Jan 2004 22:15:48 -0000      1.26
+++ lib/fnmatch.c       5 May 2004 20:07:03 -0000
@@ -24,29 +24,13 @@
 # define _GNU_SOURCE   1
 #endif
 
-#ifdef __GNUC__
-# define alloca __builtin_alloca
-# define HAVE_ALLOCA 1
-#else
-# if defined HAVE_ALLOCA_H || defined _LIBC
-#  include <alloca.h>
-# else
-#  ifdef _AIX
- #  pragma alloca
-#  else
-#   ifndef alloca
-char *alloca ();
-#   endif
-#  endif
-# endif
-#endif
-
 #if ! defined __builtin_expect && __GNUC__ < 3
 # define __builtin_expect(expr, expected) (expr)
 #endif
 
 #include <fnmatch.h>
 
+#include <alloca.h>
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
Index: lib/regex.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/regex.c,v
retrieving revision 1.80
diff -p -u -r1.80 regex.c
--- lib/regex.c 10 Sep 2003 06:18:22 -0000      1.80
+++ lib/regex.c 5 May 2004 20:07:15 -0000
@@ -4,7 +4,7 @@
    internationalization features.)
 
    Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003 Free Software Foundation, Inc.
+   2002, 2003, 2004 Free Software Foundation, Inc.
 
    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
@@ -275,13 +275,7 @@ init_syntax_once (void)
 #  ifndef alloca
 
 /* Make alloca work the best possible way.  */
-#   ifdef __GNUC__
-#    define alloca __builtin_alloca
-#   else /* not __GNUC__ */
-#    if HAVE_ALLOCA_H
-#     include <alloca.h>
-#    endif /* HAVE_ALLOCA_H */
-#   endif /* not __GNUC__ */
+#   include <alloca.h>
 
 #  endif /* not alloca */
 
Index: m4/alloca.m4
===================================================================
RCS file: /cvsroot/gnulib/gnulib/m4/alloca.m4,v
retrieving revision 1.5
diff -p -u -r1.5 alloca.m4
--- m4/alloca.m4        8 Sep 2003 22:58:10 -0000       1.5
+++ m4/alloca.m4        5 May 2004 20:07:16 -0000
@@ -1,5 +1,5 @@
-# alloca.m4 serial 3
-dnl Copyright (C) 2002-2003 Free Software Foundation, Inc.
+# alloca.m4 serial 4
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
 dnl This file is free software, distributed under the terms of the GNU
 dnl General Public License.  As a special exception to the GNU General
 dnl Public License, this file may be distributed as part of a program
@@ -18,15 +18,25 @@ AC_DEFUN([gl_FUNC_ALLOCA],
   fi
 
   # Define an additional variable used in the Makefile substitution.
-
-  AC_EGREP_CPP([Need own alloca], [
-#if defined __GNUC__ || defined _MSC_VER || !HAVE_ALLOCA_H
-  Need own alloca
+  if test $ac_cv_working_alloca_h = yes; then
+    AC_EGREP_CPP([Need own alloca], [
+#if defined __GNUC__ || defined _AIX || defined _MSC_VER
+       Need own alloca
 #endif
-    ],
-    ALLOCA_H=alloca.h,
-    ALLOCA_H=)
+      ],
+      [AC_DEFINE(HAVE_ALLOCA, 1,
+           [Define to 1 if you have `alloca' after including <alloca.h>,
+            a header that may be supplied by this distribution.])
+       ALLOCA_H=alloca.h],
+      [ALLOCA_H=])
+  else
+    ALLOCA_H=alloca.h
+  fi
   AC_SUBST([ALLOCA_H])
+
+  AC_DEFINE(HAVE_ALLOCA_H, 1,
+    [Define HAVE_ALLOCA_H for backward compatibility with older code
+     that includes <alloca.h> only if HAVE_ALLOCA_H is defined.])
 ])
 
 # Prerequisites of lib/alloca.c.
Index: modules/getdate
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/getdate,v
retrieving revision 1.5
diff -p -u -r1.5 getdate
--- modules/getdate     31 Mar 2004 07:20:49 -0000      1.5
+++ modules/getdate     5 May 2004 20:07:16 -0000
@@ -13,6 +13,7 @@ timespec
 stdbool
 gettime
 mktime
+alloca
 unlocked-io
 
 configure.ac:
Index: modules/setenv
===================================================================
RCS file: /cvsroot/gnulib/gnulib/modules/setenv,v
retrieving revision 1.5
diff -p -u -r1.5 setenv
--- modules/setenv      20 Jan 2004 17:05:34 -0000      1.5
+++ modules/setenv      5 May 2004 20:07:16 -0000
@@ -10,6 +10,7 @@ m4/setenv.m4
 
 Depends-on:
 allocsa
+alloca
 
 configure.ac:
 gt_FUNC_SETENV




reply via email to

[Prev in Thread] Current Thread [Next in Thread]