Skip to content

Commit b895bb2

Browse files
committed
regexec.c: convert SET_reg_curpm() to static fn
Convert the SET_reg_curpm() file-scoped macro into a static function, S_set_reg_curpm(). This makes debugging and any future enhancements easier.
1 parent 257ab4e commit b895bb2

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

regexec.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4364,14 +4364,23 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
43644364
}
43654365

43664366

4367-
/* Set which rex is pointed to by PL_reg_curpm, handling ref counting.
4368-
* Do inc before dec, in case old and new rex are the same */
4369-
#define SET_reg_curpm(Re2) \
4370-
if (reginfo->info_aux_eval) { \
4371-
(void)ReREFCNT_inc(Re2); \
4372-
ReREFCNT_dec(PM_GETRE(PL_reg_curpm)); \
4373-
PM_SETRE((PL_reg_curpm), (Re2)); \
4374-
}
4367+
/* Set which rex is pointed to by PL_reg_curpm (which is the fake global
4368+
* PMOP used to make $1 etc available while executing (?{...}) code).
4369+
* Handles ref counting.
4370+
*/
4371+
4372+
static void
4373+
S_set_reg_curpm(pTHX_ REGEXP *rx, regmatch_info *reginfo)
4374+
{
4375+
if (!reginfo->info_aux_eval)
4376+
return;
4377+
4378+
REGEXP *old_rx = PM_GETRE(PL_reg_curpm);
4379+
/* Do inc before dec, in case old and new rex are the same. */
4380+
SvREFCNT_inc(rx);
4381+
PM_SETRE(PL_reg_curpm, rx);
4382+
SvREFCNT_dec(old_rx);
4383+
}
43754384

43764385

43774386
/*
@@ -8528,7 +8537,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
85288537
ST.prev_rex = rex_sv;
85298538
ST.prev_curlyx = cur_curlyx;
85308539
rex_sv = re_sv;
8531-
SET_reg_curpm(rex_sv);
8540+
S_set_reg_curpm(aTHX_ rex_sv, reginfo);
85328541
rex = re;
85338542
rexi = rei;
85348543
cur_curlyx = NULL;
@@ -8565,7 +8574,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
85658574

85668575
rex_sv = ST.prev_rex;
85678576
is_utf8_pat = reginfo->is_utf8_pat = cBOOL(RX_UTF8(rex_sv));
8568-
SET_reg_curpm(rex_sv);
8577+
S_set_reg_curpm(aTHX_ rex_sv, reginfo);
85698578
rex = ReANY(rex_sv);
85708579
rexi = RXi_GET(rex);
85718580
{
@@ -8608,7 +8617,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
86088617

86098618
rex_sv = ST.prev_rex;
86108619
is_utf8_pat = reginfo->is_utf8_pat = cBOOL(RX_UTF8(rex_sv));
8611-
SET_reg_curpm(rex_sv);
8620+
S_set_reg_curpm(aTHX_ rex_sv, reginfo);
86128621
rex = ReANY(rex_sv);
86138622
rexi = RXi_GET(rex);
86148623

@@ -9696,7 +9705,7 @@ NULL
96969705
st->u.eval.cp = regcppush(rex, 0, maxopenparen);
96979706
rex_sv = CUR_EVAL.prev_rex;
96989707
is_utf8_pat = reginfo->is_utf8_pat = cBOOL(RX_UTF8(rex_sv));
9699-
SET_reg_curpm(rex_sv);
9708+
S_set_reg_curpm(aTHX_ rex_sv, reginfo);
97009709
rex = ReANY(rex_sv);
97019710
rexi = RXi_GET(rex);
97029711

@@ -11269,7 +11278,7 @@ S_setup_eval_state(pTHX_ regmatch_info *const reginfo)
1126911278
}
1127011279
#endif
1127111280
}
11272-
SET_reg_curpm(reginfo->prog);
11281+
S_set_reg_curpm(aTHX_ reginfo->prog, reginfo);
1127311282
eval_state->curpm = PL_curpm;
1127411283
PL_curpm_under = PL_curpm;
1127511284
PL_curpm = PL_reg_curpm;

0 commit comments

Comments
 (0)