Does XPUSHs make a copy of my_sv, or it really pushes my_sv into stack?
It really pushes it onto the stack.
#define XPUSHs(s) STMT_START { EXTEND(sp,1); (*++sp = (s)); } STMT_END
Your code has a memory leak, though. The scalar won't get freed since you didn't mortalise it, meaning you didn't tell Perl the stack owns a reference to it.
SV* my_sv = newSViv(12345); XPUSHs(sv_2mortal(my_sv));
Same thing:
SV* my_sv = newSViv(12345); mXPUSHs(my_sv);
It seems if I want to use the poped SV permanently (after FREETMPS and LEAVE), I have to make a copy of return by newSVsv(),
I think you can simple increase its REFCNT. If you do this, it's your responsibility to decrement its REFCNT when you're done with it.
Do I need to free the return manually, or it has been done automatically by FREETMPS and LEAVE?
You just have to call FREETMPS.
In reply to Re: What does perl stack OPs really do?
by ikegami
in thread What does perl stack OPs really do?
by llancet
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |