develooper Front page | perl.perl5.porters | Postings from October 2016

Re: Encode.xs and sv_force_normal

Thread Previous
From:
pali
Date:
October 26, 2016 10:19
Subject:
Re: Encode.xs and sv_force_normal
Message ID:
20161026101927.GA32480@pali
On Wednesday 26 October 2016 09:37:15 Dave Mitchell wrote:
> On Tue, Oct 25, 2016 at 06:44:06PM +0200, pali@cpan.org wrote:
> > On Tuesday 25 October 2016 06:48:09 Father Chrysostomos wrote:
> > > On Oct 23, 2016, at 12:42 PM, pali@cpan.org wrote:
> > > > For me it makes sense to call SvGETMAGIC/SvSETMAGIC so $/ will be
> > > > supported too...
> > > 
> > > That makes sense to me, too.
> > 
> > Ok. Now I added SvGETMAGIC(sv) before SvPOK(sv) and SvSETMAGIC(sv) after 
> > SvUTF8_on(sv) (resp. SvUTF8_off(sv)).
> > 
> > I created tests for tied scalars, but in perl 5.14 that tests are 
> > failing. They pass under bleed perl.
> > 
> > Now I looked deeply and it looks like that perl 5.14 does *not* set 
> > SvPOK flag for string-tied scalars :-( After calling _utf8_on 
> > Devel::Peek tell me this:
> > 
> > SV = PVMG(0x1070220) at 0x10eb3d0
> >   REFCNT = 1
> >   FLAGS = (PADMY,GMG,SMG,RMG,pPOK)
> > ...
> > 
> > It is some know bug in older perls, that SvPOK is not set after calling 
> > SvGETMAGIC on string tied scalars?
> > 
> > Or should I use SvPOKp(sv)? Because pPOK is set!
> 
> In older perls, get magic would only set the private versions of the
> flags, to indicate "this now has a string/integer/float value, but it's not
> really a string/integer/float".  perl 5.18.0 removed that distinction and
> sets both flags. Now the only distinction between the private and public
> flags is whether a conversion is lossless:
> 
>     $ perl -MDevel::Peek -e'$x = 1; $y = $x + 1.1; Dump $x'
>       REFCNT = 1
>       FLAGS = (IOK,NOK,pIOK,pNOK)
>       IV = 1
>       NV = 1
> 
> 
>     $ perl -MDevel::Peek -e'$x = 1.1; $y = $x + 0; Dump $x'
>       REFCNT = 1
>       FLAGS = (NOK,pIOK,pNOK)
>       IV = 1
>       NV = 1.1
> 
> 
> 1 is accurately representable as 1.0, but 1.1 is not accurately
> representable as 1

Now I found it in perlguts:
http://perldoc.perl.org/perlguts.html#What%27s-Really-Stored-in-an-SV%3f

So to supporting older versions of perl (which Encode supports) it is
really needed to check private flags. I will change that SvPOK(sv) to
SvPOKp(sv) to support magic variables.

Thread Previous


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