This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix two bugs when calling &xsub when @_ has holes
authorFather Chrysostomos <sprout@cpan.org>
Tue, 13 Feb 2018 21:36:22 +0000 (13:36 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 19 Feb 2018 00:25:42 +0000 (16:25 -0800)
commit7406cffe8ec122fcc2500115f8ed1742385893e1
tree85cd52b856bf70d6a188cf3d1c166c38f15b5138
parentc46431c409d5cdb3c1c17c039a19e0e03356c7a6
Fix two bugs when calling &xsub when @_ has holes

This fixes #132729 in the particular instance where an XSUB is
called via ampersand syntax when @_ has ‘holes’, or nonexistent ele-
ments, as in:

    @_ = ();
    $_[1] = 1;
    &xsub;

This means that if the XSUB or something it calls unshifts @_, the
first argument passed to the XSUB will now refer to $_[1], not $_[0];
i.e., as of this commit it is correctly shifted over.  Previously, a
‘defelem’ was used, which is a magical scalar that remembers its index
in the array, independent of whether the array was shifted.

In addition, the old code failed to mortalize the defelem, so this
commit fixes a memory leak with the new ‘non-elem’ mechanism (a spe-
cially-marked element stored in the array itself).
ext/XS-APItest/APItest.xs
pp_hot.c
t/op/sub.t
t/op/svleak.t