develooper Front page | perl.perl5.porters | Postings from June 2001

[PATCH] weakref fix 2, not yet there

From:
Artur Bergman
Date:
June 29, 2001 16:18
Subject:
[PATCH] weakref fix 2, not yet there
Message ID:
B762D957.1CC9%artur@contiller.se
This fixes yet another case of incorrect behaviour on weakrefs.

use threads;
use Devel::Peek qw(SvREFCNT);
my $foo = {};
my $bar = $foo;
weaken($bar);
print SvREFCNT($bar);
threads->create(sub { print SvREFCNT($bar) })->join();

this printed 1,3. So there was a refcnt leak of +2, the following patch
fixes it for one of the cases so we only got a leak of +1.

However if the weakref is not a lexical on the pad we don't see a leak at
all with the applied patch.

I can't understand what is SvREFCNT_incing that weakref.



--- sv.c.old    Fri Jun 29 15:08:45 2001
+++ sv.c    Fri Jun 29 23:57:59 2001
@@ -8440,6 +8440,18 @@
     if (mg->mg_type == PERL_MAGIC_qr) {
         nmg->mg_obj    = (SV*)re_dup((REGEXP*)mg->mg_obj);
     }
+   else if(mg->mg_type == PERL_MAGIC_backref) {
+       AV *av = (AV*) mg->mg_obj;
+       SV **svp;
+       I32 i;
+       nmg->mg_obj = (SV*)newAV();
+       svp = AvARRAY(av);
+       i = AvFILLp(av);
+       while (i >= 0) {
+           av_push((AV*)nmg->mg_obj,sv_dup(svp[i],param));
+           i--;
+       }
+    }
     else {
         nmg->mg_obj    = (mg->mg_flags & MGf_REFCOUNTED)
                   ? sv_dup_inc(mg->mg_obj, param)




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About