Trying to understand if the following patch is needed in libreplace

Timur I. Bakeyev timur at com.bat.ru
Wed Feb 13 08:20:47 MST 2013


Hi, Richard!

I see it defined in autoconf-2.69/m4sugar/m4sh.m4:

# AS_TR_SH(EXPRESSION)
# --------------------
# Transform EXPRESSION into a valid shell variable name.
# sh/m4 polymorphic.
# Be sure to update the definition of `$as_tr_sh' if you change this.

It then used in this macro in libreplace:

dnl check if the prototype in the header matches the given one
dnl
AC_VERIFY_C_PROTOTYPE(prototype,functionbody,[IF-TRUE].[IF-FALSE],[extraheaders])
AC_DEFUN(AC_VERIFY_C_PROTOTYPE,
[AC_CACHE_CHECK([for prototype $1], AS_TR_SH([ac_cv_c_prototype_$1]),
         AC_COMPILE_IFELSE([AC_LANG_SOURCE([
                    AC_INCLUDES_DEFAULT
                    $5
                    $1
                    {
                            $2
                    }
          ])],[
                    eval AS_TR_SH([ac_cv_c_prototype_$1])=yes
          ],[
                    eval AS_TR_SH([ac_cv_c_prototype_$1])=no
          ])
)
AS_IF([eval test \$AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
])

It happened to be used only in few places and seems that no one paid
attention to the results(i.e. bogus behaviour of the macro gave appropriate
results, as it happens a lot in autoconf).

I was puzzled  why function, which exists in FreeBSD wasn't recognized
right an that brought me down to this macro and resulting SH code it
produces.

AC_VERIFY_C_PROTOTYPE([struct group *getgrent_r(struct group *src, char
*buf, int buflen)]

For example generates:

if ac_fn_c_try_compile "$LINENO"; then :

                    eval `$as_echo "ac_cv_c_prototype_struct group
*getgrent_r(struct group *src, char *buf, int buflen)" | $as_tr_sh`=yes

else

                    eval `$as_echo "ac_cv_c_prototype_struct group
*getgrent_r(struct group *src, char *buf, int buflen)" | $as_tr_sh`=no

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

fi
eval ac_res=\$`$as_echo "ac_cv_c_prototype_struct group *getgrent_r(struct
group *src, char *buf, int buflen)" | $as_tr_sh`
       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }

if test $`$as_echo "ac_cv_c_prototype_struct group *getgrent_r(struct group
*src, char *buf, int buflen)" | $as_tr_sh` = yes; then :

$as_echo "#define SOLARIS_GETGRENT_R 1" >>confdefs.h

fi


Please note the last 'if' statement. It useless, as it produces smth.
like(it's another function snippet but they all the same):

+ test
$ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_
= yes

We get the name of the variable right, but we need to get it's value to see
if it is "yes' or 'no'. Hence we need to evaluate the obtained expression:

+ eval test
$ac_cv_c_prototype_struct_passwd_pgetpwent_r_struct_passwd_psrc__char_pbuf__int_buflen_
= yes
+ test yes = yes

The bottom like is - WAF may be hard to grasp, but at least it won't let
you silently stay with bogus code like this.

With regards,
Timur Bakeyev.


On Tue, Feb 12, 2013 at 9:16 PM, Richard Sharpe <realrichardsharpe at gmail.com
> wrote:

> Hi folks,
>
> I have come across the following patch from Timur in the FreeBSD ports
> collection:
>
> rsharpe-bsd# more patch-lib__replace__libreplace_macros.m4
> --- ./lib/replace/libreplace_macros.m4.orig     2011-10-12
> 01:38:14.000000000 +0200
> +++ ./lib/replace/libreplace_macros.m4  2011-10-12 01:39:36.000000000 +0200
> @@ -298,7 +298,7 @@
>                 eval AS_TR_SH([ac_cv_c_prototype_$1])=no
>         ])
>  )
> -AS_IF([test $AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
> +AS_IF([eval test \$AS_TR_SH([ac_cv_c_prototype_$1]) = yes],[$3],[$4])
>  ])
>
>  AC_DEFUN(LIBREPLACE_PROVIDE_HEADER,
>
> Where is AS_TR_SH defined? Is it possible that we actually need the
> change more generally?
>
> --
> Regards,
> Richard Sharpe
> (何以解憂?唯有杜康。--曹操)
>


More information about the samba-technical mailing list