This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Sync with libnet-1.13
[perl5.git] / scope.c
diff --git a/scope.c b/scope.c
index 8691057..a5cc4f4 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1,6 +1,6 @@
 /*    scope.c
  *
- *    Copyright (c) 1991-2002, Larry Wall
+ *    Copyright (c) 1991-2003, Larry Wall
  *
  *    You may distribute under the terms of either the GNU General Public
  *    License or the Artistic License, as specified in the README file.
@@ -391,6 +391,15 @@ Perl_save_long(pTHX_ long int *longp)
 }
 
 void
+Perl_save_bool(pTHX_ bool *boolp)
+{
+    SSCHECK(3);
+    SSPUSHBOOL(*boolp);
+    SSPUSHPTR(boolp);
+    SSPUSHINT(SAVEt_BOOL);
+}
+
+void
 Perl_save_I32(pTHX_ I32 *intp)
 {
     SSCHECK(3);
@@ -539,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
@@ -789,6 +799,10 @@ Perl_leave_scope(pTHX_ I32 base)
            ptr = SSPOPPTR;
            *(long*)ptr = (long)SSPOPLONG;
            break;
+       case SAVEt_BOOL:                        /* bool reference */
+           ptr = SSPOPPTR;
+           *(bool*)ptr = (bool)SSPOPBOOL;
+           break;
        case SAVEt_I32:                         /* I32 reference */
            ptr = SSPOPPTR;
            *(I32*)ptr = (I32)SSPOPINT;
@@ -905,16 +919,19 @@ 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_PADBUSY|SVs_PADMY|SVs_PADTMP);
+               U32 padflags = SvFLAGS(sv) & (SVs_PADMY|SVs_PADTMP);
                switch (SvTYPE(sv)) {   /* Console ourselves with a new value */
                case SVt_PVAV:  *(SV**)ptr = (SV*)newAV();      break;
                case SVt_PVHV:  *(SV**)ptr = (SV*)newHV();      break;
                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: