This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #117917] /(?{ m|...| }) (?{ $1 })/
A regular expression invoked inside a regular expression code block
can cause other code blocks in the same outer regular expression to
see the wrong values in $1.
PL_curpm holds a pointer to the match operator from which $1, $2, etc.
get their values.
Normally PL_curpm is set at the end of a match.
When code blocks are embedded inside a regular expression, PL_curpm
is set during a match to point to PL_reg_curpm, which is a dummy op
pointing to the current regular expression.
S_setup_eval_state is called at the beginning of regexp execution.
It is responsible for setting up PL_regcurpm and making PL_curpm
point to it.
Code blocks are executed using the multicall API. PUSH_MULTICALL
records the value of PL_curpm and POP_MULTICALL makes sure that the
previous value of PL_curpm is restored.
Executing a code block can cause PL_curpm to point to something else.
Since we don’t necessarily do POP_MULTICALL between code block calls
within a single regular expression (sometimes we do, depending on
backtracking), PL_curpm may not have been restored when a second code
block fires. So we have to restore it to point to PL_reg_curpm manu-
ally after calling a code block.