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

Re: Encode.xs and sv_force_normal

Thread Previous | Thread Next
From:
Dave Mitchell
Date:
October 26, 2016 08:37
Subject:
Re: Encode.xs and sv_force_normal
Message ID:
20161026083715.GQ3128@iabyn.com
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

-- 
In England there is a special word which means the last sunshine
of the summer. That word is "spring".

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