@@ -9069,6 +9069,99 @@ 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+ char *warning_bits = cop->cop_warnings;
9088+ if(warning_bits == pWARN_ALL)
9089+ return true;
9090+ else if(warning_bits == pWARN_NONE)
9091+ return false;
9092+ else
9093+ return isWARN_on(cop->cop_warnings, warn_bit);
9094+ }
9095+
9096+ #define cop_inplace_expand_warning_bitmask(cop) S_cop_inplace_expand_warning_bitmask(aTHX_ cop)
9097+ STATIC void
9098+ S_cop_inplace_expand_warning_bitmask(pTHX_ COP *cop)
9099+ {
9100+ char *warning_bits = cop->cop_warnings;
9101+
9102+ if(warning_bits == pWARN_STD || warning_bits == pWARN_ALL)
9103+ warning_bits = WARN_ALLstring;
9104+ else if(warning_bits == pWARN_NONE)
9105+ warning_bits = WARN_NONEstring;
9106+
9107+ /* Must allocate the new one before we throw the old buffer away */
9108+ char *new_warnings = Perl_new_warnings_bitfield(aTHX_ NULL, warning_bits, WARNsize);
9109+ free_and_set_cop_warnings(cop, new_warnings);
9110+ }
9111+
9112+ /*
9113+ =for apidoc cop_enable_warning
9114+
9115+ Ensures that the set of warning bits contained by the COP includes the given
9116+ warning, as specified by one of the C<WARN_...> constants from F<warnings.h>.
9117+
9118+ If the COP already includes the warning, no modification is made. Otherwise,
9119+ the stored warning bitmask is cloned, and the given warning bit is enabled
9120+ within it.
9121+
9122+ =cut
9123+ */
9124+
9125+ void
9126+ Perl_cop_enable_warning(pTHX_ COP *cop, int warn_bit)
9127+ {
9128+ PERL_ARGS_ASSERT_COP_ENABLE_WARNING;
9129+
9130+ if(cop_has_warning(cop, warn_bit))
9131+ return;
9132+
9133+ cop_inplace_expand_warning_bitmask(cop);
9134+
9135+ cop->cop_warnings[Perl_Warn_Off_(2 * warn_bit)] |= Perl_Warn_Bit_(2 * warn_bit);
9136+ }
9137+
9138+ /*
9139+ =for apidoc cop_disable_warning
9140+
9141+ Ensures that the set of warning bits contained by the COP does not include the
9142+ given warning, as specified by one of the C<WARN_...> constants from
9143+ F<warnings.h>.
9144+
9145+ If the COP does not include the warning, no modification is made. Otherwise,
9146+ the stored warning bitmask is cloned, and the given warning bit is disabled
9147+ within it.
9148+
9149+ =cut
9150+ */
9151+
9152+ void
9153+ Perl_cop_disable_warning(pTHX_ COP *cop, int warn_bit)
9154+ {
9155+ PERL_ARGS_ASSERT_COP_DISABLE_WARNING;
9156+
9157+ if(!cop_has_warning(cop, warn_bit))
9158+ return;
9159+
9160+ cop_inplace_expand_warning_bitmask(cop);
9161+
9162+ cop->cop_warnings[Perl_Warn_Off_(2 * warn_bit)] &= ~Perl_Warn_Bit_(2 * warn_bit);
9163+ }
9164+
90729165/*
90739166=for apidoc newLOGOP
90749167
0 commit comments