integrate change#3179 from maint-5.005
[p5sagit/p5-mst-13.2.git] / scope.c
diff --git a/scope.c b/scope.c
index b603641..4a2a778 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -1,6 +1,6 @@
 /*    scope.c
  *
- *    Copyright (c) 1991-1997, Larry Wall
+ *    Copyright (c) 1991-1999, 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.
@@ -204,6 +204,18 @@ save_svref(SV **sptr)
     return save_scalar_at(sptr);
 }
 
+/* Like save_svref(), but doesn't deal with magic.  Can be used to
+ * restore a global SV to its prior contents, freeing new value. */
+void
+save_generic_svref(SV **sptr)
+{
+    dTHR;
+    SSCHECK(3);
+    SSPUSHPTR(sptr);
+    SSPUSHPTR(SvREFCNT_inc(*sptr));
+    SSPUSHINT(SAVEt_GENERIC_SVREF);
+}
+
 void
 save_gp(GV *gv, I32 empty)
 {
@@ -578,6 +590,16 @@ leave_scope(I32 base)
            ptr = &GvSV(gv);
            SvREFCNT_dec(gv);
            goto restore_sv;
+        case SAVEt_GENERIC_SVREF:              /* generic sv */
+           value = (SV*)SSPOPPTR;
+           ptr = SSPOPPTR;
+           if (ptr) {
+               sv = *(SV**)ptr;
+               *(SV**)ptr = value;
+               SvREFCNT_dec(sv);
+           }
+           SvREFCNT_dec(value);
+           break;
         case SAVEt_SVREF:                      /* scalar reference */
            value = (SV*)SSPOPPTR;
            ptr = SSPOPPTR;
@@ -791,7 +813,7 @@ leave_scope(I32 base)
            if (ptr) {
                sv = *(SV**)ptr;
                if (sv && sv != &PL_sv_undef) {
-                   if (SvRMAGICAL(av) && mg_find((SV*)av, 'P'))
+                   if (SvTIED_mg((SV*)av, 'P'))
                        (void)SvREFCNT_inc(sv);
                    SvREFCNT_dec(av);
                    goto restore_sv;
@@ -809,7 +831,7 @@ leave_scope(I32 base)
                SV *oval = HeVAL((HE*)ptr);
                if (oval && oval != &PL_sv_undef) {
                    ptr = &HeVAL((HE*)ptr);
-                   if (SvRMAGICAL(hv) && mg_find((SV*)hv, 'P'))
+                   if (SvTIED_mg((SV*)hv, 'P'))
                        (void)SvREFCNT_inc(*(SV**)ptr);
                    SvREFCNT_dec(hv);
                    SvREFCNT_dec(sv);
@@ -841,8 +863,8 @@ cx_dump(PERL_CONTEXT *cx)
 {
 #ifdef DEBUGGING
     dTHR;
-    PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), block_type[cx->cx_type]);
-    if (cx->cx_type != CXt_SUBST) {
+    PerlIO_printf(Perl_debug_log, "CX %ld = %s\n", (long)(cx - cxstack), PL_block_type[CxTYPE(cx)]);
+    if (CxTYPE(cx) != CXt_SUBST) {
        PerlIO_printf(Perl_debug_log, "BLK_OLDSP = %ld\n", (long)cx->blk_oldsp);
        PerlIO_printf(Perl_debug_log, "BLK_OLDCOP = 0x%lx\n", (long)cx->blk_oldcop);
        PerlIO_printf(Perl_debug_log, "BLK_OLDMARKSP = %ld\n", (long)cx->blk_oldmarksp);
@@ -851,7 +873,7 @@ cx_dump(PERL_CONTEXT *cx)
        PerlIO_printf(Perl_debug_log, "BLK_OLDPM = 0x%lx\n", (long)cx->blk_oldpm);
        PerlIO_printf(Perl_debug_log, "BLK_GIMME = %s\n", cx->blk_gimme ? "LIST" : "SCALAR");
     }
-    switch (cx->cx_type) {
+    switch (CxTYPE(cx)) {
     case CXt_NULL:
     case CXt_BLOCK:
        break;
@@ -871,8 +893,8 @@ cx_dump(PERL_CONTEXT *cx)
        PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_IN_EVAL = %ld\n",
                (long)cx->blk_eval.old_in_eval);
        PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_OP_TYPE = %s (%s)\n",
-               op_name[cx->blk_eval.old_op_type],
-               op_desc[cx->blk_eval.old_op_type]);
+               PL_op_name[cx->blk_eval.old_op_type],
+               PL_op_desc[cx->blk_eval.old_op_type]);
        PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_NAME = %s\n",
                cx->blk_eval.old_name);
        PerlIO_printf(Perl_debug_log, "BLK_EVAL.OLD_EVAL_ROOT = 0x%lx\n",
@@ -908,8 +930,8 @@ cx_dump(PERL_CONTEXT *cx)
                (long)cx->sb_iters);
        PerlIO_printf(Perl_debug_log, "SB_MAXITERS = %ld\n",
                (long)cx->sb_maxiters);
-       PerlIO_printf(Perl_debug_log, "SB_SAFEBASE = %ld\n",
-               (long)cx->sb_safebase);
+       PerlIO_printf(Perl_debug_log, "SB_RFLAGS = %ld\n",
+               (long)cx->sb_rflags);
        PerlIO_printf(Perl_debug_log, "SB_ONCE = %ld\n",
                (long)cx->sb_once);
        PerlIO_printf(Perl_debug_log, "SB_ORIG = %s\n",