This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regexec.c - make REF into a backtracking state
authorYves Orton <demerphq@gmail.com>
Sat, 14 Jan 2023 13:38:38 +0000 (14:38 +0100)
committerYves Orton <demerphq@gmail.com>
Mon, 13 Mar 2023 13:26:08 +0000 (21:26 +0800)
commit59db194299c94c6707095797c3df0e2f67ff82b2
treec016d5aabc09854ca74f22570efe64a72847018b
parent38508ce8fc3a1bd12a3bb65e9d4ceb9b396a18db
regexec.c - make REF into a backtracking state

This way we can do the required paren restoration only when it is in use. When
we match a REF type node which is potentially a reference to an unclosed paren
we push the match context information, currently for "everything", but in a
future patch we can teach it to be more efficient by adding a new parameter to
the REF regop to track which parens it should save.

This converts the backtracking changes from the previous commit, so that it is
run only when specifically enabled via the define RE_PESSIMISTIC_PARENS which
is by default 0. We don't make the new fields in the struct conditional as the
stack frames are large and our changes don't make any real difference and it
keeps things simpler to not have conditional members, especially since some of
the structures have to line up with each other.

If enabling RE_PESSIMISTIC_PARENS fixes a backtracking bug then it means
something is sensitive to us not necessarily restoring the parens properly on
failure. We make some assumptions that the paren state after a failing state
will be corrected by a future successful state, or that the state of the
parens is irrelevant as we will fail anyway. This can be made not true by
EVAL, backrefs, and potentially some other scenarios. Thus I have left this
inefficient logic in place but guarded by the flag.
regcomp.c
regcomp.h
regcomp.sym
regcomp_internal.h
regexec.c
regexp.h
regnodes.h