This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Test::More
[perl5.git] / regexec.c
index 961611b..1127933 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -87,6 +87,7 @@
 #define RF_warned      2               /* warned about big count? */
 #define RF_evaled      4               /* Did an EVAL with setting? */
 #define RF_utf8                8               /* String contains multibyte chars? */
+#define RF_false       16              /* odd number of nested negatives */
 
 #define UTF ((PL_reg_flags & RF_utf8) != 0)
 
@@ -3204,7 +3205,10 @@ S_regmatch(pTHX_ regnode *prog)
                                      "%*s  already tried at this position...\n",
                                      REPORT_CODE_OFF+PL_regindent*2, "")
                        );
-                       sayNO_SILENT;
+                       if (PL_reg_flags & RF_false)
+                           sayYES;
+                       else
+                           sayNO_SILENT;
                    }
                    PL_reg_poscache[o] |= (1<<b);
                }
@@ -3351,7 +3355,6 @@ S_regmatch(pTHX_ regnode *prog)
        {
            I32 l = 0;
            CHECKPOINT lastcp;
-           I32 lparen = *PL_reglastparen;
        
            /* We suppose that the next guy does not need
               backtracking: in particular, it is of constant length,
@@ -3391,19 +3394,8 @@ S_regmatch(pTHX_ regnode *prog)
                    if (! HAS_TEXT(text_node)) c1 = c2 = -1000;
                    else {
                        if (PL_regkind[(U8)OP(text_node)] == REF) {
-                           I32 n, ln;
-                           n = ARG(text_node);  /* which paren pair */
-                           ln = PL_regstartp[n];
-                           /* assume yes if we haven't seen CLOSEn */
-                           if (
-                               (I32)*PL_reglastparen < n ||
-                               ln == -1 ||
-                               ln == PL_regendp[n]
-                           ) {
-                               c1 = c2 = -1000;
-                               goto assume_ok_MM;
-                           }
-                           c1 = *(PL_bostr + ln);
+                           c1 = c2 = -1000;
+                           goto assume_ok_MM;
                        }
                        else { c1 = (U8)*STRING(text_node); }
                        if (OP(text_node) == EXACTF || OP(text_node) == REFF)
@@ -3436,8 +3428,6 @@ S_regmatch(pTHX_ regnode *prog)
                        }
                        if (regmatch(next))
                            sayYES;
-                       /* t/op/regexp.t test 885 fails if this is performed */
-                       /* *PL_reglastparen = lparen; */
                        REGCP_UNWIND(lastcp);
                    }
                    /* Couldn't or didn't -- move forward. */
@@ -3475,19 +3465,8 @@ S_regmatch(pTHX_ regnode *prog)
                        if (! HAS_TEXT(text_node)) c1 = c2 = -1000;
                        else {
                            if (PL_regkind[(U8)OP(text_node)] == REF) {
-                               I32 n, ln;
-                               n = ARG(text_node);  /* which paren pair */
-                               ln = PL_regstartp[n];
-                               /* assume yes if we haven't seen CLOSEn */
-                               if (
-                                   (I32)*PL_reglastparen < n ||
-                                   ln == -1 ||
-                                   ln == PL_regendp[n]
-                               ) {
-                                   c1 = c2 = -1000;
-                                   goto assume_ok_REG;
-                               }
-                               c1 = *(PL_bostr + ln);
+                               c1 = c2 = -1000;
+                               goto assume_ok_REG;
                            }
                            else { c1 = (U8)*STRING(text_node); }
 
@@ -3525,7 +3504,6 @@ S_regmatch(pTHX_ regnode *prog)
                        }
                        if (regmatch(next))
                            sayYES;
-                       *PL_reglastparen = lparen;
                        REGCP_UNWIND(lastcp);
                    }
                    /* Couldn't or didn't -- back up. */
