@@ -9069,6 +9069,103 @@ Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
90699069 return op_prepend_elem(OP_LINESEQ, (OP*)cop, o);
90709070}
90719071
9072+ /*
9073+ =for apidoc cop_has_warning
9074+
9075+ Returns true if the set of warnings bits contained by (or implied by) the
9076+ COP contains the given warning, as specified by one of the C<WARN_...>
9077+ constants from F<warnings.h>.
9078+
9079+ =cut
9080+ */
9081+
9082+ bool
9083+ Perl_cop_has_warning(pTHX_ const COP *cop, int warn_bit)
9084+ {
9085+ PERL_ARGS_ASSERT_COP_HAS_WARNING;
9086+
9087+ const char *warning_bits = cop->cop_warnings;
9088+ if(warning_bits == pWARN_STD)
9089+ return (PL_dowarn & G_WARN_ON) ? true : PerlWarnIsSet_(WARN_DEFAULTstring, 2*warn_bit);
9090+ else if(warning_bits == pWARN_ALL)
9091+ return true;
9092+ else if(warning_bits == pWARN_NONE)
9093+ return false;
9094+ else
9095+ return isWARN_on(cop->cop_warnings, warn_bit);
9096+ }
9097+
9098+ #define cop_inplace_expand_warning_bitmask(cop) S_cop_inplace_expand_warning_bitmask(aTHX_ cop)
9099+ STATIC void
9100+ S_cop_inplace_expand_warning_bitmask(pTHX_ COP *cop)
9101+ {
9102+ const char *warning_bits = cop->cop_warnings;
9103+
9104+ if(warning_bits == pWARN_STD)
9105+ warning_bits = (PL_dowarn & G_WARN_ON) ? WARN_ALLstring : WARN_DEFAULTstring;
9106+ else if(warning_bits == pWARN_ALL)
9107+ warning_bits = WARN_ALLstring;
9108+ else if(warning_bits == pWARN_NONE)
9109+ warning_bits = WARN_NONEstring;
9110+
9111+ /* Must allocate the new one before we throw the old buffer away */
9112+ char *new_warnings = Perl_new_warnings_bitfield(aTHX_ NULL, warning_bits, WARNsize);
9113+ free_and_set_cop_warnings(cop, new_warnings);
9114+ }
9115+
9116+ /*
9117+ =for apidoc cop_enable_warning
9118+
9119+ Ensures that the set of warning bits contained by the COP includes the given
9120+ warning, as specified by one of the C<WARN_...> constants from F<warnings.h>.
9121+
9122+ If the COP already includes the warning, no modification is made. Otherwise,
9123+ the stored warning bitmask is cloned, and the given warning bit is enabled
9124+ within it.
9125+
9126+ =cut
9127+ */
9128+
9129+ void
9130+ Perl_cop_enable_warning(pTHX_ COP *cop, int warn_bit)
9131+ {
9132+ PERL_ARGS_ASSERT_COP_ENABLE_WARNING;
9133+
9134+ if(cop_has_warning(cop, warn_bit))
9135+ return;
9136+
9137+ cop_inplace_expand_warning_bitmask(cop);
9138+
9139+ cop->cop_warnings[Perl_Warn_Off_(2 * warn_bit)] |= Perl_Warn_Bit_(2 * warn_bit);
9140+ }
9141+
9142+ /*
9143+ =for apidoc cop_disable_warning
9144+
9145+ Ensures that the set of warning bits contained by the COP does not include the
9146+ given warning, as specified by one of the C<WARN_...> constants from
9147+ F<warnings.h>.
9148+
9149+ If the COP does not include the warning, no modification is made. Otherwise,
9150+ the stored warning bitmask is cloned, and the given warning bit is disabled
9151+ within it.
9152+
9153+ =cut
9154+ */
9155+
9156+ void
9157+ Perl_cop_disable_warning(pTHX_ COP *cop, int warn_bit)
9158+ {
9159+ PERL_ARGS_ASSERT_COP_DISABLE_WARNING;
9160+
9161+ if(!cop_has_warning(cop, warn_bit))
9162+ return;
9163+
9164+ cop_inplace_expand_warning_bitmask(cop);
9165+
9166+ cop->cop_warnings[Perl_Warn_Off_(2 * warn_bit)] &= ~Perl_Warn_Bit_(2 * warn_bit);
9167+ }
9168+
90729169/*
90739170=for apidoc newLOGOP
90749171
0 commit comments