From: Rafael Garcia-Suarez Date: Tue, 4 Mar 2003 22:23:41 +0000 (+0000) Subject: Patch by Salvador Fandiño to read the warning mask X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=75b6c4caab1abb3506eab9e8e512c69bbeb1c49f;hp=8fa7688f7865696bdfa78bc12d4ffb78bd1d6103;p=p5sagit%2Fp5-mst-13.2.git Patch by Salvador Fandiño to read the warning mask returned by caller() and ${^WARNING_BITS} from $warnings::Bits{all} and not from the hardcoded core constant. (This mask could have been extended by warnings::register.) Plus tests. p4raw-id: //depot/perl@18829 --- diff --git a/mg.c b/mg.c index 433cc23..3f462ee 100644 --- a/mg.c +++ b/mg.c @@ -676,7 +676,16 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg) sv_setpvn(sv, WARN_NONEstring, WARNsize) ; } else if (PL_compiling.cop_warnings == pWARN_ALL) { - sv_setpvn(sv, WARN_ALLstring, WARNsize) ; + /* Get the bit mask for $warnings::Bits{all}, because + * it could have been extended by warnings::register */ + SV **bits_all; + HV *bits=get_hv("warnings::Bits", FALSE); + if (bits && (bits_all=hv_fetch(bits, "all", 3, FALSE))) { + sv_setsv(sv, *bits_all); + } + else { + sv_setpvn(sv, WARN_ALLstring, WARNsize) ; + } } else { sv_setsv(sv, PL_compiling.cop_warnings); diff --git a/pp_ctl.c b/pp_ctl.c index 68204ce..5143391 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -1635,8 +1635,18 @@ PP(pp_caller) (old_warnings == pWARN_STD && (PL_dowarn & G_WARN_ON) == 0)) mask = newSVpvn(WARN_NONEstring, WARNsize) ; else if (old_warnings == pWARN_ALL || - (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) - mask = newSVpvn(WARN_ALLstring, WARNsize) ; + (old_warnings == pWARN_STD && PL_dowarn & G_WARN_ON)) { + /* Get the bit mask for $warnings::Bits{all}, because + * it could have been extended by warnings::register */ + SV **bits_all; + HV *bits = get_hv("warnings::Bits", FALSE); + if (bits && (bits_all=hv_fetch(bits, "all", 3, FALSE))) { + mask = newSVsv(*bits_all); + } + else { + mask = newSVpvn(WARN_ALLstring, WARNsize) ; + } + } else mask = newSVsv(old_warnings); PUSHs(sv_2mortal(mask)); diff --git a/t/op/caller.t b/t/op/caller.t index 751a161..c97191b 100644 --- a/t/op/caller.t +++ b/t/op/caller.t @@ -5,10 +5,9 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; require './test.pl'; + plan( tests => 27 ); } -plan( tests => 20 ); - my @c; print "# Tests with caller(0)\n"; @@ -63,3 +62,26 @@ my $fooref2 = delete $::{foo2}; $fooref2 -> (); is( $c[3], "(unknown)", "unknown subroutine name" ); ok( $c[4], "hasargs true with unknown sub" ); + +# See if caller() returns the correct warning mask + +sub testwarn { + my $w = shift; + is( (caller(0))[9], $w, "warnings"); +} + +# NB : extend the warning mask values below when new warnings are added +{ + no warnings; + BEGIN { is( ${^WARNING_BITS}, "\0" x 12, 'warning bits' ) } + testwarn("\0" x 12); + use warnings; + BEGIN { is( ${^WARNING_BITS}, "U" x 12, 'warning bits' ) } + BEGIN { testwarn("U" x 12); } + # run-time : + # the warning mask has been extended by warnings::register + testwarn("UUUUUUUUUUUU\001"); + use warnings::register; + BEGIN { is( ${^WARNING_BITS}, "UUUUUUUUUUUU\001", 'warning bits' ) } + testwarn("UUUUUUUUUUUU\001"); +}