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

Re: Confusion about SvANY and Devel::Peek output

Thread Previous | Thread Next
Dave Mitchell
March 20, 2013 14:47
Re: Confusion about SvANY and Devel::Peek output
Message ID:
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
>   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

> 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.


"You may not work around any technical limitations in the software"
    -- Windows Vista license

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About