new flag SvPADSTALE
authorDave Mitchell <davem@fdisolutions.com>
Thu, 19 Dec 2002 19:00:21 +0000 (19:00 +0000)
committerhv <hv@crypt.org>
Fri, 3 Jan 2003 11:06:40 +0000 (11:06 +0000)
Message-ID: <20021219190021.D9530@fdgroup.com>

p4raw-id: //depot/perl@18410

dump.c
scope.c
sv.h

diff --git a/dump.c b/dump.c
index ddd5ae5..1053f87 100644 (file)
--- a/dump.c
+++ b/dump.c
@@ -942,6 +942,7 @@ Perl_do_sv_dump(pTHX_ I32 level, PerlIO *file, SV *sv, I32 nest, I32 maxnest, bo
                   (int)(PL_dumpindent*level), "", (IV)SvREFCNT(sv),
                   (int)(PL_dumpindent*level), "");
 
+    if (flags & SVs_PADSTALE)  sv_catpv(d, "PADSTALE,");
     if (flags & SVs_PADTMP)    sv_catpv(d, "PADTMP,");
     if (flags & SVs_PADMY)     sv_catpv(d, "PADMY,");
     if (flags & SVs_TEMP)      sv_catpv(d, "TEMP,");
diff --git a/scope.c b/scope.c
index d3a4c36..bfd2969 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -548,6 +548,7 @@ Perl_save_clearsv(pTHX_ SV **svp)
     SSCHECK(2);
     SSPUSHLONG((long)(svp-PL_curpad));
     SSPUSHINT(SAVEt_CLEARSV);
+    SvPADSTALE_off(*svp); /* mark lexical as active */
 }
 
 void
@@ -918,6 +919,7 @@ Perl_leave_scope(pTHX_ I32 base)
                    (void)SvOOK_off(sv);
                    break;
                }
+               SvPADSTALE_on(sv); /* mark as no longer live */
            }
            else {      /* Someone has a claim on this, so abandon it. */
                U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
@@ -927,7 +929,9 @@ Perl_leave_scope(pTHX_ I32 base)
                default:        *(SV**)ptr = NEWSV(0,0);        break;
                }
                SvREFCNT_dec(sv);       /* Cast current value to the winds. */
-               SvFLAGS(*(SV**)ptr) |= padflags; /* preserve pad nature */
+               /* preserve pad nature, but also mark as not live
+                * for any closure capturing */
+               SvFLAGS(*(SV**)ptr) |= padflags & SVs_PADSTALE;
            }
            break;
        case SAVEt_DELETE:
diff --git a/sv.h b/sv.h
index 19d8bb3..d87ba11 100644 (file)
--- a/sv.h
+++ b/sv.h
@@ -148,7 +148,7 @@ perform the upgrade if necessary.  See C<svtype>.
 
 #define SvUPGRADE(sv, mt) (SvTYPE(sv) >= mt || sv_upgrade(sv, mt))
 
-/* XXX spare */
+#define SVs_PADSTALE   0x00000100      /* lexical has gone out of scope */
 #define SVs_PADTMP     0x00000200      /* in use as tmp */
 #define SVs_PADMY      0x00000400      /* in use a "my" variable */
 #define SVs_TEMP       0x00000800      /* string is stealable? */
@@ -637,6 +637,10 @@ and leaves the UTF8 status as it was.
 
 #define SvTHINKFIRST(sv)       (SvFLAGS(sv) & SVf_THINKFIRST)
 
+#define SvPADSTALE(sv)         (SvFLAGS(sv) & SVs_PADSTALE)
+#define SvPADSTALE_on(sv)      (SvFLAGS(sv) |= SVs_PADSTALE)
+#define SvPADSTALE_off(sv)     (SvFLAGS(sv) &= ~SVs_PADSTALE)
+
 #define SvPADTMP(sv)           (SvFLAGS(sv) & SVs_PADTMP)
 #define SvPADTMP_on(sv)                (SvFLAGS(sv) |= SVs_PADTMP)
 #define SvPADTMP_off(sv)       (SvFLAGS(sv) &= ~SVs_PADTMP)