diff options
author | Karl Williamson <khw@cpan.org> | 2018-10-14 20:16:03 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2018-10-20 00:09:55 -0600 |
commit | ed68fe11532c7073e43da9e3cb5f6d4409c44c16 (patch) | |
tree | 184f7894fa1d4648b81736dc8546d281f868fe0a | |
parent | 0a0ee7b8b14e71974adcfd6457c0d0a5486c28aa (diff) | |
download | perl-ed68fe11532c7073e43da9e3cb5f6d4409c44c16.tar.gz |
Consolidate code into a single macro
If we die during the code generation phase, we set the regex SV to be
freed during cleanup.
This consolidates many of those instances into one macro, so that it can
be easily changed. And instead of tieing it to the particular phase, we
clean up whenever that SV actually exists. This requires initializing
it to NULL.
-rw-r--r-- | regcomp.c | 29 |
1 files changed, 15 insertions, 14 deletions
@@ -683,6 +683,13 @@ static const scan_data_t zero_scan_data = { * past a nul byte. */ #define SKIP_IF_CHAR(s) (!*(s) ? 0 : UTF ? UTF8SKIP(s) : 1) +/* Set up to clean up after our imminent demise */ +#define PREPARE_TO_DIE \ + STMT_START { \ + if (RExC_rx_sv) \ + SAVEFREESV(RExC_rx_sv); \ + } STMT_END + /* * Calls SAVEDESTRUCTOR_X if needed, then calls Perl_croak with the given * arg. Show regex, up to a maximum length. If it's too long, chop and add @@ -692,8 +699,7 @@ static const scan_data_t zero_scan_data = { const char *ellipses = ""; \ IV len = RExC_precomp_end - RExC_precomp; \ \ - if (!SIZE_ONLY) \ - SAVEFREESV(RExC_rx_sv); \ + PREPARE_TO_DIE; \ if (len > RegexLengthToShowInErrorMessages) { \ /* chop 10 shorter than the max, to ensure meaning of "..." */ \ len = RegexLengthToShowInErrorMessages - 10; \ @@ -722,8 +728,7 @@ static const scan_data_t zero_scan_data = { * Calls SAVEDESTRUCTOR_X if needed, then Simple_vFAIL() */ #define vFAIL(m) STMT_START { \ - if (!SIZE_ONLY) \ - SAVEFREESV(RExC_rx_sv); \ + PREPARE_TO_DIE; \ Simple_vFAIL(m); \ } STMT_END @@ -739,8 +744,7 @@ static const scan_data_t zero_scan_data = { * Calls SAVEDESTRUCTOR_X if needed, then Simple_vFAIL2(). */ #define vFAIL2(m,a1) STMT_START { \ - if (!SIZE_ONLY) \ - SAVEFREESV(RExC_rx_sv); \ + PREPARE_TO_DIE; \ Simple_vFAIL2(m, a1); \ } STMT_END @@ -757,8 +761,7 @@ static const scan_data_t zero_scan_data = { * Calls SAVEDESTRUCTOR_X if needed, then Simple_vFAIL3(). */ #define vFAIL3(m,a1,a2) STMT_START { \ - if (!SIZE_ONLY) \ - SAVEFREESV(RExC_rx_sv); \ + PREPARE_TO_DIE; \ Simple_vFAIL3(m, a1, a2); \ } STMT_END @@ -771,22 +774,19 @@ static const scan_data_t zero_scan_data = { } STMT_END #define vFAIL4(m,a1,a2,a3) STMT_START { \ - if (!SIZE_ONLY) \ - SAVEFREESV(RExC_rx_sv); \ + PREPARE_TO_DIE; \ Simple_vFAIL4(m, a1, a2, a3); \ } STMT_END /* A specialized version of vFAIL2 that works with UTF8f */ #define vFAIL2utf8f(m, a1) STMT_START { \ - if (!SIZE_ONLY) \ - SAVEFREESV(RExC_rx_sv); \ + PREPARE_TO_DIE; \ S_re_croak2(aTHX_ UTF, m, REPORT_LOCATION, a1, \ REPORT_LOCATION_ARGS(RExC_parse)); \ } STMT_END #define vFAIL3utf8f(m, a1, a2) STMT_START { \ - if (!SIZE_ONLY) \ - SAVEFREESV(RExC_rx_sv); \ + PREPARE_TO_DIE; \ S_re_croak2(aTHX_ UTF, m, REPORT_LOCATION, a1, a2, \ REPORT_LOCATION_ARGS(RExC_parse)); \ } STMT_END @@ -7141,6 +7141,7 @@ Perl_re_op_compile(pTHX_ SV ** const patternp, int pat_count, /* ignore the utf8ness if the pattern is 0 length */ RExC_utf8 = RExC_orig_utf8 = (plen == 0 || IN_BYTES) ? 0 : SvUTF8(pat); + RExC_rx_sv = NULL; \ RExC_uni_semantics = 0; RExC_seen_unfolded_sharp_s = 0; RExC_contains_locale = 0; |