From 1797763e57261b83409b910ca28f31dc8885e3c0 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Sat, 13 Dec 2025 20:49:36 +0000 Subject: [PATCH] regex: don't LEAVE_SCOPE() in S_regtry() This commit should produce no practical change in functionality. Currently, S_regtry() notes the position of PL_savestack_ix, calls S_regmatch(), then pops the savestack back to that position. However, S_regmatch() also does this just before returning, so it's redundant in S_regtry(). (A temporary assert confirmed that lastcp == PL_savestack_ix in S_regtry always while running the test suite). So this commit removes the REGCP_UNWIND(lastcp) and associated machinery from S_regtry(). It also regularises the "note current ix; pop back to old ix" code at the start and end of S_regmatch() to use the standard REGCP_SET() and REGCP_UNWIND() macros which do the same thing but also produce debugging messages. --- regexec.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/regexec.c b/regexec.c index b62c011f58..c854666f1c 100644 --- a/regexec.c +++ b/regexec.c @@ -4408,13 +4408,9 @@ S_set_reg_curpm(pTHX_ REGEXP *rx, regmatch_info *reginfo) STATIC bool /* 0 failure, 1 success */ S_regtry(pTHX_ regmatch_info *reginfo, char **startposp) { - CHECKPOINT lastcp; REGEXP *const rx = reginfo->prog; regexp *const prog = ReANY(rx); SSize_t result; -#ifdef DEBUGGING - U32 depth = 0; /* used by REGCP_SET */ -#endif RXi_GET_DECL(prog,progi); DECLARE_AND_GET_RE_DEBUG_FLAGS; @@ -4458,7 +4454,6 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startposp) } } #endif - REGCP_SET(lastcp); result = regmatch(reginfo, *startposp, progi->program + 1); if (result != -1) { RXp_OFFSp(prog)[0].end = result; @@ -4466,7 +4461,6 @@ S_regtry(pTHX_ regmatch_info *reginfo, char **startposp) } if (reginfo->cutpoint) *startposp= reginfo->cutpoint; - REGCP_UNWIND(lastcp); return 0; } @@ -6712,7 +6706,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) char_class_number_ classnum; bool is_utf8_pat = reginfo->is_utf8_pat; bool match = false; - I32 orig_savestack_ix = PL_savestack_ix; + I32 orig_savestack_ix; U8 * script_run_begin = NULL; char *match_end= NULL; /* where a match MUST end to be considered successful */ bool is_accepted = false; /* have we hit an ACCEPT opcode? */ @@ -6747,6 +6741,8 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog) Perl_re_printf( aTHX_ "regmatch start\n" ); })); + REGCP_SET(orig_savestack_ix); + while (scan != NULL) { next = scan + NEXT_OFF(scan); if (next == scan) @@ -10399,8 +10395,9 @@ NULL POP_MULTICALL; PERL_UNUSED_VAR(SP); } - else - LEAVE_SCOPE(orig_savestack_ix); + else { + REGCP_UNWIND(orig_savestack_ix); + } if ( reginfo->info_aux_eval && reginfo->info_aux_eval->final_replsv)