xiaoyafeng has asked for the wisdom of the Perl Monks concerning the following question:
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:
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.#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 am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What does XSUB do on TMPS Stack for us?
by dave_the_m (Monsignor) on Jul 23, 2019 at 06:48 UTC | |
by xiaoyafeng (Deacon) on Jul 24, 2019 at 01:11 UTC |