Also, if I sv_2mortal(ST(0)); before returning ST(0) I get the "Attempt to free unreferenced scalar" warning again.

XSPP (I know your using something different), if you make a XS func with SV * as the return type, rather than void and PPCODE:, XSPP will throw in a sv_2mortal secretly on the "return" SV *. I always put " XSOPT => ' -nolinenumbers '," in my makefile.pl since the #line preprocessor that XSPP puts in drive my C debugger mad.

I'm not sure if the count check makes sense

Yes, it's something I've just copied verbatim from the perlcall examples, without any appreciation of it's siginificance. The error message is "Big trouble", which would be a very appropriate message if G_SCALAR is supposed to force the count as you say ;-)


I reread the perl source code, egh, the count check makes sense, see perl.c#l2736 in perl.git and pp_hot.c#l2776 in perl.git, sometimes perl fixes up the stack, often it doesn't, I guess from reading the code. If adder() is something you wrote and control, put the count check in a assert, the runtime overhead isn't worth it. PL_sv_count tip is great. I never knew that before. I also think (its been a while since the first and last time I did it), if you leave out the PUSHMARK, the callee will inherit your XSUB's stack/@_, sometimes its what you want. I generally keep the SAVE/FREETMPS out, I know the caller/entersub will clean up the mortals for me normally. By batching more mortals together for freeing, I will presume its faster than 2 separate SV freeing sessions because of CPU caching. Of course follow the event loop warning in perlcall. The ax fixup I can't comment on.

In reply to Re^3: [XS] Callbacks to perl by bulk88
in thread [XS] Callbacks to perl 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.