From 4e8e7886db513516f1ffb27b8c762a5fd6831099 Mon Sep 17 00:00:00 2001 From: Gurusamy Sarathy Date: Wed, 31 Dec 1997 14:30:46 -0500 Subject: [win32] fix for bugs in handling DESTROY (adjusted test numbers) Message-Id: <199801010030.TAA14274@aatma.engin.umich.edu> Subject: Re: [PERL] RFD: iterative DESTROYing of objects p4raw-id: //depot/win32/perl@490 --- sv.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'sv.c') diff --git a/sv.c b/sv.c index 9de271bc40..f460e45b3f 100644 --- a/sv.c +++ b/sv.c @@ -2646,37 +2646,37 @@ sv_clear(register SV *sv) if (defstash) { /* Still have a symbol table? */ djSP; GV* destructor; + HV* stash; + SV ref; - ENTER; - SAVEFREESV(SvSTASH(sv)); - - destructor = gv_fetchmethod(SvSTASH(sv), "DESTROY"); - if (destructor) { - SV ref; - - Zero(&ref, 1, SV); - sv_upgrade(&ref, SVt_RV); - SvRV(&ref) = SvREFCNT_inc(sv); - SvROK_on(&ref); - SvREFCNT(&ref) = 1; /* Fake, but otherwise - creating+destructing a ref - leads to disaster. */ - - EXTEND(SP, 2); - PUSHMARK(SP); - PUSHs(&ref); - PUTBACK; - perl_call_sv((SV*)GvCV(destructor), - G_DISCARD|G_EVAL|G_KEEPERR); - del_XRV(SvANY(&ref)); - SvREFCNT(sv)--; - } + Zero(&ref, 1, SV); + sv_upgrade(&ref, SVt_RV); + SvROK_on(&ref); + SvREADONLY_on(&ref); /* DESTROY() could be naughty */ + SvREFCNT(&ref) = 1; - LEAVE; + do { + stash = SvSTASH(sv); + destructor = gv_fetchmethod(SvSTASH(sv), "DESTROY"); + if (destructor) { + ENTER; + SvRV(&ref) = SvREFCNT_inc(sv); + EXTEND(SP, 2); + PUSHMARK(SP); + PUSHs(&ref); + PUTBACK; + perl_call_sv((SV*)GvCV(destructor), + G_DISCARD|G_EVAL|G_KEEPERR); + SvREFCNT(sv)--; + LEAVE; + } + } while (SvOBJECT(sv) && SvSTASH(sv) != stash); + + del_XRV(SvANY(&ref)); } - else - SvREFCNT_dec(SvSTASH(sv)); + if (SvOBJECT(sv)) { + SvREFCNT_dec(SvSTASH(sv)); /* possibly of changed persuasion */ SvOBJECT_off(sv); /* Curse the object. */ if (SvTYPE(sv) != SVt_PVIO) --sv_objcount; /* XXX Might want something more general */ -- cgit v1.2.1