develooper Front page | perl.perl5.porters | Postings from May 2013

Re: [perl #118159] SvTRUE changed behavior in 5.18

Thread Previous | Thread Next
From:
Tony Cook
Date:
May 25, 2013 04:05
Subject:
Re: [perl #118159] SvTRUE changed behavior in 5.18
Message ID:
20130525040521.GC7170@mars.tony.develop-help.com
On Fri, May 24, 2013 at 01:42:52PM -0700, Greg Lindahl wrote:
> # New Ticket Created by  Greg Lindahl 
> # Please include the string:  [perl #118159]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=118159 >
> 
> 
> 
> This is a bug report for perl from lindahl@pbm.com,
> generated with the help of perlbug 1.39 running under perl 5.18.0.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> In upgrading the blekko search engine backend to Perl 5.18.0, one of
> our engineers noticed a change in the behavior in SvTRUE.
> 
> $ perl -MScalar::Util=dualvar -le 'print $]; $a = dualvar 1, ""; print $a ? "true" : "false";'
> 5.008008
> false
> 
> $ perl -MScalar::Util=dualvar -le 'print $]; $a = dualvar 1, ""; print $a ? "true" : "false";'
> 5.016000
> false
> 
> $ perl -MScalar::Util=dualvar -le 'print $]; $a = dualvar 1, ""; print $a ? "true" : "false";'
> 5.018000
> true
> 
> Is this intended? We were surprised.
> 
> It became visible to us because some Graphics Magik functions return
> an XS-generated return value which is typically 1 and '' (indicating 1
> image extracted and no error), and our code then uses "if" to test for
> an error.
> 
> Graphics Magick	doesn't	document this return value and does not	test it.
> 
> We don't have an opinion about what behavior is correct here, but it
> is surprising that something so fundamental would change.

This appears to have changed in 4bac9ae4.

Previously SvTRUE was:

#  define SvTRUE(sv) (                                         \
    !sv                                                                \
    ? 0                                                                \
    :    SvPOK(sv)                                             \
       ?   (({XPV *nxpv = (XPV*)SvANY(sv);                     \
            nxpv &&                                            \
            (nxpv->xpv_cur > 1 ||                              \
             (nxpv->xpv_cur && *(sv)->sv_u.svu_pv != '0')); }) \
            ? 1                                                \
            : 0)                                               \
       :                                                       \
           SvIOK(sv)                                           \
           ? SvIVX(sv) != 0                                    \
           :   SvNOK(sv)                                       \
               ? SvNVX(sv) != 0.0                              \
               : sv_2bool(sv) )

which checks *only* the PV part of the scalar if the scalar is flagged
as a PV.

The new version, largely in SvTRUE_common():

#define SvTRUE_common(sv,fallback) (			\
      !SvOK(sv)						\
	? 0						\
    : (SvFLAGS(sv) & (SVf_POK|SVf_IOK|SVf_NOK))		\
	? (   (SvPOK(sv) && SvPVXtrue(sv))		\
	   || (SvIOK(sv) && SvIVX(sv) != 0)		\
	   || (SvNOK(sv) && SvNVX(sv) != 0.0))		\
    : (fallback))

checks each part of the SV until it finds a true part (if any).

Tony

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About