@@ -4364,14 +4364,23 @@ Perl_regexec_flags(pTHX_ REGEXP * const rx, char *stringarg, char *strend,
4364
4364
}
4365
4365
4366
4366
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
+ }
4375
4384
4376
4385
4377
4386
/*
@@ -8528,7 +8537,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
8528
8537
ST .prev_rex = rex_sv ;
8529
8538
ST .prev_curlyx = cur_curlyx ;
8530
8539
rex_sv = re_sv ;
8531
- SET_reg_curpm ( rex_sv );
8540
+ S_set_reg_curpm ( aTHX_ rex_sv , reginfo );
8532
8541
rex = re ;
8533
8542
rexi = rei ;
8534
8543
cur_curlyx = NULL ;
@@ -8565,7 +8574,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
8565
8574
8566
8575
rex_sv = ST .prev_rex ;
8567
8576
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 );
8569
8578
rex = ReANY (rex_sv );
8570
8579
rexi = RXi_GET (rex );
8571
8580
{
@@ -8608,7 +8617,7 @@ S_regmatch(pTHX_ regmatch_info *reginfo, char *startpos, regnode *prog)
8608
8617
8609
8618
rex_sv = ST .prev_rex ;
8610
8619
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 );
8612
8621
rex = ReANY (rex_sv );
8613
8622
rexi = RXi_GET (rex );
8614
8623
@@ -9696,7 +9705,7 @@ NULL
9696
9705
st -> u .eval .cp = regcppush (rex , 0 , maxopenparen );
9697
9706
rex_sv = CUR_EVAL .prev_rex ;
9698
9707
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 );
9700
9709
rex = ReANY (rex_sv );
9701
9710
rexi = RXi_GET (rex );
9702
9711
@@ -11269,7 +11278,7 @@ S_setup_eval_state(pTHX_ regmatch_info *const reginfo)
11269
11278
}
11270
11279
#endif
11271
11280
}
11272
- SET_reg_curpm ( reginfo -> prog );
11281
+ S_set_reg_curpm ( aTHX_ reginfo -> prog , reginfo );
11273
11282
eval_state -> curpm = PL_curpm ;
11274
11283
PL_curpm_under = PL_curpm ;
11275
11284
PL_curpm = PL_reg_curpm ;
0 commit comments