Change 33061 by [EMAIL PROTECTED] on 2008/01/24 12:50:32

        Change the context type of for ($a .. $b) to CXt_LOOP_LAZYIV, and
        assert that it isn't using  cx->blk_loop.iterlval.
        Fix a casting bug when assigning a sentinal to cx->blk_loop.iterary.

Affected files ...

... //depot/perl/cop.h#166 edit
... //depot/perl/pp_ctl.c#671 edit
... //depot/perl/pp_hot.c#562 edit
... //depot/perl/scope.c#218 edit
... //depot/perl/sv.c#1494 edit

Differences ...

==== //depot/perl/cop.h#166 (text) ====
Index: perl/cop.h
--- perl/cop.h#165~33059~       2008-01-24 02:44:25.000000000 -0800
+++ perl/cop.h  2008-01-24 04:50:32.000000000 -0800
@@ -518,6 +518,8 @@
        CX_ITERDATA_SET(cx,dat);
 
 #define POPLOOP(cx)                                                    \
+       if (CxTYPE(cx) == CXt_LOOP_LAZYIV)                              \
+           assert(!cx->blk_loop.iterlval);                             \
        SvREFCNT_dec(cx->blk_loop.iterlval);                            \
        if (CxITERVAR(cx)) {                                            \
             if (SvPADMY(cx->blk_loop.itersave)) {                      \
@@ -679,11 +681,12 @@
 #define CXt_BLOCK      5
 #define CXt_FORMAT     6
 #define CXt_GIVEN      7
-#define CXt_LOOP_PLAIN 8
-#define CXt_LOOP_FOR   9
+/* This is first so that CXt_LOOP_FOR|CXt_LOOP_LAZYIV is CXt_LOOP_LAZYIV */
+#define CXt_LOOP_FOR   8
+#define CXt_LOOP_PLAIN 9
 /* Foreach on a temporary list on the stack */
 #define CXt_LOOP_STACK 10
-#define CXt_LOOP_RES2  11
+#define CXt_LOOP_LAZYIV        11
 
 /* private flags for CXt_SUB and CXt_NULL
    However, this is checked in many places which do not check the type, so

==== //depot/perl/pp_ctl.c#671 (text) ====
Index: perl/pp_ctl.c
--- perl/pp_ctl.c#670~33060~    2008-01-24 04:15:43.000000000 -0800
+++ perl/pp_ctl.c       2008-01-24 04:50:32.000000000 -0800
@@ -1256,6 +1256,7 @@
            if (CxTYPE(cx) == CXt_NULL)
                return -1;
            break;
+       case CXt_LOOP_LAZYIV:
        case CXt_LOOP_STACK:
        case CXt_LOOP_FOR:
        case CXt_LOOP_PLAIN:
@@ -1373,6 +1374,7 @@
            if ((CxTYPE(cx)) == CXt_NULL)
                return -1;
            break;
+       case CXt_LOOP_LAZYIV:
        case CXt_LOOP_STACK:
        case CXt_LOOP_FOR:
        case CXt_LOOP_PLAIN:
@@ -1399,6 +1401,7 @@
        case CXt_LOOP_PLAIN:
            assert(!CxFOREACHDEF(cx));
            break;
+       case CXt_LOOP_LAZYIV:
        case CXt_LOOP_STACK:
        case CXt_LOOP_FOR:
            if (CxFOREACHDEF(cx)) {
@@ -1451,6 +1454,7 @@
        case CXt_EVAL:
            POPEVAL(cx);
            break;
+       case CXt_LOOP_LAZYIV:
        case CXt_LOOP_STACK:
        case CXt_LOOP_FOR:
        case CXt_LOOP_PLAIN:
@@ -1884,6 +1888,10 @@
            SvGETMAGIC(sv);
            SvGETMAGIC(right);
            if (RANGE_IS_NUMERIC(sv,right)) {
+               cx->cx_type |= CXt_LOOP_LAZYIV;
+               /* Make sure that no-one re-orders cop.h and breaks our
+                  assumptions */
+               assert(CxTYPE(cx) == CXt_LOOP_LAZYIV);
 #ifdef NV_PRESERVES_UV
                if ((SvOK(sv) && ((SvNV(sv) < (NV)IV_MIN) ||
                                  (SvNV(sv) > (NV)IV_MAX)))
@@ -1924,7 +1932,7 @@
        }
     }
     else {
-       cx->blk_loop.iterary = (SV*)0xDEADBEEF;
+       cx->blk_loop.iterary = (AV*)0xDEADBEEF;
        if (PL_op->op_private & OPpITER_REVERSED) {
            cx->blk_loop.itermax = MARK - PL_stack_base + 1;
            cx->blk_loop.iterix = cx->blk_oldsp + 1;
@@ -2150,6 +2158,7 @@
     cxstack_ix++; /* temporarily protect top context */
     mark = newsp;
     switch (CxTYPE(cx)) {
+    case CXt_LOOP_LAZYIV:
     case CXt_LOOP_STACK:
     case CXt_LOOP_FOR:
     case CXt_LOOP_PLAIN:
@@ -2195,6 +2204,7 @@
     cxstack_ix--;
     /* Stack values are safe: */
     switch (pop2) {
+    case CXt_LOOP_LAZYIV:
     case CXt_LOOP_PLAIN:
     case CXt_LOOP_STACK:
     case CXt_LOOP_FOR:
@@ -2555,6 +2565,7 @@
                    break;
                 }
                 /* else fall through */
+           case CXt_LOOP_LAZYIV:
            case CXt_LOOP_STACK:
            case CXt_LOOP_FOR:
            case CXt_LOOP_PLAIN:

==== //depot/perl/pp_hot.c#562 (text) ====
Index: perl/pp_hot.c
--- perl/pp_hot.c#561~33060~    2008-01-24 04:15:43.000000000 -0800
+++ perl/pp_hot.c       2008-01-24 04:50:32.000000000 -0800
@@ -1914,7 +1914,7 @@
     av = CxTYPE(cx) == CXt_LOOP_STACK ? PL_curstack : cx->blk_loop.iterary;
     if (SvTYPE(av) != SVt_PVAV) {
        /* iterate ($min .. $max) */
-       if (cx->blk_loop.iterlval) {
+       if (CxTYPE(cx) != CXt_LOOP_LAZYIV) {
            /* string increment */
            register SV* cur = cx->blk_loop.iterlval;
            STRLEN maxlen = 0;
@@ -1944,6 +1944,7 @@
            RETPUSHNO;
        }
        /* integer increment */
+       assert(!cx->blk_loop.iterlval);
        if (cx->blk_loop.iterix > cx->blk_loop.itermax)
            RETPUSHNO;
 

==== //depot/perl/scope.c#218 (text) ====
Index: perl/scope.c
--- perl/scope.c#217~33057~     2008-01-24 01:36:05.000000000 -0800
+++ perl/scope.c        2008-01-24 04:50:32.000000000 -0800
@@ -1083,6 +1083,8 @@
                PTR2UV(cx->blk_eval.retop));
        break;
 
+    case CXt_LOOP_LAZYIV:
+    case CXt_LOOP_STACK:
     case CXt_LOOP_FOR:
     case CXt_LOOP_PLAIN:
        PerlIO_printf(Perl_debug_log, "BLK_LOOP.LABEL = %s\n", CxLABEL(cx));

==== //depot/perl/sv.c#1494 (text) ====
Index: perl/sv.c
--- perl/sv.c#1493~33059~       2008-01-24 02:44:25.000000000 -0800
+++ perl/sv.c   2008-01-24 04:50:32.000000000 -0800
@@ -10542,6 +10542,7 @@
                                                      param);
                ncx->blk_eval.cur_text  = sv_dup(ncx->blk_eval.cur_text, param);
                break;
+           case CXt_LOOP_LAZYIV:
            case CXt_LOOP_FOR:
                ncx->blk_loop.iterary   = av_dup_inc(ncx->blk_loop.iterary,
                                                     param);
End of Patch.

Reply via email to