In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/729aaeb502af62aff1b72f90b3d33e7218b94e0c?hp=39ea6a4bb86bea2953fbe16b8063fd13073507a0>
- Log ----------------------------------------------------------------- commit 729aaeb502af62aff1b72f90b3d33e7218b94e0c Author: Yves Orton <[email protected]> Date: Tue Mar 20 00:52:46 2012 +0100 correct logic error that meant that "last" might not be updated properly While checking into an unrelated issue I realized "last" might not be reset under certain circumstances. Although I could not find a way to make anything bad happen from perl, I decided to fix it, at worst we waste a few CPU cycles setting "last" to NULL more often than we should. M regcomp.c commit a40630bf5c45bc9d528e1eacffde2666ad23c6b2 Author: Yves Orton <[email protected]> Date: Tue Mar 20 00:46:45 2012 +0100 [RT #111842] prevent TRIE overwriting EXACT following NOTHING at start Fixes RT #111842. Example: "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/ Should match, but didn't due to allowing NOTHING to start a sequence. See comment in patch for details. This also changes a test to no longer be TODO, and improves the test name to explain its purpose. M regcomp.c M t/re/pat_advanced.t ----------------------------------------------------------------------- Summary of changes: regcomp.c | 39 +++++++++++++++++++++++++++------------ t/re/pat_advanced.t | 6 ++---- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/regcomp.c b/regcomp.c index 8c287bf..b106cc1 100644 --- a/regcomp.c +++ b/regcomp.c @@ -3325,11 +3325,23 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, if ( noper_trietype && ( - ( noper_trietype == NOTHING ) - || - ( trietype == NOTHING ) - || - ( trietype == noper_trietype ) + /* XXX: Currently we cannot allow a NOTHING node to be the first element + * of a TRIEABLE sequence, Otherwise we will overwrite the regop following + * the NOTHING with the TRIE regop later on. This is because a NOTHING node + * is only one regnode wide, and a TRIE is two regnodes. An example of a + * problematic pattern is: "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/ + * At a later point of time we can somewhat workaround this by handling + * NOTHING -> EXACT sequences as generated by /(?:)A|(?:)B/ type patterns, + * as we can effectively ignore the NOTHING regop in that case. + * This clause, which allows NOTHING to start a sequence is left commented + * out as a reference. + * - Yves + + ( noper_trietype == NOTHING) + || ( trietype == NOTHING ) + */ + ( noper_trietype == NOTHING && trietype ) + || ( trietype == noper_trietype ) ) #ifdef NOJUMPTRIE && noper_next == tail @@ -3354,13 +3366,16 @@ S_study_chunk(pTHX_ RExC_state_t *pRExC_state, regnode **scanp, /* handle unmergable node - * noper may either be a triable node which can not be tried * together with the current trie, or a non triable node */ - if ( last && trietype != NOTHING ) { - /* if last is set then we have found at least two triable branch - * sequences in a row of a similar trietype so we can turn them - * into a trie */ - make_trie( pRExC_state, - startbranch, first, cur, tail, count, - trietype, depth+1 ); + if ( last ) { + /* If last is set and trietype is not NOTHING then we have found + * at least two triable branch sequences in a row of a similar + * trietype so we can turn them into a trie. If/when we + * allow NOTHING to start a trie sequence this condition will be + * required, and it isn't expensive so we leave it in for now. */ + if ( trietype != NOTHING ) + make_trie( pRExC_state, + startbranch, first, cur, tail, count, + trietype, depth+1 ); last = NULL; /* note: we clear/update first, trietype etc below, so we dont do it here */ } if ( noper_trietype diff --git a/t/re/pat_advanced.t b/t/re/pat_advanced.t index 775f663..15f25b5 100644 --- a/t/re/pat_advanced.t +++ b/t/re/pat_advanced.t @@ -2069,10 +2069,8 @@ EOP like("\xC0", $p, "Verify \"\\xC0\" =~ /[\\xE0_]/i; pattern in utf8"); } - { - local $::TODO = 'RT #111842'; - ok "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/, "EXACT nodetypes"; - } + ok "x" =~ /\A(?>(?:(?:)A|B|C?x))\z/, + "Check TRIE does not overwrite EXACT following NOTHING at start - RT #111842"; # # Keep the following tests last -- they may crash perl -- Perl5 Master Repository
