Bug#401132: Devel::Peek enhancement
Robert Stone
talby at trap.mtview.ca.us
Wed Jan 27 18:06:39 UTC 2010
On Wed, Jan 27, 2010 at 12:31:44PM +0200, Niko Tyni wrote:
>
> Sorry for the lack of action on this.
No problem at all, thanks for looking into this.
>
> What's wrong with Devel::Peek:SvREFCNT(\%m) ?
"\%m" is a reference constructor, so SvREFCNT() ends up
reporting the reference count of that newly constructed SV. The
situation can be illustrated with this small script:
#!/usr/bin/perl
use strict;
use warnings;
use Devel::Peek;
my %m = (a => 'b');
my $mr = \%m;
Devel::Peek::Dump($mr);
print Devel::Peek::SvREFCNT(\%m), "\n";
From the Dump you can see that %m (the PVHV) has a refcount of
2, but "Devel::Peek::SvREFCNT(\%m)" reports 1. The reason for this can
be illustrated by breaking that call up a little bit. One would
normally expect that:
Devel::Peek::SvREFCNT(\%m)
should be equivalent to
my $tmp = \%m;
Devel::Peek::SvREFCNT($tmp)
which unsurprisingly reports a refcount of 1 for $tmp. Nothing changes
when $tmp is an immediate, unlabeled value on the argument stack to
SvREFCNT() and I think that's expected and correct behavior.
The proposed patch solves this difficulty by always passing the
argument from Perl by reference and then unconditionally dereferencing
to access the target value.
Thanks,
Robert Stone
More information about the Perl-maintainers
mailing list