Subject: | Bug in version 1.04 |
Date: | Mon, 2 Jan 2017 12:18:34 -0500 |
To: | bug-Aspect [...] rt.cpan.org |
From: | Ken Beal <ken [...] kenbeal.com> |
Hi,
I've found a bug. If I define (but do not declare) a sub, in other words,
define a non-existent sub, it gives a warning and then its behavior goes
undefined (one of three possibilities; see the end).
The warning: "Use of each() on hash after insertion without resetting hash
iterator results in undefined behavior, Perl interpreter: 0x809dc8 at
C:/Strawberry/perl/site/lib/Aspect/Pointcut.pm line 172."
By "undefined" I mean that on subsequent runs with no changes, it sometimes
gives the output I'm looking for; sometimes gives no output; and sometimes
doubles the output.
I'm developing extra logging so that it can report every time it enters a
sub, with the parameters that are coming in; and log every time it leaves a
sub, with the input parameters as well as the return value(s).
In the script that I was working on, I had defined a sub and then renamed
it without updating the definition, creating the above situation.
I'm not sure whether it would be a simple matter to fix, or if this is "a
difficult edge case" but since I ran into it as an edge case in the code
I'm working on, and it stumped me for a couple days, I wanted to report
what I had found.
Below is a simple sample script which demonstrates the issue. All you have
to do to stop the issue from happening is to comment out the second line,
"sub notdefined($$$);":
===
use Aspect;
sub notdefined($$$);
sub main();
my @stack;
push @stack, around { print "Entering\n"; $_->proceed; print "Leaving\n"; }
call qr/./;
exit main();
sub main() {
print "hi!\n";
}
===
When I repeatedly run the above, it gives one of three possible outputs.
Either the expected (plus a warning):
===
Use of each() on hash after insertion without resetting hash iterator
results in undefined behavior, Perl interpreter: 0x839dc8 at
C:/Strawberry/perl/site/lib/Aspect/Pointcut.pm line 172.
Entering
hi!
Leaving
===
Or doubled:
===
Use of each() on hash after insertion without resetting hash iterator
results in undefined behavior, Perl interpreter: 0x7b9dc8 at
C:/Strawberry/perl/site/lib/Aspect/Pointcut.pm line 172.
Entering
Entering
hi!
Leaving
Leaving
===
Or no "Entering"/"Leaving" lines (but it still calls the inner routine!):
===
Use of each() on hash after insertion without resetting hash iterator
results in undefined behavior, Perl interpreter: 0x4f9dc8 at
C:/Strawberry/perl/site/lib/Aspect/Pointcut.pm line 172.
hi!
===
The fixed version should remove the "Use of each()" warning, and always
output the expected (without the warning), e.g.:
===
Entering
hi!
Leaving
===
Sincerely,
Ken
--
"Look at what's happened to me;
I can't believe it myself!"