in reply to When to (and not to) use sv_2mortal()
I gather you've already discovered that the Inline::C stack macros are, by themselves, usually incapable of dealing with callbacks.use warnings; use strict; use Inline C => Config => BUILD_NOISY => 1; use Inline C =><<'EOC'; void call_Adder(int a, int b) { dSP; int count; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; count = call_pv("Adder", G_SCALAR); SPAGAIN; if (count != 1) croak("Big trouble\n"); printf ("The sum of %d and %d is %d\n", a, b, POPi); PUTBACK; FREETMPS; LEAVE; } EOC call_Adder(17, 16); sub Adder { my($a, $b) = @_; $a + $b; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: When to (and not to) use sv_2mortal()
by davido (Cardinal) on Oct 29, 2011 at 00:18 UTC |