develooper Front page | perl.perl5.porters | Postings from September 2012

[perl #49115] $_[0] seems to get reused inappropriately

Thread Next
From:
James E Keenan via RT
Date:
September 1, 2012 16:29
Subject:
[perl #49115] $_[0] seems to get reused inappropriately
Message ID:
rt-3.6.HEAD-11172-1346542182-651.49115-15-0@perl.org
On Wed Dec 26 12:09:18 2007, schmorp@schmorp.de wrote:
> 
> This is a bug report for perl from schmorp@schmorp.de,
> generated with the help of perlbug 1.35 running under perl v5.8.8.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> 
> Hi!
> 
> I cannot provide a testcase for this bug. I can only provide a
>    description
> and hope that somebody with enough experience might spot the problem
> quickly.
> 
> If you can't, do not hesitate to just close this bug.
> 
> (I might re-try with 5.10 which I plan to install soon, but I will
>    likely
> not find the time).
> 
> In any case, in a fairly complex (perl-wise) program, I added a
> Carp::cluck call, and got an exception:
> 
>    Bizarre copy of ARRAY in sassign at
>    /opt/perl/lib/perl5/Carp/Heavy.pm line 104.
> 
> I prepended this code to the cluck call:
> 
>    for(1..10) {
>       package DB;
>       @DB::args=();
>       print join " ", $_, caller $_; print "\n";
>       print join ":", "  ", @DB::args; print "\n";#d#
>       @DB::args=();
>    }
>    Carp::cluck;#d#
> 
> And got the following output:
>    http://ue.tst.eu/7b8f67644b1cfc209f013991fac35a30.txt
> 
> Note the double :: in "4". Digging with gdb showed that carp indeed
>    tried
> to copy this very value. When dumped, I get:
> 
>    SV = NULL(0x0) at 0x202e570
>      REFCNT = 2
>      FLAGS = (PADBUSY,PADMY)
> 
> (which is not an array..., so maybe I was wrong - unfortunately gcc
> optimised most local variables away)
> 
> Now, this is during a hide method call. The hide method in question
> looks like this (including the dump call):
> 
>    # sv_dump simply calls sv_dump (SvROK (arg) ? SvRV (arg) : arg);
>    use PApp::Util; PApp::Util::sv_dump $self->{parent};
> 
>    $self->{parent}->remove ($self)
>      if $self->{parent};
> 
> background: $self is a widget, $self->{parent} is a widget, and a side
>    effect
> of remove is to:
> 
>    delete $child->{parent}; # $child == the above $self
> 
> Also, $self->{parent} is a weak reference, so I do not get an unwanted
> reference cycle.
> 
> When I use sv_dump on $self->{parent}, I get this:
> http://ue.tst.eu/2936444271424c67b6a4e8ab5bea6fd9.txt
> 
>    SV = PVLV(0x9c80f8) at 0x1951b50 ...
> 
> This is the $self->{parent} scalar that later goes "missing".
> 
> When I reformulate the hide method to:
> 
>    if (my $parent = $self->{parent}) {
>       $parent->remove ($self);
>    }
> 
> then I no longer get any crash.
> 
> My theory is that somehow, $_[0] is not correctly being refcounted, or
> for soem other reason gets freed (later reused and then replaced by
>    e.g.
> an AV). When I increase the refcount artificially by copying it to a
>    my
> variable, all is well as it never gets freed.
> 
> I must admit my knowledge of weak references is not too good, and I
>    cannot
> understand why I get a PVLV there at all.
> 
> My hope is that somebody else can pinpoint the bug or at least come up
> with a likely explanation I could test. I am sorry that I cannot work
>    on
> this more right now.
> 
> And again, feel free to close this report if no solution is
>    forthcoming.
> 

Well, no solution has been forthcoming in the 4+ years since this ticket
was originally filed.

I recommend that we close this ticket unless we can get a report of a
reproducible bug within the next 30 days.

Thank you very much.
Jim Keenan

---
via perlbug:  queue: perl5 status: new
https://rt.perl.org:443/rt3/Ticket/Display.html?id=49115

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