bug-gnulib
[Top][All Lists]
Advanced

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

[bug-gnulib] Re: getdate don't need alloca


From: Bruno Haible
Subject: [bug-gnulib] Re: getdate don't need alloca
Date: Sat, 18 Dec 2004 17:05:35 +0100
User-agent: KMail/1.5

Simon Josefsson wrote:
> So could getdate depend on alloca-opt instead of alloca?

Yes, this would make sense. bison already has code for using malloc()
when there is no alloca(). This is certainly more efficient than using
the malloc-based alloca() emulation in alloca.c.

Paul Eggert wrote:
> I don't understand how alloca-opt works.  Doesn't it invoke
> AC_FUNC_ALLOCA?  And doesn't that mean that the user must put
> $(ALLOCA) into ..._LIBADD?  And won't that break on hosts that don't
> have alloca?
>
> Also, with alloca-opt, isn't a program supposed to inspect HAVE_ALLOCA
> before attempting to invoke alloca?

Yes. alloca-opt means that the program uses alloca() if and only if
HAVE_ALLOCA is true.

gl_FUNC_ALLOCA invokes AC_FUNC_ALLOCA already.

There's no need to add $(ALLOCA) into ..._LIBADD since alloca.c is not used.

> Since it includes <alloca.h>, _ALLOCA_H will be defined, so
> it will use alloca, even though alloca doesn't exist.

Ouch, yes. I propose the appended patch.

Simon Josefsson wrote:
> given this I think there are three options:

I think there are three separate issues, which can be addressed separately:

- The bison output uses _ALLOCA_H as meaning "there is an alloca.h file and
  it defines alloca()". But ours doesn't define alloca. I propose the
  appended patch.

- The bison output uses YYSTACK_USE_ALLOCA, no autoconf macro, to decide
  whether to use alloca(). Since gnulib uses autoconf, I propose to feed
  the result of our autoconf macro into bison:

+ /* Tell the bison-generated code when alloca() should be used.  */
+ #if HAVE_ALLOCA
+ # define YYSTACK_USE_ALLOCA 1
+ #endif

- bison generated output does not need to use alloca.c; therefore I propose
  to make the 'getdate' module depend on 'alloca-opt' instead of 'alloca'.

Paul Eggert wrote:
> Perhaps someting like the following patch would do the trick?
>
> --- getdate.y.~1.91.~ 2004-12-08 14:01:51 -0800
> +++ getdate.y 2004-12-17 23:42:11 -0800
> @@ -36,7 +36,13 @@
>
>  #include "getdate.h"
>
> -#include <alloca.h>
> +#if HAVE_ALLOCA
> +# include <alloca.h>
> +# define YYMAXDEPTH \
> +   ((4032 - sizeof (YYSTYPE)) / (sizeof (short) + sizeof (YYSTYPE)))
> +#else
> +# define YYSTACK_USE_ALLOCA 0
> +#endif
>
>  /* Since the code of getdate.y is not included in the Emacs executable
>     itself, there is no need to #define static in this file.  Even if

Yes, I agree this would be good. Taken together, this yields

*** getdate.y   8 Dec 2004 22:25:43 -0000       1.91
--- getdate.y   18 Dec 2004 16:06:05 -0000
***************
*** 37,42 ****
--- 37,51 ----
  #include "getdate.h"
  
  #include <alloca.h>
+ /* Tell the bison-generated code when alloca() should be used and, if so,
+    what is the maximum safe argument to alloca().  */
+ #if HAVE_ALLOCA
+ # define YYSTACK_USE_ALLOCA 1
+ # define YYMAXDEPTH \
+    ((4032 - sizeof (YYSTYPE)) / (sizeof (short) + sizeof (YYSTYPE)))
+ #else
+ # define YYSTACK_USE_ALLOCA 0
+ #endif
  
  /* Since the code of getdate.y is not included in the Emacs executable
     itself, there is no need to #define static in this file.  Even if


Bruno


diff -c -3 -r1.6 alloca_.h
*** alloca_.h   11 Nov 2004 09:25:55 -0000      1.6
--- alloca_.h   18 Dec 2004 15:49:11 -0000
***************
*** 22,29 ****
     declarations.  Thanks to AIX.  Therefore we include it right after
     "config.h", not later.  */
  
! #ifndef _ALLOCA_H
! # define _ALLOCA_H
  
  /* alloca (N) returns a pointer to N bytes of memory
     allocated on the stack, which will last until the function returns.
--- 22,29 ----
     declarations.  Thanks to AIX.  Therefore we include it right after
     "config.h", not later.  */
  
! #ifndef _GNULIB_ALLOCA_H
! # define _GNULIB_ALLOCA_H
  
  /* alloca (N) returns a pointer to N bytes of memory
     allocated on the stack, which will last until the function returns.
***************
*** 51,54 ****
  void *alloca (size_t);
  #endif
  
! #endif /* _ALLOCA_H */
--- 51,54 ----
  void *alloca (size_t);
  #endif
  
! #endif /* _GNULIB_ALLOCA_H */





reply via email to

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