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: Derek Robert Price
Subject: Re: [Bug-gnulib] Re: fnmatch.c includes alloca.h conditionally?
Date: Tue, 04 May 2004 17:48:56 -0400
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040413

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks for getting to this, Paul!

Mostly this looks great to me, but you left out the HAVE_ALLOCA
definitions from my patch.  I've attached a revised version.  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.

Incidentally, lib/getdate.y only includes <alloca.h> and never calls
alloca(), so maybe it is better to remove the #include from getdate.y
rather than updating the module dependency in modules/getdate?

2004-05-04  Paul Eggert  <address@hidden>
        Derek Price  <address@hidden>

    * 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.
     * lib/alloca_.h: Define HAVE_ALLOCA when a native version is found.
     Don't try to source the system alloca.h since it will not be
found and
     to prevent recursively including its replacement.

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

Derek

Paul Eggert wrote:

>I looked into this and found a few more problems.  Many files don't
>include <alloca.h> first, which is needed on AIX.  Rather than fix
>them all, I fixed alloca.h so that it needn't be included first on
>AIX.  (Not that I have an AIX host to test this on....)  Also, getdate
>and setenv include <alloca.h> unconditionally without depending on the
>alloca module.  Here's a proposed patch.


- --
                *8^)

Email: address@hidden

Get CVS support at <http://ximbiot.com>!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFAmA/GLD1OTBfyMaQRAptQAKC37RQxo+5DF/QogCcpSzq1HLxyVwCdGDO9
epVqgcedLh4FgzbWXQUDaVc=
=rK7C
-----END PGP SIGNATURE-----

Index: lib/alloca.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/lib/alloca.c,v
retrieving revision 1.13
diff -u -p -r1.13 alloca.c
--- lib/alloca.c        24 Nov 2003 21:38:44 -0000      1.13
+++ lib/alloca.c        4 May 2004 21:15:51 -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 -u -p -r1.4 alloca_.h
--- lib/alloca_.h       9 Aug 2003 08:57:49 -0000       1.4
+++ lib/alloca_.h       4 May 2004 21:15:51 -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,22 @@
        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
+# define HAVE_ALLOCA
+#elif defined _AIX
+# define alloca __alloca 
+# define HAVE_ALLOCA
+#elif defined _MSC_VER
+# include <malloc.h>
+# define alloca _alloca
+# define HAVE_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 -u -p -r1.26 fnmatch.c
--- lib/fnmatch.c       14 Jan 2004 22:15:48 -0000      1.26
+++ lib/fnmatch.c       4 May 2004 21:15:52 -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 -u -p -r1.80 regex.c
--- lib/regex.c 10 Sep 2003 06:18:22 -0000      1.80
+++ lib/regex.c 4 May 2004 21:15:58 -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 -u -p -r1.5 alloca.m4
--- m4/alloca.m4        8 Sep 2003 22:58:10 -0000       1.5
+++ m4/alloca.m4        4 May 2004 21:15:58 -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
@@ -20,13 +20,17 @@ AC_DEFUN([gl_FUNC_ALLOCA],
   # Define an additional variable used in the Makefile substitution.
 
   AC_EGREP_CPP([Need own alloca], [
-#if defined __GNUC__ || defined _MSC_VER || !HAVE_ALLOCA_H
+#if defined __GNUC__ || defined _AIX || defined _MSC_VER || !HAVE_ALLOCA_H
   Need own alloca
 #endif
     ],
     ALLOCA_H=alloca.h,
     ALLOCA_H=)
   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 -u -p -r1.5 getdate
--- modules/getdate     31 Mar 2004 07:20:49 -0000      1.5
+++ modules/getdate     4 May 2004 21:15:58 -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 -u -p -r1.5 setenv
--- modules/setenv      20 Jan 2004 17:05:34 -0000      1.5
+++ modules/setenv      4 May 2004 21:15:58 -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]