From: Ilya Zakharevich Date: Tue, 7 Jan 1997 12:56:02 +0000 (-0500) Subject: Patch for Object subroutines X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=174150afa5efdafc0e94a18211d3c9aa06b15cd9;p=p5sagit%2Fp5-mst-13.2.git Patch for Object subroutines The following script segfaults with _17 (): #!./perl my $x; BEGIN { $x = sub {print "in sub.\n"; undef $x}; sub X::DESTROY { print "Destroying.\n"} bless $x, 'X'; } # At this moment refcount of $x and &$x are 1 (we need a closure for this # because of a sub leak). &$x(); print "x: `$x'.\n"; --- diff --git a/cop.h b/cop.h index 543c039..20301ff 100644 --- a/cop.h +++ b/cop.h @@ -46,6 +46,8 @@ struct block_sub { cx->blk_sub.dfoutgv = defoutgv; \ (void)SvREFCNT_inc(cx->blk_sub.dfoutgv) +/* We muck with cxstack_ix since _dec may call a DESTROY, overwriting cx. */ + #define POPSUB(cx) \ if (cx->blk_sub.hasargs) { /* put back old @_ */ \ GvAV(defgv) = cx->blk_sub.savearray; \ @@ -55,7 +57,9 @@ struct block_sub { if (cx->blk_sub.hasargs) { \ SvREFCNT_inc((SV*)cx->blk_sub.argarray); \ } \ + cxstack_ix++; \ SvREFCNT_dec((SV*)cx->blk_sub.cv); \ + cxstack_ix--; \ } \ }