Hi monks

I found that perlcall and perlxs treat mortal variable are different. When you calls perl subroutine from C, you have to save and free them manually, but in XS code, you don't have to do that. like:

#in perlcall, you have to use ENTER,SAVETMPS, FREETMPS, LEAVE to free +mortal variables dSP; ENTER; SAVETMPS; PUSHMARK(SP); EXTEND(SP, 2); PUSHs(sv_2mortal(newSVpv(a, 0))); PUSHs(sv_2mortal(newSViv(b))); PUTBACK; call_pv("LeftString", G_DISCARD); FREETMPS; LEAVE; #in XS, you don't have to do that: void rpcb_gettime(host) char *host PREINIT: time_t timep; bool_t status; PPCODE: status = rpcb_gettime( host, &timep ); EXTEND(SP, 2); PUSHs(sv_2mortal(newSViv(status))); PUSHs(sv_2mortal(newSViv(timep)));
I've searched C file generated by XS, there are still no any code to free mortal variables. So When these mortal variable are freed? Please enlightened me. TIA.




I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction


In reply to What does XSUB do on TMPS Stack for us? by xiaoyafeng

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.