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

Re: Confusion about SvANY and Devel::Peek output

Thread Previous | Thread Next
From:
demerphq
Date:
March 20, 2013 15:12
Subject:
Re: Confusion about SvANY and Devel::Peek output
Message ID:
CANgJU+VsPW5FQfPbPpbxeeht7ts+A-D2AT65ATw3xAG+G=y65A@mail.gmail.com
On 20 March 2013 15:47, Dave Mitchell <davem@iabyn.com> wrote:
> On Wed, Mar 20, 2013 at 11:59:06AM +0100, demerphq wrote:
>> Consider  the following output:
>>
>> $ perl -MDevel::Peek -e'my $x=1; Dump($x)'
>> SV = IV(0x1a5fbd8) at 0x1a5fbe0
>>   REFCNT = 1
>>   FLAGS = (PADMY,IOK,pIOK)
>>   IV = 1
>>
>> I cannot understand the two pointer values there.  The first is
>> supposed to be the address in the sv_any field of an SV head. The
>> second is supposed to be the address of the SV head itself.
>
> Because we want, for all SV types, for the IV slot to be at a fixed offset
> from the sv_any pointer.
>
> For a SVt_PVIV say, the sv_u slot contains the PV, while for an SVt_IV
> it contains the IV. If we arrange that for an SVt_IV, the sv_any pointer is
> faked up to point to ourself (or rather, slightly before ourself), then
> we can have this simple definition:
>
> #    define SvIVX(sv) ((XPVIV*) SvANY(sv))->xiv_iv
>
> otherwise we'd need something like
>
>     SvTYPE(sv) == SVt_IV ? ((sv)->sv_u.svu_iv) ?  ((XPVIV*) SvANY(sv))->xiv_iv

Ok, thanks for the explanation.

>> Another question this raises for me: why is SvANY _before_ the
>> refcount and flags? Id have expected the flags to be first, then the
>> refcount then the sv_any member.
>
> Why?

Well id expect the flags to be first because I would assume they are
used the most.

Yves


-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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