This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Further conversion of overload.t
[perl5.git] / op.c
diff --git a/op.c b/op.c
index dd85eaf..71d0764 100644 (file)
--- a/op.c
+++ b/op.c
@@ -332,8 +332,16 @@ Perl_op_clear(pTHX_ OP *o)
 #ifdef PERL_MAD
     /* if (o->op_madprop && o->op_madprop->mad_next)
        abort(); */
-    mad_free(o->op_madprop);
-    o->op_madprop = 0;
+    /* FIXME for MAD - if I uncomment these two lines t/op/pack.t fails with
+       "modification of a read only value" for a reason I can't fathom why.
+       It's the "" stringification of $_, where $_ was set to '' in a foreach
+       loop, but it defies simplification into a small test case.
+       However, commenting them out has caused ext/List/Util/t/weak.t to fail
+       the last test.  */
+    /*
+      mad_free(o->op_madprop);
+      o->op_madprop = 0;
+    */
 #endif    
 
  retry:
@@ -1737,12 +1745,13 @@ S_my_kid(pTHX_ OP *o, OP *attrs, OP **imopsp)
     if (!o || PL_error_count)
        return o;
 
+    type = o->op_type;
+
     if (PL_madskills && type == OP_NULL && o->op_flags & OPf_KIDS) {
        (void)my_kid(cUNOPo->op_first, attrs, imopsp);
        return o;
     }
 
-    type = o->op_type;
     if (type == OP_LIST) {
         OP *kid;
        for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
@@ -4228,10 +4237,10 @@ Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
                break;
 
              case OP_SASSIGN:
-               if (k1->op_type == OP_READDIR
+               if (k1 && (k1->op_type == OP_READDIR
                      || k1->op_type == OP_GLOB
                      || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
-                     || k1->op_type == OP_EACH)
+                     || k1->op_type == OP_EACH))
                    expr = newUNOP(OP_DEFINED, 0, expr);
                break;
            }
@@ -4290,10 +4299,10 @@ whileline, OP *expr, OP *block, OP *cont, I32 has_my)
                break;
 
              case OP_SASSIGN:
-               if (k1->op_type == OP_READDIR
+               if (k1 && (k1->op_type == OP_READDIR
                      || k1->op_type == OP_GLOB
                      || (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
-                     || k1->op_type == OP_EACH)
+                     || k1->op_type == OP_EACH))
                    expr = newUNOP(OP_DEFINED, 0, expr);
                break;
            }
@@ -4598,7 +4607,7 @@ S_newGIVWHENOP(pTHX_ OP *cond, OP *block,
  */
 STATIC
 bool
-S_looks_like_bool(pTHX_ OP *o)
+S_looks_like_bool(pTHX_ const OP *o)
 {
     dVAR;
     switch(o->op_type) {
@@ -4669,7 +4678,7 @@ Perl_newGIVENOP(pTHX_ OP *cond, OP *block, PADOFFSET defsv_off)
 OP *
 Perl_newWHENOP(pTHX_ OP *cond, OP *block)
 {
-    bool cond_llb = (!cond || looks_like_bool(cond));
+    const bool cond_llb = (!cond || looks_like_bool(cond));
     OP *cond_op;
 
     if (cond_llb)
@@ -6357,13 +6366,15 @@ Perl_ck_fun(pTHX_ OP *o)
        listkids(o);
     }
     else if (PL_opargs[type] & OA_DEFGV) {
-       OP *newop = newUNOP(type, 0, newDEFSVOP());
 #ifdef PERL_MAD
+       OP *newop = newUNOP(type, 0, newDEFSVOP());
        op_getmad(o,newop,'O');
+       return newop;
 #else
+       /* Ordering of these two is important to keep f_map.t passing.  */
        op_free(o);
+       return newUNOP(type, 0, newDEFSVOP());
 #endif
-       return newop;
     }
 
     if (oa) {
@@ -6434,13 +6445,13 @@ OP *
 Perl_ck_grep(pTHX_ OP *o)
 {
     dVAR;
-    LOGOP *gwop;
+    LOGOP *gwop = NULL;
     OP *kid;
     const OPCODE type = o->op_type == OP_GREPSTART ? OP_GREPWHILE : OP_MAPWHILE;
     I32 offset;
 
     o->op_ppaddr = PL_ppaddr[OP_GREPSTART];
-    NewOp(1101, gwop, 1, LOGOP);
+    /* don't allocate gwop here, as we may leak it if PL_error_count > 0 */
 
     if (o->op_flags & OPf_STACKED) {
        OP* k;
@@ -6451,6 +6462,7 @@ Perl_ck_grep(pTHX_ OP *o)
        for (k = cUNOPx(kid)->op_first; k; k = k->op_next) {
            kid = k;
        }
+       NewOp(1101, gwop, 1, LOGOP);
        kid->op_next = (OP*)gwop;
        o->op_flags &= ~OPf_STACKED;
     }
@@ -6467,6 +6479,8 @@ Perl_ck_grep(pTHX_ OP *o)
        Perl_croak(aTHX_ "panic: ck_grep");
     kid = kUNOP->op_first;
 
+    if (!gwop)
+       NewOp(1101, gwop, 1, LOGOP);
     gwop->op_type = type;
     gwop->op_ppaddr = PL_ppaddr[type];
     gwop->op_first = listkids(o);
@@ -6826,18 +6840,18 @@ Perl_ck_require(pTHX_ OP *o)
 
     if (gv && GvCVu(gv) && GvIMPORTED_CV(gv)) {
        OP * const kid = cUNOPo->op_first;
-       OP * newop
-           = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
-                             append_elem(OP_LIST, kid,
-                                         scalar(newUNOP(OP_RV2CV, 0,
-                                                        newGVOP(OP_GV, 0,
-                                                                gv))))));
+       OP * newop;
+
        cUNOPo->op_first = 0;
-#ifdef PERL_MAD
-       op_getmad(o,newop,'O');
-#else
+#ifndef PERL_MAD
        op_free(o);
 #endif
+       newop = ck_subr(newUNOP(OP_ENTERSUB, OPf_STACKED,
+                               append_elem(OP_LIST, kid,
+                                           scalar(newUNOP(OP_RV2CV, 0,
+                                                          newGVOP(OP_GV, 0,
+                                                                  gv))))));
+       op_getmad(o,newop,'O');
        return newop;
     }