From 94c8b9c1f0f31f0e85c11a61ad166ea156ae2b3a Mon Sep 17 00:00:00 2001 From: Nicolas R Date: Tue, 10 Mar 2020 11:14:04 -0600 Subject: Add macro to free and set cop_warnings This is avoiding the boilerplate to free the cop_warning string when setting it. --- mg.c | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'mg.c') diff --git a/mg.c b/mg.c index cd1f57de5a..b21f4d3c2b 100644 --- a/mg.c +++ b/mg.c @@ -2966,9 +2966,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) else if (strEQ(mg->mg_ptr+1, "ARNING_BITS")) { if ( ! (PL_dowarn & G_WARN_ALL_MASK)) { if (!SvPOK(sv)) { - if (!specialWARN(PL_compiling.cop_warnings)) - PerlMemShared_free(PL_compiling.cop_warnings); - PL_compiling.cop_warnings = pWARN_STD; + free_and_set_cop_warnings(PL_compiling, pWARN_STD); break; } { @@ -2980,26 +2978,22 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) not_all |= ptr[i] ^ 0x55; } if (!not_none) { - if (!specialWARN(PL_compiling.cop_warnings)) - PerlMemShared_free(PL_compiling.cop_warnings); - PL_compiling.cop_warnings = pWARN_NONE; + free_and_set_cop_warnings(PL_compiling, pWARN_NONE); } else if (len >= WARNsize && !not_all) { - if (!specialWARN(PL_compiling.cop_warnings)) - PerlMemShared_free(PL_compiling.cop_warnings); - PL_compiling.cop_warnings = pWARN_ALL; - PL_dowarn |= G_WARN_ONCE ; - } - else { - STRLEN len; - const char *const p = SvPV_const(sv, len); - - PL_compiling.cop_warnings - = Perl_new_warnings_bitfield(aTHX_ PL_compiling.cop_warnings, + free_and_set_cop_warnings(PL_compiling, pWARN_ALL); + PL_dowarn |= G_WARN_ONCE ; + } + else { + STRLEN len; + const char *const p = SvPV_const(sv, len); + + PL_compiling.cop_warnings + = Perl_new_warnings_bitfield(aTHX_ PL_compiling.cop_warnings, p, len); - if (isWARN_on(PL_compiling.cop_warnings, WARN_ONCE)) + if (isWARN_on(PL_compiling.cop_warnings, WARN_ONCE)) PL_dowarn |= G_WARN_ONCE ; - } + } } } -- cgit v1.2.1