Front page | perl.perl5.porters |
Postings from May 2008
Re: [perl #53244] perl-5.10.0-33733 assertion with JSON::XS-2.2
Thread Previous
|
Thread Next
From:
Nicholas Clark
Date:
May 9, 2008 15:22
Subject:
Re: [perl #53244] perl-5.10.0-33733 assertion with JSON::XS-2.2
Message ID:
20080509222249.GT6780@plum.flirble.org
On Sat, Apr 26, 2008 at 08:01:42AM +0200, Marc Lehmann wrote:
> On Fri, Apr 25, 2008 at 10:42:57PM -0700, Jan Dubois <jand@activestate.com> wrote:
> > What is the meaning of SvCUR() if your SV is just SvROK() and the PVX
> > slot contains a reference to another SV instead of a string buffer?
>
> It gives me CUR:
>
> > perl -MDevel::Peek -e "$a='foo'; $a=\$b; Dump $a"
> > CUR = 0
>
> > SvCUR() is supposed to return the "length of the string in the SV",
> > but when SvPOK() is not set, then there is no string in the SV, so
> > the concept of a current length doesn't make any sense.
>
> Well, PV's can contain some memory pointer, a length and the currently used
> length of this memory range.
>
> Lots of modules upgrade to pv, grow to get some memory, and only then set
> svpok for example.
>
> > expect the semantics of SvCUR() to be in this case? Note that SvCUR()
>
> Just give me CUR.
That's not what SvCUR() is about. It's direct access to the structure.
If you want the length, you need sv_len()
>
> > is not actually the length of the string if you would print the SV,
> > which would print " SCALAR(0x182a32c)" and not the empty string "".
>
> You said there is no string in the pv, so how can it suddenly have a
> length? :)
> In any case, what I was pointing out that this simply was a regression. As I
> said, when perl changes the meaning of SvCUR from "accesses CUR" to "asserts
> unless some private flag is set", then I will happily oblige.
The documentation certainly needs correcting.
> I don't think this is a singular case, though, and I see no wrong ina
> cecssing the CUR slot of a PV when it exists.
But it won't always contain a value that bears any relation to the length
that SvPV() and variants can return. For example:
$ perl -MDevel::Peek -e '$a = "Long"; $a = 4; Dump $a'
SV = PVIV(0x802020) at 0x800bb8
REFCNT = 1
FLAGS = (IOK,pIOK)
IV = 4
PV = 0x201ad0 "Long"\0
CUR = 4
LEN = 8
or with overloaded references:
$ cat ~/test/overload.pl
#!perl -w
use strict;
package String;
use overload '""', sub { ${$_[0]} };
package main;
use Devel::Peek;
my $ref = "";
$ref = \do {my $a = "***Text***"; $a};
bless $ref, "String";
Dump $ref;
print "$ref\n";
Dump $ref;
__END__
$ perl ~/test/overload.pl
SV = PV(0x801060) at 0x800c0c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,ROK,OVERLOAD)
RV = 0x800168
SV = PVMG(0x80ba60) at 0x800168
REFCNT = 1
FLAGS = (OBJECT,POK,pPOK)
IV = 0
NV = 0
PV = 0x207270 "***Text***"\0
CUR = 10
LEN = 12
STASH = 0x800bac "String"
PV = 0x800168 ""
CUR = 0
LEN = 0
***Text***
SV = PV(0x801060) at 0x800c0c
REFCNT = 1
FLAGS = (PADBUSY,PADMY,ROK,OVERLOAD)
RV = 0x800168
SV = PVMG(0x80ba60) at 0x800168
REFCNT = 1
FLAGS = (OBJECT,POK,pPOK)
IV = 0
NV = 0
PV = 0x207270 "***Text***"\0
CUR = 10
LEN = 12
STASH = 0x800bac "String"
PV = 0x800168 ""
CUR = 0
LEN = 0
(both those are 5.8.8)
Nicholas Clark
Thread Previous
|
Thread Next