Ilya Zakharevich writes:
>
> I recall that the reason why void code may be marked as XSRETURN(1) is
> that XS TUTORIAL recommended to mark XSUB as void if you manually put
It is not perlxstut, it is perlxs.
> in stack manipulation! I do not know why this horrible practice is
> blessed, but we need a workaround which would allow this mess, and
> would not make an XSUB
[Add: ] ... segfault if some Perl code was called in between.
As I found out, the only difference between an XSUB with a CODE:
section which is declared `void' and one which is declared "SV *" is
that the first one does not contain a line:
SV * RETVAL;
Is there any trouble if such a line is present?
If nobody will strongly object to it, I will remove an advice to
mark a CODE:-XSUBs as `void' from the POD(s).
I can also add a warning to xsubpp if a `void' XSUB sets ST(*). What
about it? (Warning will be issued only once per .xs .)
> Solution: Make the check for CODE section stricter: check for actuall
> occurence of "ST(" (with embedded spaces) before making the decision
> to XSRETURN(1).
The following patch is checked with Perl 3_17 and Tk (it checks for ST
at the LHS as an assignment):
Enjoy,
p5p-msgid: <
199701080825.DAA15813@monk.mps.ohio-state.edu>
$PPCODE = grep(/^\s*PPCODE\s*:/, @line);
$CODE = grep(/^\s*CODE\s*:/, @line);
+ $EXPLICIT_RETURN = $CODE && ("@line" =~ /\bST\s*\([^;]*=/ );
$ALIAS = grep(/^\s*ALIAS\s*:/, @line);
# print function header
# croak(errbuf);
EOF
- if ($ret_type ne "void" or $CODE) {
+ if ($ret_type ne "void" or $EXPLICIT_RETURN) {
print Q<<EOF unless $PPCODE;
# XSRETURN(1);
EOF