Hi,
I had always assumed that if, in XS, we wanted to return items from the stack to perl, we had to do an XSRETURN(x) where x is the number of items we want to return.

Apparently that's not so. The below Inline::C script doesn't explicitly return anything, yet the 3 values that are pushed onto the stack are returned:
use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; void foo() { dXSARGS; sp = mark; XPUSHs(sv_2mortal(newSVuv(111))); XPUSHs(sv_2mortal(newSVuv(87))); XPUSHs(sv_2mortal(newSVuv(42))); PUTBACK; } EOC @bar = foo(); print "@bar\n"; # prints 111 87 42
There's also a demo in the Inline::C-Cookbook that returns values in the same way without an explicit XSRETURN(x).

If no explicit XSRETURN(x) is made, and the function is void, is it simply the case that everything that has been pushed onto the stack is returned ? Is this behaviour reliable ?

Cheers,
Rob

In reply to [XS] Correct way to return the stack by syphilis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.