Skip Menu |

This queue is for tickets about the Log-Trace CPAN distribution.

Report information
The Basics
Id: 49409
Status: open
Priority: 0/
Queue: Log-Trace

People
Owner: Nobody in particular
Requestors: frequency [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.070
Fixed in: (no value)



Subject: [PATCH] Does not correctly handle constants
Hi there: I'm forwarding this bug on behalf of a Debian user. The original text (which follows), can be found at: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=539171 Look at this small program: ==== package MY; use constant C1 => 0; sub ok { } package main; sub ok { } use Log::Trace warn => { 'AllSubs' => 1, 'Everywhere' => 1, 'Deep' => 1, }; ok(); MY::ok(); ==== When running it, it fails: ==== vdanjean@eyak:/tmp$ perl ./test.pl Not a GLOB reference at /usr/share/perl5/Log/Trace.pm line 275. BEGIN failed--compilation aborted at ./test.pl line 10. vdanjean@eyak:/tmp$ ==== If I patch /usr/share/perl5/Log/Trace.pm (near line 275) # only wrap code references + next if (ref($symbols->{$typeglob}) eq 'SCALAR'); my $sub = *{$symbols->{$typeglob}}{CODE}; next unless (defined $sub and defined &$sub); then, it works: ==== vdanjean@eyak:/tmp$ perl ./test.pl main::ok( ) MY::ok( ) Config::DESTROY( Config, ... ) vdanjean@eyak:/tmp$ ==== Note that I'm not sure there are not others bugs. In particular, if I do not set 'Deep' => 1, the result should not change. However, in this case, the programm runs (with or without my patch) but other modules such as MY::ok are not traced anymore! ==== vdanjean@eyak:/tmp$ perl ./test.pl main::ok( ) vdanjean@eyak:/tmp$ ====
On Thu Sep 03 16:05:02 2009, FREQUENCY wrote: Show quoted text
> Hi there: > > I'm forwarding this bug on behalf of a Debian user. The original text > (which follows), can be found at: > http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=539171 > > Look at this small program: > ==== > package MY; > use constant C1 => 0; > sub ok { } > package main; > sub ok { } > use Log::Trace warn => { 'AllSubs' => 1, > 'Everywhere' => 1, > 'Deep' => 1, > }; > ok(); > MY::ok(); > ==== > > When running it, it fails: > ==== > vdanjean@eyak:/tmp$ perl ./test.pl > Not a GLOB reference at /usr/share/perl5/Log/Trace.pm line 275. > BEGIN failed--compilation aborted at ./test.pl line 10. > vdanjean@eyak:/tmp$ > ==== > If I patch /usr/share/perl5/Log/Trace.pm (near line 275) > # only wrap code references > + next if (ref($symbols->{$typeglob}) eq 'SCALAR'); > my $sub = *{$symbols->{$typeglob}}{CODE}; > next unless (defined $sub and defined &$sub); > then, it works: > ==== > vdanjean@eyak:/tmp$ perl ./test.pl > main::ok( ) > MY::ok( ) > Config::DESTROY( Config, ... ) > vdanjean@eyak:/tmp$ > ==== > > Note that I'm not sure there are not others bugs. > In particular, if I do not set 'Deep' => 1, the result should not change. > However, in this case, the programm runs (with or without my patch) but > other modules such as MY::ok are not traced anymore! > ==== > vdanjean@eyak:/tmp$ perl ./test.pl > main::ok( ) > vdanjean@eyak:/tmp$ > ====
Failure to handle constants also prevents Log::Trace from handling other types of stubs correctly. Currently if you have a subroutine stub declared with a $ prototype: sub foo ($); Log::Trace will look for the &$ subroutine in the main package, because it assumes that all stash entries are typeglobs. Perl has stored other stuff in stash elements for a *long* time now. The patch above does not solve that. The proper solution is to check for a typeglob and, if there is not one, then just access the typeglob normally, as in *{"$package:\:$globname"} and it will work. I came across this myself because Log::Trace naturally fails to handle the new CV-in-stash optimization to be included in perl 5.28, details of which can be found here: https://rt.perl.org/Ticket/Display.html?id=132252#txn-1500037 Attached is a patch to get it working.
Subject: open_ow3wfbre.txt
diff -rup Log-Trace-1.070-dCF6ee/lib/Log/Trace.pm Log-Trace-1.070-0/lib/Log/Trace.pm --- Log-Trace-1.070-dCF6ee/lib/Log/Trace.pm 2005-11-24 02:56:52.000000000 -0800 +++ Log-Trace-1.070-0/lib/Log/Trace.pm 2017-10-23 14:29:44.000000000 -0700 @@ -270,7 +270,10 @@ sub _wrap_functions { next if $typeglob =~ /^(?:TRACE(?:F|_HERE)?|DUMP|AUTOLOAD)$/; # only wrap code references - my $sub = *{$symbols->{$typeglob}}{CODE}; + my $sub = *{ ref \$symbols->{$typeglob} eq 'GLOB' + ? $symbols->{$typeglob} + : *{"$package:\:$typeglob"} + }{CODE}; next unless (defined $sub and defined &$sub); # skip if sub is already wrapped
On 2017-10-23 17:41:08, SPROUT wrote: Show quoted text
> On Thu Sep 03 16:05:02 2009, FREQUENCY wrote:
> > Hi there: > > > > I'm forwarding this bug on behalf of a Debian user. The original text > > (which follows), can be found at: > > http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=539171 > > > > Look at this small program: > > ==== > > package MY; > > use constant C1 => 0; > > sub ok { } > > package main; > > sub ok { } > > use Log::Trace warn => { 'AllSubs' => 1, > > 'Everywhere' => 1, > > 'Deep' => 1, > > }; > > ok(); > > MY::ok(); > > ==== > > > > When running it, it fails: > > ==== > > vdanjean@eyak:/tmp$ perl ./test.pl > > Not a GLOB reference at /usr/share/perl5/Log/Trace.pm line 275. > > BEGIN failed--compilation aborted at ./test.pl line 10. > > vdanjean@eyak:/tmp$ > > ==== > > If I patch /usr/share/perl5/Log/Trace.pm (near line 275) > > # only wrap code references > > + next if (ref($symbols->{$typeglob}) eq 'SCALAR'); > > my $sub = *{$symbols->{$typeglob}}{CODE}; > > next unless (defined $sub and defined &$sub); > > then, it works: > > ==== > > vdanjean@eyak:/tmp$ perl ./test.pl > > main::ok( ) > > MY::ok( ) > > Config::DESTROY( Config, ... ) > > vdanjean@eyak:/tmp$ > > ==== > > > > Note that I'm not sure there are not others bugs. > > In particular, if I do not set 'Deep' => 1, the result should not > > change. > > However, in this case, the programm runs (with or without my patch) > > but > > other modules such as MY::ok are not traced anymore! > > ==== > > vdanjean@eyak:/tmp$ perl ./test.pl > > main::ok( ) > > vdanjean@eyak:/tmp$ > > ====
> > Failure to handle constants also prevents Log::Trace from handling > other types of stubs correctly. Currently if you have a subroutine > stub declared with a $ prototype: > > sub foo ($); > > Log::Trace will look for the &$ subroutine in the main package, > because it assumes that all stash entries are typeglobs. Perl has > stored other stuff in stash elements for a *long* time now. > > The patch above does not solve that. The proper solution is to check > for a typeglob and, if there is not one, then just access the typeglob > normally, as in *{"$package:\:$globname"} and it will work. > > I came across this myself because Log::Trace naturally fails to handle > the new CV-in-stash optimization to be included in perl 5.28, details > of which can be found here: > https://rt.perl.org/Ticket/Display.html?id=132252#txn-1500037 > > Attached is a patch to get it working.
CPAN.pm may use the following distroprefs file for automatic patching: https://github.com/eserte/srezic-cpan-distroprefs/blob/master/Log-Trace.yml