Commit 2ff0d67766 for perl
commit 2ff0d67766dbb4ed25036510f9b7828a8a88427b
Author: David Mitchell <davem@iabyn.nospamdeletethisbit.com>
Date: Mon Oct 5 13:39:09 2026 +0100
regmatch: refactor some EVAL code
Re-order some of the code in the EVAL branch of S_regmatch().
Move some of the code which does more "regexy" stuff to be together
ahead of the code which is responsible for actually calling the perl
code within the (?{...}).
In a few commits' time, some of the code in the EVAL branch will be
moved into its own static function, and this change will help facilitate
that.
There should be no functional changes - it shouldn't matter what
order the various bits of set-up are done in.
diff --git a/regexec.c b/regexec.c
index a0e020d28f..baab4a7561 100644
--- a/regexec.c
+++ b/regexec.c
@@ -8995,6 +8995,23 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
} else {
nochange_depth = 0;
}
+
+ /* save *all* paren positions */
+ ST.cp = regcppush(rex, 0, maxopenparen);
+ REGCP_SET(ST.lastcp);
+
+ /* make $1 etc and pos available within called code */
+ RXp_OFFSp(rex)[0].end = locinput - reginfo->strbeg;
+ if (reginfo->info_aux_eval->pos_magic)
+ MgBYTEPOS_set(reginfo->info_aux_eval->pos_magic,
+ reginfo->sv, reginfo->strbeg,
+ locinput - reginfo->strbeg);
+
+ if (sv_yes_mark) {
+ SV *sv_mrk = get_sv("REGMARK", 1);
+ sv_setsv(sv_mrk, sv_yes_mark);
+ }
+
{
/* execute the code in the {...} */
@@ -9004,16 +9021,11 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
COP * const ocurcop = PL_curcop;
OP *nop;
CV *newcv;
-
- /* save *all* paren positions */
- ST.cp = regcppush(rex, 0, maxopenparen);
- REGCP_SET(ST.lastcp);
+ U32 n = EVAL_CODE_DATA_SLOT(scan);
if (!reginfo->caller_cv)
reginfo->caller_cv = find_runcv(NULL);
- n = EVAL_CODE_DATA_SLOT(scan);
-
if (rexi->data->what[n] == 'r') { /* code from an external qr */
newcv = (ReANY(
(REGEXP*)(rexi->data->data[n])
@@ -9138,17 +9150,6 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
DEBUG_STATE_r( re_printf(
" re EVAL PL_op = 0x%" UVxf "\n", PTR2UV(nop)) );
- RXp_OFFSp(rex)[0].end = locinput - reginfo->strbeg;
- if (reginfo->info_aux_eval->pos_magic)
- MgBYTEPOS_set(reginfo->info_aux_eval->pos_magic,
- reginfo->sv, reginfo->strbeg,
- locinput - reginfo->strbeg);
-
- if (sv_yes_mark) {
- SV *sv_mrk = get_sv("REGMARK", 1);
- sv_setsv(sv_mrk, sv_yes_mark);
- }
-
/* we don't use MULTICALL here as we want to call the
* first op of the block of interest, rather than the
* first op of the sub. Also, we don't want to free
@@ -9212,6 +9213,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
* be used again soon. This is safe as long as nothing
* in the regexp code uses the pad ! */
PL_op = oop;
+
PL_curcop = ocurcop;
regcp_restore(rex, ST.lastcp, &maxopenparen);
PL_curpm_under = PL_curpm;