PerlXS и @_
Oct. 29th, 2008 04:53 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Не случалось ли кому из xs вызывать обратно перловую функцию, желая прокинуть ей неизменнённый @_ ? А то в man perlcall в описании G_NOARGS сказано, что вроде как это можно, а на практике - вызываемая функция параметров не получает. ЧЯДНТ?
Фрагмент из man perlcall:
Фрагмент из man perlcall:
G_NOARGS
Whenever a Perl subroutine is called using one of the call_* functions, it is assumed by default that parameters are to be passed to the subroutine. If you are not passing any parameters to the Perl subroutine, you can save a bit of time by setting this flag. It has the effect of not creating the @_ array for the Perl subroutine.
Although the functionality provided by this flag may seem straightforward, it should be used only if there is a good reason to do so. The reason for being cautious is that even if you have specified the G_NOARGS flag, it is still possible for the Perl subroutine that has been called to think that you have passed it parameters.
In fact, what can happen is that the Perl subroutine you have called can access the @_ array from a previous Perl subroutine. This will occur when the code that is executing the call_* function has itself been called from another Perl subroutine. The code below illustrates this
sub fred
{ print "@_\n" }
sub joe
{ &fred }
&joe(1,2,3);
This will print
1 2 3
What has happened is that "fred" accesses the @_ array which belongs to "joe".