@@ -3585,19 +3563,8 @@ S_regmatch(pTHX_ regnode *prog)
                if (! HAS_TEXT(text_node)) c1 = c2 = -1000;
                else {
                    if (PL_regkind[(U8)OP(text_node)] == REF) {
-                       I32 n, ln;
-                       n = ARG(text_node);  /* which paren pair */
-                       ln = PL_regstartp[n];
-                       /* assume yes if we haven't seen CLOSEn */
-                       if (
-                           (I32)*PL_reglastparen < n ||
-                           ln == -1 ||
-                           ln == PL_regendp[n]
-                       ) {
-                           c1 = c2 = -1000;
-                           goto assume_ok_easy;
-                       }
-                       s = (U8*)PL_bostr + ln;
+                       c1 = c2 = -1000;
+                       goto assume_ok_easy;
                    }
                    else { s = (U8*)STRING(text_node); }
 
@@ -3638,7 +3605,6 @@ S_regmatch(pTHX_ regnode *prog)
            PL_reginput = locinput;
            if (minmod) {
                CHECKPOINT lastcp;
-               I32 lparen = *PL_reglastparen;
                minmod = 0;
                if (ln && regrepeat(scan, ln) < ln)
                    sayNO;
@@ -3745,7 +3711,6 @@ S_regmatch(pTHX_ regnode *prog)
                        if (c == (UV)c1 || c == (UV)c2)
                        {
                            TRYPAREN(paren, ln, PL_reginput);
-                           *PL_reglastparen = lparen;
                            REGCP_UNWIND(lastcp);
                        }
                    }
@@ -3753,7 +3718,6 @@ S_regmatch(pTHX_ regnode *prog)
                    else if (c1 == -1000)
                    {
                        TRYPAREN(paren, ln, PL_reginput);
-                       *PL_reglastparen = lparen;
                        REGCP_UNWIND(lastcp);
                    }
                    /* Couldn't or didn't -- move forward. */
@@ -3768,7 +3732,6 @@ S_regmatch(pTHX_ regnode *prog)
            }
            else {
                CHECKPOINT lastcp;
-               I32 lparen = *PL_reglastparen;
                n = regrepeat(scan, n);
                locinput = PL_reginput;
                if (ln < n && PL_regkind[(U8)OP(next)] == EOL &&
@@ -3799,7 +3762,6 @@ S_regmatch(pTHX_ regnode *prog)
                        if (c1 == -1000 || c == (UV)c1 || c == (UV)c2)
                            {
                                TRYPAREN(paren, n, PL_reginput);
-                               *PL_reglastparen = lparen;
                                REGCP_UNWIND(lastcp);
                            }
                        /* Couldn't or didn't -- back up. */
@@ -3823,7 +3785,6 @@ S_regmatch(pTHX_ regnode *prog)
                        if (c1 == -1000 || c == (UV)c1 || c == (UV)c2)
                            {
                                TRYPAREN(paren, n, PL_reginput);
-                               *PL_reglastparen = lparen;
                                REGCP_UNWIND(lastcp);
                            }
                        /* Couldn't or didn't -- back up. */
@@ -3897,6 +3858,7 @@ S_regmatch(pTHX_ regnode *prog)
            }
            else
                PL_reginput = locinput;
+           PL_reg_flags ^= RF_false;
            goto do_ifmatch;
        case IFMATCH:
            n = 1;
@@ -3912,6 +3874,8 @@ S_regmatch(pTHX_ regnode *prog)
          do_ifmatch:
            inner = NEXTOPER(NEXTOPER(scan));
            if (regmatch(inner) != n) {
+               if (n == 0)
+                   PL_reg_flags ^= RF_false;
              say_no:
                if (logical) {
                    logical = 0;
@@ -3921,6 +3885,8 @@ S_regmatch(pTHX_ regnode *prog)
                else
                    sayNO;
            }
+           if (n == 0)
+               PL_reg_flags ^= RF_false;
          say_yes:
            if (logical) {
                logical = 0;