This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
File/Spec.pm needs trailing newline
[perl5.git] / op.c
diff --git a/op.c b/op.c
index 6d3a6d3..ecefb83 100644 (file)
--- a/op.c
+++ b/op.c
@@ -619,6 +619,7 @@ op_free(OP *o)
        /* FALL THROUGH */
     case OP_PUSHRE:
     case OP_MATCH:
+    case OP_QR:
        ReREFCNT_dec(cPMOPo->op_pmregexp);
        break;
     }
@@ -725,6 +726,7 @@ scalar(OP *o)
        }
        /* FALL THROUGH */
     case OP_MATCH:
+    case OP_QR:
     case OP_SUBST:
     case OP_NULL:
     default:
@@ -983,6 +985,7 @@ list(OP *o)
        break;
     default:
     case OP_MATCH:
+    case OP_QR:
     case OP_SUBST:
     case OP_NULL:
        if (!(o->op_flags & OPf_KIDS))
@@ -1304,6 +1307,9 @@ scalar_mod_type(OP *o, I32 type)
     case OP_CONCAT:
     case OP_SUBST:
     case OP_TRANS:
+    case OP_READ:
+    case OP_SYSREAD:
+    case OP_RECV:
     case OP_ANDASSIGN: /* may work later */
     case OP_ORASSIGN:  /* may work later */
        return TRUE;
@@ -1518,11 +1524,21 @@ scope(OP *o)
     return o;
 }
 
+void
+save_hints(void)
+{
+    SAVEI32(hints);
+    SAVESPTR(GvHV(hintgv));
+    GvHV(hintgv) = newHVhv(GvHV(hintgv));
+    SAVEFREESV(GvHV(hintgv));
+}
+
 int
 block_start(int full)
 {
     dTHR;
     int retval = savestack_ix;
+
     SAVEI32(comppad_name_floor);
     if (full) {
        if ((comppad_name_fill = AvFILLp(comppad_name)) > 0)
@@ -1537,7 +1553,7 @@ block_start(int full)
     SAVEI32(padix_floor);
     padix_floor = padix;
     pad_reset_pending = FALSE;
-    SAVEI32(hints);
+    SAVEHINTS();
     hints &= ~HINT_BLOCK_SCOPE;
     return retval;
 }
@@ -1967,12 +1983,6 @@ newUNOP(I32 type, I32 flags, OP *first)
     unop->op_first = first;
     unop->op_flags = flags | OPf_KIDS;
     unop->op_private = 1 | (flags >> 8);
-#if 1
-    if(type == OP_STUDY && first->op_type == OP_MATCH) {
-       first->op_type = OP_PUSHRE;
-       first->op_ppaddr = ppaddr[OP_PUSHRE];
-    }
-#endif
     unop = (UNOP*) CHECKOP(type, unop);
     if (unop->op_next)
        return (OP*)unop;
@@ -2090,8 +2100,11 @@ newPMOP(I32 type, I32 flags)
     pmop->op_flags = flags;
     pmop->op_private = 0 | (flags >> 8);
 
+    if (hints & HINT_RE_TAINT)
+       pmop->op_pmpermflags |= PMf_RETAINT;
     if (hints & HINT_LOCALE)
-       pmop->op_pmpermflags = (pmop->op_pmflags |= PMf_LOCALE);
+       pmop->op_pmpermflags |= PMf_LOCALE;
+    pmop->op_pmflags = pmop->op_pmpermflags;
 
     /* link into pm list */
     if (type != OP_TRANS && curstash) {
@@ -2105,6 +2118,7 @@ newPMOP(I32 type, I32 flags)
 OP *
 pmruntime(OP *o, OP *expr, OP *repl)
 {
+    dTHR;
     PMOP *pm;
     LOGOP *rcop;
     I32 repl_has_vars = 0;
@@ -2124,25 +2138,29 @@ pmruntime(OP *o, OP *expr, OP *repl)
            p = SvPV(pat, plen);
            pm->op_pmflags |= PMf_SKIPWHITE;
        }
-       pm->op_pmregexp = pregcomp(p, p + plen, pm);
+       pm->op_pmregexp = CALLREGCOMP(p, p + plen, pm);
        if (strEQ("\\s+", pm->op_pmregexp->precomp))
            pm->op_pmflags |= PMf_WHITE;
        op_free(expr);
     }
     else {
-       if (pm->op_pmflags & PMf_KEEP)
-           expr = newUNOP(OP_REGCMAYBE,0,expr);
+       if (pm->op_pmflags & PMf_KEEP || !(hints & HINT_RE_EVAL))
+           expr = newUNOP((!(hints & HINT_RE_EVAL) 
+                           ? OP_REGCRESET
+                           : OP_REGCMAYBE),0,expr);
 
        Newz(1101, rcop, 1, LOGOP);
        rcop->op_type = OP_REGCOMP;
        rcop->op_ppaddr = ppaddr[OP_REGCOMP];
        rcop->op_first = scalar(expr);
-       rcop->op_flags |= OPf_KIDS;
+       rcop->op_flags |= ((hints & HINT_RE_EVAL) 
+                          ? (OPf_SPECIAL | OPf_KIDS)
+                          : OPf_KIDS);
        rcop->op_private = 1;
        rcop->op_other = o;
 
        /* establish postfix order */
-       if (pm->op_pmflags & PMf_KEEP) {
+       if (pm->op_pmflags & PMf_KEEP || !(hints & HINT_RE_EVAL)) {
            LINKLIST(expr);
            rcop->op_next = expr;
            ((UNOP*)expr)->op_first->op_next = (OP*)rcop;
@@ -2202,6 +2220,8 @@ pmruntime(OP *o, OP *expr, OP *repl)
                             curop->op_type == OP_PADANY) {
                        repl_has_vars = 1;
                    }
+                   else if (curop->op_type == OP_PUSHRE)
+                       ; /* Okay here, dangerous in newASSIGNOP */
                    else
                        break;
                }
@@ -2501,6 +2521,14 @@ newASSIGNOP(I32 flags, OP *left, I32 optype, OP *right)
                        if (lastop->op_type != OP_GV)   /* funny deref? */
                            break;
                    }
+                   else if (curop->op_type == OP_PUSHRE) {
+                       if (((PMOP*)curop)->op_pmreplroot) {
+                           GV *gv = (GV*)((PMOP*)curop)->op_pmreplroot;
+                           if (gv == defgv || SvCUR(gv) == generation)
+                               break;
+                           SvCUR(gv) = generation;
+                       }       
+                   }
                    else
                        break;
                }
