Third consting batch
[p5sagit/p5-mst-13.2.git] / regexec.c
index 9efb479..fb84645 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -98,6 +98,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)
 
@@ -874,7 +875,7 @@ Perl_re_intuit_start(pTHX_ regexp *prog, SV *sv, char *strpos,
        s = find_byclass(prog, prog->regstclass, s, endpos, startpos, 1);
        if (!s) {
 #ifdef DEBUGGING
-           char *what = 0;
+           const char *what = 0;
 #endif
            if (endpos == strend) {
                DEBUG_EXECUTE_r( PerlIO_printf(Perl_debug_log,
@@ -2264,50 +2265,6 @@ typedef union re_unwind_t {
 #define sayNO_SILENT goto do_no
 #define saySAME(x) if (x) goto yes; else goto no
 
-#define POSCACHE_SUCCESS 0     /* caching success rather than failure */
-#define POSCACHE_SEEN 1                /* we know what we're caching */
-#define POSCACHE_START 2       /* the real cache: this bit maps to pos 0 */
-#define CACHEsayYES STMT_START { \
-    if (PL_reg_poscache) { \
-       if (!(PL_reg_poscache[0] & (1<<POSCACHE_SEEN))) \
-           PL_reg_poscache[0] |= (1<<POSCACHE_SUCCESS) || (1<<POSCACHE_SEEN); \
-        else if (!(PL_reg_poscache[0] & (1<<POSCACHE_SUCCESS))) { \
-           /* cache records failure, but this is success */ \
-           I32 o = locinput - PL_bostr, b; \
-           o = (scan->flags & 0xf) - 1 + POSCACHE_START + o * (scan->flags>>4); \
-           b = o % 8; \
-           o /= 8; \
-           DEBUG_r( \
-               PerlIO_printf(Perl_debug_log, \
-                   "%*s  (remove success from failure cache)\n", \
-                   REPORT_CODE_OFF+PL_regindent*2, "") \
-           ); \
-           PL_reg_poscache[o] &= ~(1<<b); \
-       } \
-    } \
-    sayYES; \
-} STMT_END
-#define CACHEsayNO STMT_START { \
-    if (PL_reg_poscache) { \
-       if (!(PL_reg_poscache[0] & (1<<POSCACHE_SEEN))) \
-           PL_reg_poscache[0] |= (1<<POSCACHE_SEEN); \
-        else if ((PL_reg_poscache[0] & (1<<POSCACHE_SUCCESS))) { \
-           /* cache records success, but this is failure */ \
-           I32 o = locinput - PL_bostr, b; \
-           o = (scan->flags & 0xf) - 1 + POSCACHE_START + o * (scan->flags>>4); \
-           b = o % 8; \
-           o /= 8; \
-           DEBUG_r( \
-               PerlIO_printf(Perl_debug_log, \
-                   "%*s  (remove failure from success cache)\n", \
-                   REPORT_CODE_OFF+PL_regindent*2, "") \
-           ); \
-           PL_reg_poscache[o] &= ~(1<<b); \
-       } \
-    } \
-    sayNO; \
-} STMT_END
-
 /* this is used to determine how far from the left messages like
    'failed...' are printed. Currently 29 makes these messages line
    up with the opcode they refer to. Earlier perls used 25 which
@@ -2361,7 +2318,8 @@ typedef union re_unwind_t {
             }                                                           \
         }                                                               \
         if ( charid &&                                                  \
-             ( base + charid - 1 - trie->uniquecharcount ) >=0  &&      \
+             ( base + charid > trie->uniquecharcount ) &&               \
+             ( base + charid - 1 - trie->uniquecharcount < trie->lasttrans) && \
              trie->trans[ base + charid - 1 - trie->uniquecharcount ].check == state ) \
         {                                                               \
             state = trie->trans[ base + charid - 1 - trie->uniquecharcount ].next;     \
@@ -2731,7 +2689,7 @@ S_regmatch(pTHX_ regnode *prog)
                            tmp ? SvPV_nolen( *tmp ) : "not compiled under -Dr",
                            PL_colors[5] );
                    });
-                   PL_reginput = accept_buff[ 0 ].endpos;
+                   PL_reginput = (char *)accept_buff[ 0 ].endpos;
                    /* in this case we free tmps/leave before we call regmatch
                       as we wont be using accept_buff again. */
                    FREETMPS;
@@ -2772,7 +2730,7 @@ S_regmatch(pTHX_ regnode *prog)
                            accept_buff[ accepted ] = tmp;
                            best = accepted;
                        }
-                       PL_reginput = accept_buff[ best ].endpos;
+                       PL_reginput = (char *)accept_buff[ best ].endpos;
 
                         /* 
                            as far as I can tell we only need the SAVETMPS/FREETMPS 
@@ -3544,7 +3502,7 @@ S_regmatch(pTHX_ regnode *prog)
                    PL_reg_leftiter = PL_reg_maxiter;
                }
                if (PL_reg_leftiter-- == 0) {
-                   I32 size = (PL_reg_maxiter + 7 + POSCACHE_START)/8;
+                   I32 size = (PL_reg_maxiter + 7)/8;
                    if (PL_reg_poscache) {
                        if ((I32)PL_reg_poscache_size < size) {
                            Renew(PL_reg_poscache, size, char);
@@ -3565,7 +3523,7 @@ S_regmatch(pTHX_ regnode *prog)
                if (PL_reg_leftiter < 0) {
                    I32 o = locinput - PL_bostr, b;
 
-                   o = (scan->flags & 0xf) - 1 + POSCACHE_START + o * (scan->flags>>4);
+                   o = (scan->flags & 0xf) - 1 + o * (scan->flags>>4);
                    b = o % 8;
                    o /= 8;
                    if (PL_reg_poscache[o] & (1<<b)) {
@@ -3574,11 +3532,9 @@ S_regmatch(pTHX_ regnode *prog)
                                      "%*s  already tried at this position...\n",
                                      REPORT_CODE_OFF+PL_regindent*2, "")
                        );
-                       if (PL_reg_poscache[0] & (1<<POSCACHE_SUCCESS))
-                           /* cache records success */
+                       if (PL_reg_flags & RF_false)
                            sayYES;
                        else
-                           /* cache records failure */
                            sayNO_SILENT;
                    }
                    PL_reg_poscache[o] |= (1<<b);
@@ -3595,7 +3551,7 @@ S_regmatch(pTHX_ regnode *prog)
                    REGCP_SET(lastcp);
                    if (regmatch(cc->next)) {
                        regcpblow(cp);
-                       CACHEsayYES;    /* All done. */
+                       sayYES; /* All done. */
                    }
                    REGCP_UNWIND(lastcp);
                    regcppop();
@@ -3611,7 +3567,7 @@ S_regmatch(pTHX_ regnode *prog)
                                 "Complex regular subexpression recursion",
                                 REG_INFTY - 1);
                        }
