From your example it is not clear why are you using ST(2) in CODE section. In general, the declaration of function arguments tell xsubpp how to map perl variables into C variables. If you look at the generated by call "perl Makefile.PL" .c file, then you'll see how exactly the moving from perl variables to C variables shall happen.

You can affect this transition by providing initialization to your variables in the declaration. Then you don't need to provide CODE section. See for more details in perldoc perlxs.

One way to handle your situation could also be this. I don't know if this is what you want

foo * routine(a, b, c=NULL) SV * a SV * b SV * c INIT: ... if(!SvROK(c)) croak("Expected reference"); CODE: { SV * str = SvRV(c); }

Note. In your example you are using SvOK, I guess you want to use SvROK if you want to catch the reference.


In reply to Re: XS: How to enable passing ref or undef? by andal
in thread XS: How to enable passing ref or undef? by tlhackque

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.