[revisiting another old thread; see here for the original patch] http://lists.gnu.org/archive/html/autoconf-patches/2009-09/msg00076.html
According to Paolo Bonzini on 9/16/2009 5:39 PM: > On 09/16/2009 11:37 PM, Eric Blake wrote: >> It gives a reduction >> in size by using more AC_CHECK_FUNCS_ONCE instead of inline function >> checks, >> and can reduce forks by using a literal rather than a shell variable >> in more >> places; particularly when doing AC_REPLACE_FUNCS([a b]). > > No, this breaks if AC_REPLACE_FUNCS is used within a conditional. > However, since we do not support (pfew...) non-literal $1, using > AC_CHECK_FUNC to reduce forks is fine now that we are using shell > functions, like > > m4_define([_AC_REPLACE_FUNC], > [AC_CHECK_FUNC([$1, [AC_LIBOBJ([$1])]) > ]) > > This should expand to just four lines per function. It won't give a > size reduction but it would noticeably reduce forks. Hmm. I originally read your reply as a rejection of the entire patch; but kept it marked in my inbox to revisit. Now, on closer re-reading, I see that you were only worried about the change in semantics caused by using AC_CHECK_FUNC_ONCE causing an unconditional check for a function where it used to be guarded by shell conditionals. In which case, your proposed helper function is indeed no semantic change, fewer forks, but not as good at code reduction. So, here's what I'm looking at pushing, after testing (gnulib already overrides AC_REPLACE_FUNCS, so this will probably require a followup patch there before most gnulib-using projects see a similar improvement). By the way, AC_CHECK_FUNC is insufficient (it doesn't define HAVE_FUNC); but AC_CHECK_FUNCS generates efficient output with single-literal input. But I may decide to use the former with a copy of the HAVE_FUNC logic, if that proves to be faster at m4 time than the current approach of making AC_CHECK_FUNCS is acting on a single-element list. > > I should polish up my patches introducing AC_FOREACH, but that would be > after 2.65. Or even after 2.66? It looks like we both have a bad habit of starting experiments then forgetting to push them upstream. ;) -- Eric Blake [email protected] +1-801-349-2682 Libvirt virtualization library http://libvirt.org
From d26822c06539122ddb0f78858e31bbb8e2a4843c Mon Sep 17 00:00:00 2001 From: Eric Blake <[email protected]> Date: Wed, 9 Sep 2009 08:32:46 -0600 Subject: [PATCH] Optimize AC_REPLACE_FUNCS. * lib/autoconf/functions.m4 (_AC_REPLACE_FUNC): New helper macro. (AC_REPLACE_FUNCS): Use it to check for functions only once, and to pass literal rather than shell variable to AC_LIBOBJ. Signed-off-by: Eric Blake <[email protected]> --- ChangeLog | 7 +++++++ lib/autoconf/functions.m4 | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8d4ed1..464bf85 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2010-02-25 Eric Blake <[email protected]> + Optimize AC_REPLACE_FUNCS. + * lib/autoconf/functions.m4 (_AC_REPLACE_FUNC): New helper macro. + (AC_REPLACE_FUNCS): Use it to check for functions only once, and + to pass literal rather than shell variable to AC_LIBOBJ. + +2010-02-25 Eric Blake <[email protected]> + Properly quote AC_PREREQ during autoupdate. * lib/autoconf/general.m4 (AC_PREREQ): Follow consistent quoting style for AC_PREREQ. diff --git a/lib/autoconf/functions.m4 b/lib/autoconf/functions.m4 index 24dcf86..f2e6ad6 100644 --- a/lib/autoconf/functions.m4 +++ b/lib/autoconf/functions.m4 @@ -116,12 +116,21 @@ m4_define([_AC_FUNCS_EXPANSION], ]) +# _AC_REPLACE_FUNC(FUNCTION) +# -------------------------- +# If FUNCTION exists, define HAVE_FUNCTION; else add FUNCTION.c +# to the list of library objects. FUNCTION must be literal. +m4_define([_AC_REPLACE_FUNC], +[AC_CHECK_FUNCS([$1], [], [AC_LIBOBJ([$1])])]) + # AC_REPLACE_FUNCS(FUNCTION...) # ----------------------------- +# For each FUNCTION in the whitespace separated list, perform the +# equivalent of AC_CHECK_FUNC, then call AC_LIBOBJ if the function +# was not found. AC_DEFUN([AC_REPLACE_FUNCS], -[m4_map_args_w([$1], [AC_LIBSOURCE(], [.c)])]dnl -[AC_CHECK_FUNCS([$1], , [_AC_LIBOBJ($ac_func)]) -]) +[m4_map_args_w([$1], [_AC_REPLACE_FUNC(], [) +])]) # AC_TRY_LINK_FUNC(FUNC, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND) -- 1.6.6.1
signature.asc
Description: OpenPGP digital signature
