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

[perl #118159] SvTRUE changed behavior in 5.18

Thread Previous | Thread Next
From:
Father Chrysostomos via RT
Date:
May 25, 2013 18:20
Subject:
[perl #118159] SvTRUE changed behavior in 5.18
Message ID:
rt-3.6.HEAD-2650-1369506031-1881.118159-15-0@perl.org
On Fri May 24 21:06:07 2013, tonyc wrote:
> 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
> 

I can’t believe I missed that when reviewing the patch in question. 
Traditionally, truth was based solely on stringification.  The
examination of the SvIVX and SvNVX slots was for those cases where there
was no string already and it could be deduced from IVX or NVX whether it
would stringify as "0" or no (bugs with -0 aside).

So this seems like a bug to me.  Should we change it back?

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=118159

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