diff options
author | Nicholas Clark <nick@ccl4.org> | 2005-11-14 22:31:14 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2005-11-14 22:31:14 +0000 |
commit | 0565a181ab920bd3cc76f2ab45d62768abfcaf8d (patch) | |
tree | 3bef6b0b82a543d722fd1ad8d544c18184053a02 | |
parent | 80002e0d612c016105daaa578514ef1b726842f4 (diff) | |
download | perl-0565a181ab920bd3cc76f2ab45d62768abfcaf8d.tar.gz |
Mark all places where perl needs to look at a possibly-freed scalar
with a macro SvIS_FREED(sv)
p4raw-id: //depot/perl@26132
-rw-r--r-- | av.c | 2 | ||||
-rw-r--r-- | mg.c | 4 | ||||
-rw-r--r-- | op.c | 2 | ||||
-rw-r--r-- | pad.c | 2 | ||||
-rw-r--r-- | pp_hot.c | 2 | ||||
-rw-r--r-- | sv.h | 5 |
6 files changed, 12 insertions, 5 deletions
@@ -244,7 +244,7 @@ Perl_av_fetch(pTHX_ register AV *av, I32 key, I32 lval) } else if (AvREIFY(av) && (!AvARRAY(av)[key] /* eg. @_ could have freed elts */ - || SvTYPE(AvARRAY(av)[key]) == SVTYPEMASK)) { + || SvIS_FREED(AvARRAY(av)[key]))) { AvARRAY(av)[key] = &PL_sv_undef; /* 1/2 reify */ goto emptyness; } @@ -2040,7 +2040,9 @@ Perl_magic_killbackrefs(pTHX_ SV *sv, MAGIC *mg) SV **svp = AvARRAY(av); PERL_UNUSED_ARG(sv); - if (svp) { + /* Not sure why the av can get freed ahead of its sv, but somehow it does + in ext/B/t/bytecode.t test 15 (involving print <DATA>) */ + if (svp && !SvIS_FREED(av)) { SV *const *const last = svp + AvFILLp(av); while (svp <= last) { @@ -407,7 +407,7 @@ Perl_op_clear(pTHX_ OP *o) clear_pmop: { HV * const pmstash = PmopSTASH(cPMOPo); - if (pmstash && SvREFCNT(pmstash)) { + if (pmstash && !SvIS_FREED(pmstash)) { MAGIC * const mg = mg_find((SV*)pmstash, PERL_MAGIC_symtab); if (mg) { PMOP *pmop = (PMOP*) mg->mg_obj; @@ -233,7 +233,7 @@ Perl_pad_undef(pTHX_ CV* cv) if (!padlist) return; - if (!SvREFCNT(CvPADLIST(cv))) /* may be during global destruction */ + if (SvIS_FREED(padlist)) /* may be during global destruction */ return; DEBUG_X(PerlIO_printf(Perl_debug_log, @@ -1909,7 +1909,7 @@ PP(pp_iter) } } - if (sv && SvREFCNT(sv) == 0) { + if (sv && SvIS_FREED(sv)) { *itersvp = Nullsv; Perl_croak(aTHX_ "Use of freed value in iteration"); } @@ -185,6 +185,11 @@ perform the upgrade if necessary. See C<svtype>. #define SVTYPEMASK 0xff #define SvTYPE(sv) ((sv)->sv_flags & SVTYPEMASK) +/* Sadly there are some parts of the core that have pointers to already-freed + SV heads, and rely on being able to tell that they are now free. So mark + them all by using a consistent macro. */ +#define SvIS_FREED(sv) ((sv)->sv_flags == SVTYPEMASK) + #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= (mt) || (sv_upgrade(sv, mt), 1)) #define SVs_PADSTALE 0x00000100 /* lexical has gone out of scope */ |