Skip to content

Commit 7eec73e

Browse files
committed
move warning text to RExC_state (via RExC_warn_text)
This way we reuse the same AV each time, and avoid various refcount bookkeeping issues, all at a relatively modest cost (IMO)
1 parent 8c47236 commit 7eec73e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

regcomp.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct RExC_state_t {
199199
scan_frame *frame_head;
200200
scan_frame *frame_last;
201201
U32 frame_count;
202+
AV *warn_text;
202203
#ifdef ADD_TO_REGEXEC
203204
char *starttry; /* -Dr: where regtry was called. */
204205
#define RExC_starttry (pRExC_state->starttry)
@@ -290,6 +291,7 @@ struct RExC_state_t {
290291
#define RExC_frame_count (pRExC_state->frame_count)
291292
#define RExC_strict (pRExC_state->strict)
292293
#define RExC_study_started (pRExC_state->study_started)
294+
#define RExC_warn_text (pRExC_state->warn_text)
293295

294296
/* Heuristic check on the complexity of the pattern: if TOO_NAUGHTY, we set
295297
* a flag to disable back-off on the fixed/floating substrings - if it's
@@ -6764,6 +6766,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count,
67646766
#endif
67656767
}
67666768

6769+
pRExC_state->warn_text = NULL;
67676770
pRExC_state->code_blocks = NULL;
67686771
pRExC_state->num_code_blocks = 0;
67696772

@@ -13764,8 +13767,8 @@ S_populate_ANYOF_from_invlist(pTHX_ regnode *node, SV** invlist_ptr)
1376413767
* routine. q.v. */
1376513768
#define ADD_POSIX_WARNING(p, text) STMT_START { \
1376613769
if (posix_warnings) { \
13767-
if (! warn_text) warn_text = (AV *) sv_2mortal((SV *) newAV()); \
13768-
av_push(warn_text, Perl_newSVpvf(aTHX_ \
13770+
if (! RExC_warn_text ) RExC_warn_text = (AV *) sv_2mortal((SV *) newAV()); \
13771+
av_push(RExC_warn_text, Perl_newSVpvf(aTHX_ \
1376913772
WARNING_PREFIX \
1377013773
text \
1377113774
REPORT_LOCATION, \
@@ -13896,7 +13899,6 @@ S_handle_possible_posix(pTHX_ RExC_state_t *pRExC_state,
1389613899
bool has_opening_colon = FALSE;
1389713900
int class_number = OOB_NAMEDCLASS; /* Out-of-bounds until find
1389813901
valid class */
13899-
AV* warn_text = NULL; /* any warning messages */
1390013902
const char * possible_end = NULL; /* used for a 2nd parse pass */
1390113903
const char* name_start; /* ptr to class name first char */
1390213904

@@ -13912,6 +13914,9 @@ S_handle_possible_posix(pTHX_ RExC_state_t *pRExC_state,
1391213914

1391313915
PERL_ARGS_ASSERT_HANDLE_POSSIBLE_POSIX;
1391413916

13917+
if (posix_warnings && RExC_warn_text)
13918+
av_clear(RExC_warn_text);
13919+
1391513920
if (p >= e) {
1391613921
return NOT_MEANT_TO_BE_A_POSIX_CLASS;
1391713922
}
@@ -14529,10 +14534,9 @@ S_handle_possible_posix(pTHX_ RExC_state_t *pRExC_state,
1452914534
ADD_POSIX_WARNING(p, "there is no terminating ']'");
1453014535
}
1453114536

14532-
if (warn_text) {
14537+
if (posix_warnings && av_top_index(RExC_warn_text) > -1) {
1453314538
/* warn_text should only be true if posix_warnings is true */
14534-
assert(posix_warnings);
14535-
*posix_warnings = warn_text;
14539+
*posix_warnings = RExC_warn_text;
1453614540
}
1453714541
}
1453814542
else if (class_number != OOB_NAMEDCLASS) {

0 commit comments

Comments
 (0)