@@ -3047,19 +3075,19 @@ newFOROP(I32 flags,char *label,line_t forline,OP *sv,OP *expr,OP *block,OP *cont
        CONDOP* range = (CONDOP*) flip->op_first;
        OP* left  = range->op_first;
        OP* right = left->op_sibling;
-       LISTOP* list;
+       LISTOP* listop;
 
        range->op_flags &= ~OPf_KIDS;
        range->op_first = Nullop;
 
-       list = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
-       list->op_first->op_next = range->op_true;
+       listop = (LISTOP*)newLISTOP(OP_LIST, 0, left, right);
+       listop->op_first->op_next = range->op_true;
        left->op_next = range->op_false;
-       right->op_next = (OP*)list;
-       list->op_next = list->op_first;
+       right->op_next = (OP*)listop;
+       listop->op_next = listop->op_first;
 
        op_free(expr);
-       expr = (OP*)(list);
+       expr = (OP*)(listop);
         null(expr);
        iterflags |= OPf_STACKED;
     }
@@ -3462,7 +3490,7 @@ newSUB(I32 floor, OP *o, OP *proto, OP *block)
                goto done;
            }
            /* ahem, death to those who redefine active sort subs */
-           if (curstackinfo->si_type == SI_SORT && sortcop == CvSTART(cv))
+           if (curstackinfo->si_type == PERLSI_SORT && sortcop == CvSTART(cv))
                croak("Can't redefine active sort subroutine %s", name);
            if(const_sv = cv_const_sv(cv))
                const_changed = sv_cmp(const_sv, op_const_sv(block, Nullcv));
@@ -4961,7 +4989,7 @@ peep(register OP *o)
 
        case OP_PADAV:
            if (o->op_next->op_type == OP_RV2AV
-               && (o->op_next->op_flags && OPf_REF))
+               && (o->op_next->op_flags & OPf_REF))
            {
                null(o->op_next);
                o->op_next = o->op_next->op_next;
@@ -4970,7 +4998,7 @@ peep(register OP *o)
        
        case OP_PADHV:
            if (o->op_next->op_type == OP_RV2HV
-               && (o->op_next->op_flags && OPf_REF))
+               && (o->op_next->op_flags & OPf_REF))
            {
                null(o->op_next);
                o->op_next = o->op_next->op_next;
@@ -5000,6 +5028,7 @@ peep(register OP *o)
            peep(cLOOP->op_lastop);
            break;
 
+       case OP_QR:
        case OP_MATCH:
        case OP_SUBST:
            o->op_seq = op_seqmax++;