develooper Front page | perl.perl5.porters | Postings from January 2019

[perl #133800] Carp croak() fails on anon sub and package deletion

Thread Previous
From:
Chris Wagner
Date:
January 26, 2019 01:00
Subject:
[perl #133800] Carp croak() fails on anon sub and package deletion
Message ID:
rt-4.0.24-4214-1548464443-1577.133800-75-0@perl.org
# New Ticket Created by  Chris Wagner 
# Please include the string:  [perl #133800]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=133800 >


This perlbug is in support of RT#133776.

croak() fails with numerous unitialized warnings and incorrect error 
location when called from an anonymous sub in another package and if the 
package (stash) that the error is thrown from has been deleted.  The 
problem arises from short_error_loc() iterating through the call stack 
and leaving $called undefined.  The corresponding code in 
long_error_loc() seems to work.

I rewrote stash_deletion.t and added a new test for croak() to make it 
easier to track the errors.  Each test block is made to have unique 
values so that the origin of any message is identifiable.  I would like 
to submit this file as a permanent replacement for the existing test 
file.

The problem is not with the test construction because merely changing 
Carp::croak("Croak_Msg") to Carp::confess("Croak_Msg") lets the test 
pass.




Output:
$ t/stash_deletion_new.t 2>&1
1..18
Test file t/stash_deletion_new.t, Perl v5.22.4, Carp 1.50 
/usr/lib/perl5/site_perl/5.22/Carp.pm
ok 1
ok 2
ok 3
ok 4 - Confess_sub compile
ok 5 - Confess_sub execute
ok 6 - Confess_sub execute after package delete
ok 7 - Croak_sub compile
not ok 8 - Croak_sub execute
#   Failed test 'Croak_sub execute'
#   at t/stash_deletion_new.t line 69.
#                   'Croak_Msg at t/stash_deletion_new.t line 68.
# '
#     doesn't match '(?^:^Croak_Msg at Croak_File line 3)'
Use of uninitialized value $called in hash element at 
/usr/lib/perl5/site_perl/5.22/Carp.pm line 672.
Use of uninitialized value $pkg in hash element at 
/usr/lib/perl5/site_perl/5.22/Carp.pm line 499.
Use of uninitialized value $pkg in anonymous hash ({}) at 
/usr/lib/perl5/site_perl/5.22/Carp.pm line 499.
Use of uninitialized value $class in concatenation (.) or string at 
/usr/lib/perl5/site_perl/5.22/Carp.pm line 731.
Use of uninitialized value $pkg in hash element at 
/usr/lib/perl5/site_perl/5.22/Carp.pm line 500.
Use of uninitialized value $parent in exists at 
/usr/lib/perl5/site_perl/5.22/Carp.pm line 724.
not ok 9 - Croak_sub execute after package delete
#   Failed test 'Croak_sub execute after package delete'
#   at t/stash_deletion_new.t line 75.
#                   'Croak_Msg at t/stash_deletion_new.t line 74.
# '
#     doesn't match '(?^:^Croak_Msg at Croak_File line 3)'
ok 10
ok 11
ok 12
ok 13
ok 14
ok 15
ok 16
ok 17
ok 18
# Looks like you failed 2 tests of 18.



I also created an instrumented version of Carp.pm that illustrates how 
$called is left undefined.  The unanswered question is why the reported 
error location is wrong.  I attached the debug version and the output.  
short_error_loc() either goes 1 too far or caller_info() adds 1 extra.  
It should clearly report at 1 level down from what is currently 
returned.  Scroll down to just after the "ok 7" message, line 174, which 
is the start of the output for test 8.

This failure came to light in investigating warnings::enabled() calling 
short_error_loc() and throwing warnings.


Thanks.







Thread Previous


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