in reply to Re^3: XS: Passing an external library's function a Perl XS callback
in thread SOLVED: XS: Passing an external library's function a Perl XS callback
I greatly appreciate the feedback to try, AnonyMonk!
With the last code, static didn't work, so I removed that. I also initialized a and b. This very slightly modified declaration (yep, I corrected the def as well):
void callback(){ int a = 10; int b = 20; dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; call_pv("p_callback", G_DISCARD|G_NOARGS); SPAGAIN; printf("%d to the %dth power is %d.\n", a, b, POPi); PUTBACK; FREETMPS; LEAVE; }
...with the exact same otherwise all around, produces:
in init in perl callback Use of uninitialized value in subroutine entry at c_extern_call_perl.p +l line 11. 10 to the 20th power is -474476032. Segmentation fault
So, callback() is working perfectly on the direct call from the perl code, it still registers ok in the external function, but as soon as the callback is triggered from extern, it breaks, from my estimation, at or before the call to call_pv().
Update: I moved around some comments, and it segfaults on anything following the call to dSP().
Perhaps I'm XY Problem-ing this. Here's what I want...
Am I making sense here? Perhaps I'm thinking this totally wrong. I'm going to keep pounding on this because I know there's got to be a way :) I'm just not experienced enough in all of the cross-language comms, and using XS. I'm having fun though
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: XS: Passing an external library's function a Perl XS callback
by syphilis (Archbishop) on Aug 14, 2016 at 23:38 UTC | |
by stevieb (Canon) on Aug 15, 2016 at 13:27 UTC |