develooper Front page | perl.perl5.porters | Postings from October 2005

[perl #36815] [PATCH] warnings.pl/pm: Croaker function: bug (perl v5.8, v5.9)

From:
Steve Peters via RT
Date:
October 29, 2005 21:48
Subject:
[perl #36815] [PATCH] warnings.pl/pm: Croaker function: bug (perl v5.8, v5.9)
Message ID:
rt-3.0.11-36815-123477.18.1619361337108@perl.org
> [animator - Thu Aug 04 14:54:39 2005]:
> 
> This is a bug report for perl from perl-rt@wizbit.be,
> generated with the help of perlbug 1.35 running under perl v5.8.5.
> 
> 
> -----------------------------------------------------------------
> [Please enter your report here]
> Hello,
> 
> Recently I submitted another bug report ( [perl #36781] ) about
> warnings.pm, which was related to the __chk function (which is used by
> warnings::enabled, warnings::warn, and warnings::warnif).
> [ I'm not quite sure wheter I should create a new ticket or add a
> reply
> to the other, but I finally decided to create a new one... ]
> 
> 
> After testing some more I discovered a bug, which applies to perl v5.8
> and to the latest development version available from CPAN: perl
> v5.9.2.
> 
> The problem is that the Croaker subroutine, which is used when there
> is
> an error in one of the functions and has to call Carp::Croak, removes
> 'warnings' from the internal list, which is used by Carp::Heavy.
> 
> This in itself is not a problem if the execution really ends, but this
> is not always the case. Especially not if it's called inside an
> eval-block.
> 
> Attached is an example script that shows the problem, a patch for it,
> and a test-script (which is similar to the example).
> 
> (Small note: the same happens when the warnings aren't fatal).
> 
> Example script:
> 
> #!perl -l
>  use warnings FATAL => qw/all/;;
> 
>  eval { warnings::warn("void", "..."); };
>  print "ERROR-1: ";
>  print $@;
>  print "END-ERROR-1.";
> 
>  eval { warnings::enabled(qw/e r r o r/); };
>  print "ERROR-2: ";
>  print $@;
>  print "END-ERROR-2.";
> 
>  eval { warnings::warn("void", "..."); };
>  print "ERROR-3: ";
>  print $@;
>  print "END-ERROR-3.";
> 
> Example output:
> 
>  ERROR-1:
>  ... at script.pl line 7
>          eval {...} called at script.pl line 7
> 
>  END-ERROR-1.
>  ERROR-2:
>  Usage: warnings::enabled([category]) at script.pl line 12
> 
>  END-ERROR-2.
>  ERROR-3:
>  ... at script.pl line 17
> 
>  END-ERROR-3.
> 
> The first error, and the third error should be the same (apart from
> the
> line numbers). And that's not the case...
> 
> Enabling the verbose flag of Carp makes it even more clear:
> 
> Output with verbose mode enabled:
> 
>  ERROR-1:
>  ... at script.pl line 7
>          eval {...} called at script.pl line 7
> 
>  END-ERROR-1.
>  ERROR-2:
>  Usage: warnings::enabled([category]) at
> /usr/local/lib/perl5/5.8.5/warnings.pm line 298
>          warnings::Croaker('Usage: warnings::enabled([category])')
> called at /usr/local/lib/perl5/5.8.5/warnings.pm line 449
>          warnings::enabled('e', 'r', 'r', 'o', 'r') called at
> script.pl
> line 12
>          eval {...} called at script.pl line 12
> 
>  END-ERROR-2.
>  ERROR-3:
>  ... at /usr/local/lib/perl5/5.8.5/warnings.pm line 467
>          warnings::warn('void') called at script.pl line 17
>          eval {...} called at script.pl line 17
> 
>  END-ERROR-3.
> 
> 
> Patch warnings.pl: (the same patch can be used to patch warnings.pm,
> by
> changing the filename in the patch-header)
> 
> I added two patches... the change in code is the same but the lines
> surrounding the change aren't. To prevent manual patching I thought it
> would be best to add two patches (I apologize if that is/was a bad
> idea).
> 
> warnings.pl distributed with v5.8.7 which generates warnings.pm 1.03:
> 
> --- old/warnings.pl     Thu Aug  4 21:24:15 2005
> +++ new/warnings.pl     Thu Aug  4 21:30:17 2005
> @@ -606,6 +606,7 @@
> 
>  sub Croaker
>  {
> +    local $Carp::CarpInternal{'warnings'};
>      delete $Carp::CarpInternal{'warnings'};
>      Carp::croak(@_);
>  }
> 
> 
> warnings.pl distributed with v5.9.2 which generates warnings.pm 1.04:
> 
> --- old/warnings.pl     2005-08-04 21:26:11.000000000 +0200
> +++ new/warnings.pl     2005-08-04 21:26:34.000000000 +0200
> @@ -609,6 +609,7 @@
>  sub Croaker
>  {
>      require Carp;
> +    local $Carp::CarpInternal{'warnings'};
>      delete $Carp::CarpInternal{'warnings'};
>      Carp::croak(@_);
>  }
> 
> 
> Test script:
> 
> Big note for perl v5.9.2: the _error_loc function (of warnings.pm) is
> broken in v5.9.2. A patch for that is available in my other bug report
> (
> [perl #36781] ). This patch needs to be applied before running this
> test-script on perl v5.9.2.
> (The reason is that the test-script makes the warnings FATAL, and uses
> eval to capture them. But this does not happen because of the broken
> _error_loc function.)
> 
> It works immediately on perl v5.8. (It does not quite work on v5.6.1
> since the version of Carp.pm/Heavy.pm doesn't has the %CarpInternal
> hash.)
> 
> #!perl -l
> 
>  use Test;
>  use warnings FATAL => qw/void/;
>  BEGIN { plan tests => 4 }
>  use Carp;
> 
>  ok (exists $Carp::CarpInternal{'warnings'});
> 
> 
>  eval { warnings::warn("void", "..."); };
>  my $line1 = 0;
>  if ($@) {
>    $line1 = scalar split /\n/, $@;
>  }
> 
>  ok (exists $Carp::CarpInternal{'warnings'});
> 
>  eval { warnings::enabled(qw/e r r o r/); };
>  ok (exists $Carp::CarpInternal{'warnings'});
> 
>  eval { warnings::warn("void", "..."); };
>  if ($@) {
>    ok ($line1 == split /\n/, $@);
>  }
> 
> 
> 

Thanks!  Your patch was applied as change #25888.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About