-                       CACHEsayNO;
+                       sayNO;
                    }
 
                    DEBUG_EXECUTE_r(
@@ -3627,13 +3583,13 @@ S_regmatch(pTHX_ regnode *prog)
                    REGCP_SET(lastcp);
                    if (regmatch(cc->scan)) {
                        regcpblow(cp);
-                       CACHEsayYES;
+                       sayYES;
                    }
                    REGCP_UNWIND(lastcp);
                    regcppop();
                    cc->cur = n - 1;
                    cc->lastloc = lastloc;
-                   CACHEsayNO;
+                   sayNO;
                }
 
                /* Prefer scan over next for maximal matching. */
@@ -3645,7 +3601,7 @@ S_regmatch(pTHX_ regnode *prog)
                    REGCP_SET(lastcp);
                    if (regmatch(cc->scan)) {
                        regcpblow(cp);
-                       CACHEsayYES;
+                       sayYES;
                    }
                    REGCP_UNWIND(lastcp);
                    regcppop();         /* Restore some previous $<digit>s? */
@@ -3669,13 +3625,13 @@ S_regmatch(pTHX_ regnode *prog)
                if (PL_regcc)
                    ln = PL_regcc->cur;
                if (regmatch(cc->next))
-                   CACHEsayYES;
+                   sayYES;
                if (PL_regcc)
                    PL_regcc->cur = ln;
                PL_regcc = cc;
                cc->cur = n - 1;
                cc->lastloc = lastloc;
-               CACHEsayNO;
+               sayNO;
            }
            /* NOT REACHED */
        case BRANCHJ:
@@ -4212,6 +4168,7 @@ S_regmatch(pTHX_ regnode *prog)
            }
            else
                PL_reginput = locinput;
+           PL_reg_flags ^= RF_false;
            goto do_ifmatch;
        case IFMATCH:
            n = 1;
@@ -4227,6 +4184,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;
@@ -4236,6 +4195,8 @@ S_regmatch(pTHX_ regnode *prog)
                else
                    sayNO;
            }
+           if (n == 0)
+               PL_reg_flags ^= RF_false;
          say_yes:
            if (logical) {
                logical = 0;