ac-archive-maintainers
[Top][All Lists]
Advanced

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

Re: Contributions for ac-archive


From: Guido Draheim
Subject: Re: Contributions for ac-archive
Date: Sat, 25 Jan 2003 05:37:35 -0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; de-AT; rv:1.1) Gecko/20020826

Scott Pakin schrieb:
Guido,

Here are three simple macros that I wrote recently that other people
might be interested in, too.

    * AX_FUNC_MALLOC_ALIGNED checks whether malloc() returned page-aligned
      address if more than a page of memory is requested (a la certain BSD
      flavors).

    * AX_FUNC_POSIX_MEMALIGN_WORKS verifies that posix_memalign() is not
      sanity-checking the wrong parameter (as is the case in glibc 2.2.5).

    * AX_REQUIRE_ONE_FUNC is similar to AC_CHECK_FUNCS but ensures that
      at least one of the functions is found.

More to come....

-- Scott

Thanks Scott,

those look great and quite useful in some places. As for stylistics:

(a) you've picked the AX_-prefix for the macros but the various
    dedicated variables (like for CACHE_CHECK) there is ac_cv_
(b) what's the result of m4_define on $1 in ONE_FUNC ?
    wouldn't that be a very long string for the cachevar?
(c) is it worth that ONE_FUNC ACTION-IF-FOUND can discover which one
    has been found first? Your example shows the usage with the
    IF-NOT-FOUND case which might be all too-usual, but: do you have
    an example that actually uses action-if-found?
(d) the func_malloc tests use a default for cross-compiling to
    be just "no". What about adding an argument to specify a
    default value for the cachevar when the state can not be
    discovered? ah, I see, almost impossible because...
(e) they are in fact combined with AC_DEFINE - what about making
    up action-if and action-if-not where the default action is
    AC_DEFINE ? would that make for some flexibility? Well, I am
    not sure here, actually...
(f) I am not sure whehter they should be named AX_FUNC_ as is, as
    they do not provide the functionality. They are CHECK functions
    in a way. Also, the AC_DEFINE value is not quite guessable
    from the macro name. Hmmm, looking into the main autoconf parts,
    I guess it would be better to choose this scheme:
    (1) AX_FUNC_POSIX_MEMALIGN
        AC_DEFINE(HAVE_POSIX_MEMALIGN,
        [whether your system has a working `posix_memalign' function])
    (2) AX_CHECK_PAGE_ALIGNED_MALLOC
        AC_DEFINE(HAVE_PAGE_ALIGNED_MALLOC,.... (etc as is))

WDYT, have fun, guido



------------------------------------------------------------------------

dnl @synopsis AX_FUNC_MALLOC_ALIGNED
dnl
dnl Some operating systems (generally, BSD Unix variants) lack a
dnl posix_memalign function, a memalign function, and a working (meaning,
dnl the memory can be freed) valloc function.  To make up for it, the
dnl malloc function promises to return page-aligned addresses if more than
dnl one page's worth of memory is allocated.  AX_FUNC_MALLOC_ALIGNED
dnl checks for this condition and defines HAVE_PAGE_ALIGNED_MALLOC if the
dnl condition holds.
dnl dnl As an aside, note that valloc'd memory cannot safely be freed on all
dnl operating systems.  (Again, some flavors of BSD are the troublemakers.)
dnl It's best to avoid using valloc in favor of posix_memalign, memalign,
dnl or an aligned malloc as detected by AX_FUNC_MALLOC_ALIGNED.
dnl dnl Caveat: AX_FUNC_MALLOC_ALIGNED takes a probabalistic approach. If 100
dnl calls to malloc all return page-aligned addresses, it assumes that all
dnl calls will behave likewise.  It is therefore possible -- albeit
dnl extremely unlikely -- that AX_FUNC_MALLOC_ALIGNED can return a false
dnl positive.
dnl dnl @version $Id: $
dnl @author Scott Pakin <address@hidden>
dnl
AC_DEFUN([AX_FUNC_MALLOC_ALIGNED],
[AC_CACHE_CHECK([if large mallocs guarantee page-alignment],
  [ac_cv_func_malloc_aligned],
  [AC_TRY_RUN([
#include "confdefs.h"

int main()
{
  int pagesize = getpagesize();
  int i;

  for (i=0; i<100; i++)
    if ((unsigned long)malloc(pagesize+1) & (pagesize-1))
      return 1;
  return 0;
}
              ],
     [ac_cv_func_malloc_aligned=yes],
     [ac_cv_func_malloc_aligned=no],
     [ac_cv_func_malloc_aligned=no])
  ])
if test "$ac_cv_func_malloc_aligned" = yes ; then
  AC_DEFINE([HAVE_PAGE_ALIGNED_MALLOC], [1],
    [Define if `malloc'ing more than one page always returns a page-aligned 
address.])
fi
])



