Commit 34a2a824c2 for perl

commit 34a2a824c2afaf716146466c17b649105525463d
Author: David Mitchell <davem@iabyn.nospamdeletethisbit.com>
Date:   Mon Oct 5 12:53:48 2026 +0100

    regmatch: refactor: move some auto vars to reginfo

    Remove these local vars from S_regmatch():

        caller_cv
        last_pushed_cv
        last_pad

    and instead, make them be new fields in the reginfo struct. That struct
    is intended for variables which are local to the match but which need to
    be accessed from multiple functions.

    In a few commits' time, some of the code in the EVAL branch will be
    moved into its own static function, so this change will make it easier
    to share the state contained in those variables.

    Should be no functional changes.

diff --git a/regexec.c b/regexec.c
index 62ddaa9c43..c7a1677dd8 100644
--- a/regexec.c
+++ b/regexec.c
@@ -7234,11 +7234,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                                      type such as \1 or (??{...}. For more
                                      details, see
                                      L<perlreguts/The super-linear cache> */
-    PAD* last_pad = NULL;
     dMULTICALL;
     U8 gimme = G_SCALAR;
-    CV *caller_cv = NULL;	/* who called us */
-    CV *last_pushed_cv = NULL;	/* most recently called (?{}) CV */
     U32 maxopenparen = 0;       /* max '(' index seen so far */
     int to_complement;  /* Invert the result? */
     char_class_number_ classnum;
@@ -7261,6 +7258,10 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
 #ifdef DEBUGGING
     DECLARE_AND_GET_RE_DEBUG_FLAGS;
 #endif
+    /* some state used by (?{...}) and friends */
+    reginfo->last_pushed_cv = NULL;
+    reginfo->caller_cv      = NULL;
+    reginfo->last_pad       = NULL;

     /* shut up 'may be used uninitialized' compiler warnings for dMULTICALL */
     multicall_oldcatch = 0;
@@ -9013,8 +9014,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                 ST.cp = regcppush(rex, 0, maxopenparen);
                 REGCP_SET(ST.lastcp);

-                if (!caller_cv)
-                    caller_cv = find_runcv(NULL);
+                if (!reginfo->caller_cv)
+                    reginfo->caller_cv = find_runcv(NULL);

                 n = EVAL_CODE_DATA_SLOT(scan);

@@ -9025,7 +9026,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                     nop = (OP*)rexi->data->data[n+1];
                 }
                 else if (rexi->data->what[n] == 'l') { /* literal code */
-                    newcv = caller_cv;
+                    newcv = reginfo->caller_cv;
                     nop = (OP*)rexi->data->data[n];
                     assert(CvDEPTH(newcv));
                 }
@@ -9083,12 +9084,14 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                  * if PL_comppad has got messed up from backtracking
                  * through SAVECOMPPADs, then refresh the context.
                  */
-                if (newcv != last_pushed_cv || PL_comppad != last_pad)
+                if (   newcv      != reginfo->last_pushed_cv
+                    || PL_comppad != reginfo->last_pad)
                 {
                     U8 flags = (CXp_SUB_RE |
-                                ((newcv == caller_cv) ? CXp_SUB_RE_FAKE : 0));
+                                ((newcv == reginfo->caller_cv)
+                                            ? CXp_SUB_RE_FAKE : 0));
                     SAVECOMPPAD();
-                    if (last_pushed_cv) {
+                    if (reginfo->last_pushed_cv) {
                         CHANGE_MULTICALL_FLAGS(newcv, flags);
                     }
                     else {
@@ -9097,14 +9100,14 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
                     /* see notes above */
                     CX_CUR()->blk_oldsaveix = orig_savestack_ix;

-                    last_pushed_cv = newcv;
+                    reginfo->last_pushed_cv = newcv;
                 }
                 else {
                     /* these assignments are just to silence compiler
                      * warnings */
                     multicall_cop = NULL;
                 }
-                last_pad = PL_comppad;
+                reginfo->last_pad = PL_comppad;

                 /* the initial nextstate you would normally execute
                  * at the start of an eval (which would cause error
@@ -11065,7 +11068,7 @@ NULL
     }


-    if (last_pushed_cv) {
+    if (reginfo->last_pushed_cv) {
         dSP;
         /* see "Some notes about MULTICALL" above, especially how
          * the POP_MULTICALL does the equivalent of the LEAVE_SCOPE
diff --git a/regexp.h b/regexp.h
index dab3be3e1d..e0f620169d 100644
--- a/regexp.h
+++ b/regexp.h
@@ -845,6 +845,12 @@ typedef struct {
     bool is_utf8_pat;    /* regex is utf8 */
     bool is_utf8_target; /* string being matched is utf8 */
     bool warned; /* we have issued a recursion warning; no need for more */
+
+    /* Some state cached between calls to (?{...}) to potentially
+     * make further calls more efficient */
+    CV *caller_cv;       /* who called us: a cached find_runcv(NULL) */
+    CV *last_pushed_cv;  /* most recently called (?{...}) CV */
+    PAD* last_pad;       /* pad used for last (?{...}) execution */
 } regmatch_info;