Use defelems for (goto) &xsub calls
authorFather Chrysostomos <sprout@cpan.org>
Fri, 6 Sep 2013 07:17:05 +0000 (00:17 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Fri, 6 Sep 2013 13:18:08 +0000 (06:18 -0700)
commitdd2a7f9048da2c440a4dfed5122c0bfd98f079d3
treec901bb9cb11796df795d97b5cf5c1914a2781aec
parent956f23f034b0a3aa7c521134b47f388252b9f843
Use defelems for (goto) &xsub calls

Before ce0d59f:

$ perl -e '++$#_; &utf8::encode'
Modification of a read-only value attempted at -e line 1.

As of ce0d59f:

$ ./perl -Ilib -e '++$#_; &utf8::encode'
Assertion failed: (sv), function Perl_sv_utf8_encode, file sv.c, line 3581.
Abort trap: 6

Calling sub { utf8::encode($_[0]) } should be more or less equivalent
to calling utf8::encode, but it is not in this case:

$ ./perl -Ilib -we '++$#_; &{sub { utf8::encode($_[0]) }}'
Use of uninitialized value in subroutine entry at -e line 1.

In the first two examples above, an implementation detail is leaking
through.  What you are seeing is not the array element, but a place-
holder that indicates an element that has not been assigned to yet.

We should use defelem magic so that what the XSUB assigns to will cre-
ate an array element (as happens with utf8::encode($_[0])).

All of the above applies to goto &xsub as well.
pp_ctl.c
pp_hot.c
t/op/goto.t
t/op/sub.t