------------------------------------------------------------------------

dnl @synopsis AX_FUNC_POSIX_MEMALIGN_WORKS
dnl
dnl dnl Some versions of posix_memalign (notably glibc 2.2.5) incorrectly
dnl apply their power-of-two check to the size argument, not the alignment
dnl argument.  AX_FUNC_POSIX_MEMALIGN_WORKS defines POSIX_MEMALIGN_WORKS
dnl if the power-of-two check is correctly applied to the alignment
dnl argument.
dnl dnl @version $Id: $
dnl @author Scott Pakin <address@hidden>
dnl
AC_DEFUN([AX_FUNC_POSIX_MEMALIGN_WORKS],
[AC_CACHE_CHECK([if posix_memalign works],
  [ac_cv_func_posix_memalign_works],
  [AC_TRY_RUN([
#include <stdlib.h>

int
main ()
{
  void *buffer;

  /* Some versions of glibc incorrectly perform the alignment check on
   * the size word. */
  return posix_memalign (&buffer, sizeof(void *), 123);
}
    ],
    [ac_cv_func_posix_memalign_works=yes],
    [ac_cv_func_posix_memalign_works=no],
    [ac_cv_func_posix_memalign_works=no])])
if test "$ac_cv_func_posix_memalign_works" = "yes" ; then
  AC_DEFINE([POSIX_MEMALIGN_WORKS], [1],
    [Define if the `posix_memalign' function correctly checks its `alignment'
     and `size' parameters.])
fi
])



------------------------------------------------------------------------

dnl @synopsis AX_REQUIRE_ONE_FUNC (FUNCTION..., [ACTION-IF-ANY-FOUND], 
[ACTION-IF-NONE-FOUND])
dnl
dnl AX_REQUIRE_ONE_FUNC is a simple wrapper for AC_CHECK_FUNCS.  It calls
dnl AC_CHECK_FUNCS on the list of functions named in the first argument,
dnl then invokes ACTION-IF-ANY-FOUND if at least one of the functions
dnl exists or ACTION-IF-NONE-FOUND if none of the functions exist.
dnl
dnl Here's an example:
dnl dnl AX_REQUIRE_ONE_FUNC([posix_memalign memalign valloc], ,
dnl       [AC_MSG_ERROR([unable to allocate page-aligned memory])])
dnl dnl @version $Id: $
dnl @author Scott Pakin <address@hidden>
dnl
AC_DEFUN([AX_REQUIRE_ONE_FUNC],
[m4_define([ac_1func_cv], [AS_TR_SH(ac_cv_func_any_$1)])
AC_CACHE_VAL([ac_1func_cv],
  [ac_1func_cv=no
   AC_CHECK_FUNCS([$1], [ac_1func_cv="$ac_1func_cv $ac_func"])])
AS_IF([test "$ac_1func_cv" = "no"],
  [$3],
  [ac_1func_cv=`echo $ac_1func_cv | sed 's/^no //'`
   $2])
])






reply via email to

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