[perl #6828] Set $AUTOLOAD once more for XS autoloading
authorFather Chrysostomos <sprout@cpan.org>
Wed, 12 Oct 2011 04:35:00 +0000 (21:35 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Wed, 12 Oct 2011 04:35:00 +0000 (21:35 -0700)
commitbb619f370aef1336c90dc1522addf0eff4dfd6c6
treec68480b97982e511395ebfb60248a026727ad122
parent120b7a08b6eec7ddfe4a829dd2b2ec5ed8612ec1
[perl #6828] Set $AUTOLOAD once more for XS autoloading

In 5.6.0, XS autoloading worked.  $AUTOLOAD would be set, as with
a Perl sub.

Commit ed850460 (5.6.1) allowed ‘sub AUTOLOAD;’ to prevent autoload
inheritance.  But the code to check for that mistakenly equated an
XSUB with a forward declaration.  So XS autoloading simply did not
work any more.

Then someone found it didn’t work and introduced it as a ‘new’ feature
in 5.8.0, with commit adb5a9ae.  For efficiency’s sake, instead of
joining the package name and sub name together, only to have the XSUB
do the same, it set the CvSTASH and SvPVX fields of the SV.

SvPVX was already being used for the sub’s prototype, so 8fa6a409
(just recently) made the autoloaded sub name and the prototype play
along nicely together, with a few fix-up commits (05b525f43d5f9785
and 74ee33f2).

It was only after that that I find out that $AUTOLOAD used to be set
for XSUBs.  See the discussion at these two links

    http://www.nntp.perl.org/group/perl.perl5.porters/;msgid=4E9468E8.8050206@cpan.org
    https://rt.perl.org/rt3/Ticket/Display.html?id=72708

This commit restores the original behaviour of setting $AUTOLOAD for
XSUBs, while retaining the CvSTASH+SvPVX method as well, as it has
been documented for a while.

Steffen Müller’s AUTOLOAD tests that I committed recently (120b7a08)
needed to be adjusted a bit.  The test count was off, which was my
fault (I *thought* I had checked that.)  The test XSUB was using
get_sv("AUTOLOAD"), which ended up fetching the caller’s $AUTOLOAD.
It was also using SvPV_set on an undefined scalar, which does not turn
the SvPOK flag on.
ext/XS-APItest/APItest.xs
ext/XS-APItest/t/autoload.t
gv.c