--- Lib\test\re_tests.py.orig 2003-04-20 00:35:44.000000000 -0700 +++ Lib\test\re_tests.py 2003-04-22 09:57:41.000000000 -0700 @@ -659,6 +659,13 @@ ('^([ab]*?)(?=(b)?)c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), ('^([ab]*?)(?!(b))c', 'abc', SUCCEED, 'g1+"-"+g2', 'ab-None'), ('^([ab]*?)(?repeat) { + i = mark_save(state, 0, lastmark); + if (i < 0) + return i; + } + } + /* If the subpattern in the assertion succeeds, it may leave marks + at the top of the mark stack. These marks reflect potential + backtrack points which were not needed because the subpattern + succeeded. Once the assertion completes, the overall pattern + will never backtrack into the assertion, so we need to be ready to + pop any marks pushed by the assertion to resynch the mark stack + with active backtrack points. */ + mark_stack_base = state->mark_stack_base; + + result = SRE_MATCH(state, pattern, level); + if (result < 0) + return result; + + if (result) + /* pop off any marks that may have been left by successful repeats + or branches */ + state->mark_stack_base = mark_stack_base; + else + /* subpattern should only fail after trying all backtrack points, + so, in case of failure, the top of the mark stack should be + the same as before executing the subpattern */ + assert(state->mark_stack_base == mark_stack_base); + + if (!positive) { + if (state->repeat) { + i = mark_restore(state, 0, lastmark); + if (i < 0) + return i; + } + LASTMARK_RESTORE(); + } + + if (positive) + return result; + else + return !result; +} + + +LOCAL(int) SRE_MATCH(SRE_STATE* state, SRE_CODE* pattern, int level) { /* check if string matches the given pattern. returns <0 for @@ -905,7 +971,7 @@ state->ptr = ptr - pattern[1]; if (state->ptr < state->beginning) return 0; - i = SRE_MATCH(state, pattern + 2, level + 1); + i = SRE_ASSERT(state, pattern + 2, level + 1, 1); if (i <= 0) return i; pattern += pattern[0]; @@ -917,11 +983,9 @@ TRACE(("|%p|%p|ASSERT_NOT %d\n", pattern, ptr, pattern[1])); state->ptr = ptr - pattern[1]; if (state->ptr >= state->beginning) { - i = SRE_MATCH(state, pattern + 2, level + 1); - if (i < 0) + i = SRE_ASSERT(state, pattern + 2, level + 1, 0); + if (i <= 0) return i; - if (i) - return 0; } pattern += pattern[0]; break;