develooper Front page | perl.perl5.porters | Postings from June 2008

Accessing caller's $^H in 5.8 and 5.10

Thread Next
Paul Fenwick
June 16, 2008 00:33
Accessing caller's $^H in 5.8 and 5.10
Message ID:
CC'ed to p5p.

The story so far: Our intrepid adventurer, PJF, has descended into the 
labyrinthine depths of user pragmata, seeking the legendary Amulet of 
Autodie.  Believing the code to almost be in his grasp, the wise wizard 
chocolateboy advises him of the potential for %^H to leak across file 
boundaries, sending a chill deep into the adventurer's heart.  We join them 
during their conversation about how this dread beast may be overcome...


G'day chocolateboy,

chocolateboy wrote:

> You Oz hackers never sleep, do you :-)

We do, just at odd hours.

>  > I also need to: Get a failing test case of %^H leaking across files 
> and causing havoc with autodie. Currently all my tests are passing with 
> 0x02000.
> Should be doable. See the penultimate and antepenultimate tests here: 

Great!  I now have a failing test.  It works when compiled with the latest 
bleedperl, which has the patch applied to it.  This is good.

However, I'm finding it tremendously difficult to implement a workaround. 
The reason is that autodie creates a bunch of subroutines at compile-time, 
but those subs don't get called until run-time.  To the best of my 
knowledge, the caller's $^H is completely inaccessible at run-time.  This 
means the potentially leaked subroutine has no way to determine if it 
actually *HAS* leaked.

In 5.10, we do have access to the caller's %^H, but since that contains the 
bug that we're trying to avoid, this doesn't help.

> There might be a way to work around the %^H scope bug by setting the 
> caller's file name in %^H. Then doing something like:
>     if ($^H{my_module_filename} eq (caller)[1]) { ... }

I was thinking about this as well, but it doesn't provide much relief for 
autodie.  The reason is that one can say 'use autodie' in a great many 
different files.  Where possible we install the *same* subroutine in lots of 
packages, otherwise we end up with a tremendous amount of (automatically 
generated) code duplication.

Even if we did go storing filenames in %^H, there's the potentially for a 
subroutine from one file using autodie leaking into another file using 
autodie (but not yet).  Plus it only helps in 5.10, where the caller's %^H 
is accessible at run-time.

The only good news is that in order to see this bug in autodie, one would 
need to:

	* use autodie at the top level (file) scope.

	* use another file.

	* use an autodying subroutine from the package in the original file.

For the "typical" example of each file contains its own package, and autodie 
is used to make autodying built-ins, this situation should be rare.  As 
such, I don't believe it's a complete show-stopper, but I still don't like 
that it *can* happen (even under 5.10.0).

Many thanks again for your help,


Paul Fenwick <> |
Director of Training                   | Ph:  +61 3 9354 6001
Perl Training Australia                | Fax: +61 3 9354 2681

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About