-----BEGIN PGP SIGNED MESSAGE----- Moin,
On Sunday 15 August 2004 15:04, muppet wrote: > On Aug 15, 2004, at 1:08 AM, Tassilo von Parseval wrote: > > On Sat, Aug 14, 2004 at 05:50:20PM -0400 muppet wrote: > >> On Aug 14, 2004, at 3:28 AM, Tels wrote: > >>> FastCalc.c: In function `XS_Math__BigInt__FastCalc__is_ten': > >>> FastCalc.c:480: warning: unused variable `class' > >>> FastCalc.c:482: warning: unused variable `RETVAL' > >> > >> you've used CODE without setting RETVAL. if you're not going to use > >> RETVAL, don't use CODE. see below. > > > > I don't see why that should be so. The main difference between CODE > > and PPCODE is that the latter will adjust SP for you, whereas CODE > > leaves it untouched. Furthermore, PPCODE can't be used with an OUTPUT > > section. However, it's totally ok to have CODE without OUTPUT/RETVAL. > > that's true. i misspoke earlier, as void return without OUTPUT is > quite okay with CODE (remembered that within seconds of hitting send > ;-). but the idiom of XS is to use PPCODE when you're returning more > than one value. when people read your xsubs and see CODE they're going > to be surprised when they find multiple values returned. > > > Most of the time, my XSUBs follow this scheme: > > > > void > > function (arg1, arg2) > > type1 arg1; > > type2 arg2; > > CODE: > > { > > ... > > EXTEND(SP, 3); > > ST(0) = ... > > ST(1) = ... > > ST(2) = ... > > XSRETURN(3); > > } > > if you're going to write it that way, why use XS at all? just write > the perlapi C code directly. > > you could just as easily have written > > void function (type1 arg1, type2 arg2) > PPCODE: > ... > EXTEND (SP, 3); > PUSHs (...); > PUSHs (...); > PUSHs (...); > > >> you could much more easily use int for a bool than an SV. > > > > For returning one boolean value, I'd always use one of > > XSRETURN_(YES|NO): > > > > if (SvIV(temp) == 10) > > XSRETURN_YES; > > XSRETURN_NO; > > > > I find this more convenient than assigning to ST(0) plus doing an > > XSRETURN(1). > > forgive me, but i don't understand why that's preferable to > > int > .... > RETVAL = some boolean condition; > OUTPUT: > RETVAL I know this :) First, thank you all for your time and tricks and tipps. Not declaring class gets rid of the warning, very cool. Also, I got segfaults because I had return type SV* and RETVAL, but forgot the OUTPUT: statement. Ouch. Back to the difference between void and SV*: The last lines of my original routine, with a void return type: temp = *av_fetch(a, 0, 0); /* fetch first element */ ST(0) = boolSV((SvIV(temp) == 0)); #line 554 "FastCalc.c" } XSRETURN(1); } The same with RETVAL and OUTPUT: section: temp = *av_fetch(a, 0, 0); /* fetch first element */ RETVAL = boolSV((SvIV(temp) == 0)); #line 582 "FastCalc.c" ST(0) = RETVAL; sv_2mortal(ST(0)); } XSRETURN(1); } See the sv2mortal(ST(0)); there? :) I think it doesn't hurt, but it certainly is not neccessary, since everything works fine without it. Best wishes, Tels - -- Signed on Sun Aug 15 22:11:32 2004 with key 0x93B84C15. Visit my photo gallery at http://bloodgate.com/photos/ PGP key on http://bloodgate.com/tels.asc or per email. "Retsina?" - "Ja, Papa?" - "Warp 3." - "Is gut, Papa." -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl. iQEVAwUBQR/EJncLPEOTuEwVAQEjjwf8CCBlnzo8PjFSckeLmaNZs5uc0OoBZwNs cVkQTD25DEuPMAmtLqonsfFBdJCdvWripUsy2Ofb864EcdNeTKsRp8m408SXPi9/ cKI07iDFI0HuEsmbhgp5YORpBlXNZsjOOaZDWtyxbTHyoaUSmn43SBI20hQq9pDS 2a0uESsOHGFlediY8IzfhOUFmEkU624T4E2u+eLi2aJ1/voJwam93K1lGf224gxa U2o/57cO/p24l0AZerj/UCrGK3+gwp/DvDWwgNcymkoKr5dtWwwLNKQ8uuc6X9+L R1DsMvdFE3z3C0QqzGCq6NvgEcLkfq7YNdJHTx4pfRH+vCJI0AU30A== =jAGv -----END PGP SIGNATURE-----