List Info

Thread: AutoLoader: goto considered harmful (especially with AutoLoaded XS)




AutoLoader: goto considered harmful (especially with AutoLoaded XS)
user name
2007-11-07 01:28:02
# New Ticket Created by  craig deforest 
# Please include the string:  [perl #47219]
# in the subject line of all future correspondence about
this issue. 
# <URL: h
ttp://rt.perl.org/rt3/Ticket/Display.html?id=47219 >


The AutoLoader documentation page recommends using
"goto &$AUTOLOAD"  
to enter the newly declared subroutine.  This munges the
stack if the  
declaration code includes loading XS modules.  In
particular, if the  
subroutine is defined via  "bootstrap newmodule"
(this most often  
happens with declarations that use Inline to autocompile a
new XS  
module), then a stray '1' is left on the Perl stack by the 

declaration step.  By using 'goto', the autoload subroutine
preserves  
the 1, which is then returned as an extra value(!) when the
newly  
declared subroutine returns.

In scalar context, the '1' is dropped on the floor; in list
context,  
it is interpolated into the returned list and appears as the
first  
value in that list.

In this case, the simplest workaround is to use "return
&$AUTOLOAD 
(_)" rather than "goto &$AUTOLOAD".
 That costs an extra stack  
frame, but is more bulletproof.

I have tested this bug in Perl 5.8.6 and 5.8.8 under MacOS X
and  
5.8.8 under Fedora Core 4.

The bug could be fixed by updating the AutoLoad man page to
use the  
safer construction, or by looking at the dynamic loader to
identify  
why it is leaving an extra 1 on the stack.  The former is
less likely  
to stir up trouble in other parts of Perl.



[1]

about | contact  Other archives ( Real Estate discussion Medical topics )