diff options
author | Karl Williamson <khw@cpan.org> | 2015-01-05 13:17:58 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2015-01-13 12:01:03 -0700 |
commit | 67cdf558540fcb50072632cb50aa953c0583f350 (patch) | |
tree | 82939f4dd1b0c3783defc60226f6b39dda11d87e /regcomp.c | |
parent | af631a26a8f5a7d7136bf909c27dbba1a2d49690 (diff) | |
download | perl-67cdf558540fcb50072632cb50aa953c0583f350.tar.gz |
Add 'strict' subpragma to 'use re'
This subpragma is to allow p5p to add warnings/errors for regex patterns
without having to worry about backwards compatibility. And it allows
users who want to have the latest checks on their code to do so. An
experimental warning is raised by default when it is used, not because
the subpragma might go away, but because what it catches is subject to
change from release-to-release, and so the user is acknowledging that
they waive the right to backwards compatibility. I will be working in
the near term to make some changes to what is detected by this.
Note that there is no indication in the pattern stringification that it
was compiled under this. This means I didn't have to figure out how to
stringify it. It is fine because using this doesn't affect what the
pattern gets compiled into, if successful. And interpolating the
stringified pattern under either strict or non-strict should both just
work.
Diffstat (limited to 'regcomp.c')
-rw-r--r-- | regcomp.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -184,6 +184,7 @@ struct RExC_state_t { scan_frame *frame_head; scan_frame *frame_last; U32 frame_count; + U32 strict; #ifdef ADD_TO_REGEXEC char *starttry; /* -Dr: where regtry was called. */ #define RExC_starttry (pRExC_state->starttry) @@ -253,6 +254,7 @@ struct RExC_state_t { #define RExC_frame_head (pRExC_state->frame_head) #define RExC_frame_last (pRExC_state->frame_last) #define RExC_frame_count (pRExC_state->frame_count) +#define RExC_strict (pRExC_state->strict) /* Heuristic check on the complexity of the pattern: if TOO_NAUGHTY, we set * a flag to disable back-off on the fixed/floating substrings - if it's @@ -6532,6 +6534,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count, RExC_uni_semantics = 0; RExC_contains_locale = 0; RExC_contains_i = 0; + RExC_strict = cBOOL(pm_flags & RXf_PMf_STRICT); pRExC_state->runtime_code_qr = NULL; RExC_frame_head= NULL; RExC_frame_last= NULL; @@ -11648,7 +11651,7 @@ tryagain: FALSE, /* means parse the whole char class */ TRUE, /* allow multi-char folds */ FALSE, /* don't silence non-portable warnings. */ - FALSE, /* not strict */ + RExC_strict, NULL); if (*RExC_parse != ']') { RExC_parse = oregcomp_parse; @@ -11884,7 +11887,7 @@ tryagain: FALSE, /* don't silence non-portable warnings. It would be a bug if these returned non-portables */ - FALSE, /* not strict */ + RExC_strict, NULL); /* regclass() can only return RESTART_UTF8 if multi-char folds are allowed. */ @@ -12259,7 +12262,7 @@ tryagain: &result, &error_msg, PASS2, /* out warnings */ - FALSE, /* not strict */ + RExC_strict, TRUE, /* Output warnings for non- portables */ @@ -12288,7 +12291,7 @@ tryagain: &result, &error_msg, PASS2, /* out warnings */ - FALSE, /* not strict */ + RExC_strict, TRUE, /* Output warnings for non- portables */ |