bug-autoconf
[Top][All Lists]
Advanced

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

Re: autoconf-2.69 pkgsrc patch


From: Thomas Klausner
Subject: Re: autoconf-2.69 pkgsrc patch
Date: Sat, 15 Sep 2012 13:15:32 +0200

On Fri, Sep 14, 2012 at 08:13:02AM -0600, Eric Blake wrote:
> > @@ -369,6 +369,8 @@ AC_CACHE_CHECK([for alloca], ac_cv_func_
> >  # ifdef _MSC_VER
> >  #  include <malloc.h>
> >  #  define alloca _alloca
> > +# elif defined(__NetBSD__) || defined(__FreeBSD__) || 
> > defined(__DragonFly__) || defined(__OpenBSD__)
> > +#   include <stdlib.h>
> 
> The autoconf philosophy is to avoid system-specific defines, and instead
> test features.

The context above starts with a test for _MSC_VER :)

> I would rather do one of two things - identify the
> specific feature (that is, write a test that fails if <stdlib.h> is not
> included, and define something like FUNC_ALLOCA_REQUIRES_STDLIB), or
> make the use of <stdlib.h> unconditional (does it hurt any other
> platform, other than the possibility of namespace pollution?).

I'm not sure I understand this part completely:
> identify the
> specific feature (that is, write a test that fails if <stdlib.h> is not
> included, and define something like FUNC_ALLOCA_REQUIRES_STDLIB)

I think a test should check if alloca is defined in stdlib.h, and if
so, prefer that.

About stdlib.h, including it unconditionally is already recommended by
the sample code in the documentation (see below):

> Also, I'm worried that there is some matching documentation that will
> need touching up.
> 
> Can you please investigate these two points, and resubmit the patch
> accordingly?

You're right, there's a big section in autoconf.texi about that which
needs to be changed. It currently says:

-- begin quote --
@c @caindex working_alloca_h
Check how to get @code{alloca}.  Tries to get a builtin version by
checking for @file{alloca.h} or the predefined C preprocessor macros
@code{__GNUC__} and @code{_AIX}.  If this macro finds @file{alloca.h},
it defines @code{HAVE_ALLOCA_H}.

If those attempts fail, it looks for the function in the standard C
library.  If any of those methods succeed, it defines
@code{HAVE_ALLOCA}.  Otherwise, it sets the output variable
@code{ALLOCA} to @address@hidden@}alloca.o} and defines
@code{C_ALLOCA} (so programs can periodically call @samp{alloca (0)} to
garbage collect).  This variable is separate from @code{LIBOBJS} so
multiple programs can share the value of @code{ALLOCA} without needing
to create an actual library, in case only some of them use the code in
@code{LIBOBJS}.  The @address@hidden@}} prefix serves the same
purpose as in @code{LIBOBJS} (@pxref{AC_LIBOBJ vs LIBOBJS}).

This macro does not try to get @code{alloca} from the System V R3
@file{libPW} or the System V R4 @file{libucb} because those libraries
contain some incompatible functions that cause trouble.  Some versions
do not even contain @code{alloca} or contain a buggy version.  If you
still want to use their @code{alloca}, use @code{ar} to extract
@file{alloca.o} from them instead of compiling @file{alloca.c}.

Source files that use @code{alloca} should start with a piece of code
like the following, to declare it properly.

@example
@group
#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
-- end quote --

That code is riddled with ifdefs :(

Do you have suggestions on how to improve the situation?
 Thomas



reply via email to

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