From: Ilya Zakharevich Date: Wed, 8 Jan 1997 08:25:47 +0000 (-0500) Subject: Re: xsubpp and Tk ==> segfault X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7c5b83de28ae2ebfce6a3a7e907a300596342a30;p=p5sagit%2Fp5-mst-13.2.git Re: xsubpp and Tk ==> segfault 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> --- diff --git a/lib/ExtUtils/xsubpp b/lib/ExtUtils/xsubpp index d43eb1c..76e45d6 100755 --- a/lib/ExtUtils/xsubpp +++ b/lib/ExtUtils/xsubpp @@ -842,6 +842,7 @@ while (fetch_para()) { $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 @@ -1025,7 +1026,7 @@ EOF # croak(errbuf); EOF - if ($ret_type ne "void" or $CODE) { + if ($ret_type ne "void" or $EXPLICIT_RETURN) { print Q<