| 1 |
#include "EXTERN.h" |
| 2 |
#include "perl.h" |
| 3 |
#include "XSUB.h" |
| 4 |
#include "ppport.h" |
| 5 |
#include "ffi_platypus.h" |
| 6 |
#include "ffi_platypus_guts.h" |
| 7 |
|
| 8 |
SV* |
| 9 |
ffi_pl_custom_perl(SV *subref, SV *in_arg, int i) |
| 10 |
{ |
| 11 |
if(subref == NULL) |
| 12 |
{ |
| 13 |
return newSVsv(in_arg); |
| 14 |
} |
| 15 |
else |
| 16 |
{ |
| 17 |
dSP; |
| 18 |
|
| 19 |
int count; |
| 20 |
SV *out_arg; |
| 21 |
|
| 22 |
ENTER; |
| 23 |
SAVETMPS; |
| 24 |
PUSHMARK(SP); |
| 25 |
XPUSHs(in_arg); |
| 26 |
XPUSHs(sv_2mortal(newSViv(i))); |
| 27 |
PUTBACK; |
| 28 |
|
| 29 |
count = call_sv(subref, G_ARRAY); |
| 30 |
|
| 31 |
SPAGAIN; |
| 32 |
|
| 33 |
if(count >= 1) |
| 34 |
out_arg = SvREFCNT_inc(POPs); |
| 35 |
else |
| 36 |
out_arg = NULL; |
| 37 |
|
| 38 |
PUTBACK; |
| 39 |
FREETMPS; |
| 40 |
LEAVE; |
| 41 |
|
| 42 |
return out_arg; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void |
| 47 |
ffi_pl_custom_perl_cb(SV *subref, SV *in_arg, int i) |
| 48 |
{ |
| 49 |
dSP; |
| 50 |
ENTER; |
| 51 |
SAVETMPS; |
| 52 |
PUSHMARK(SP); |
| 53 |
XPUSHs(in_arg); |
| 54 |
XPUSHs(sv_2mortal(newSViv(i))); |
| 55 |
PUTBACK; |
| 56 |
call_sv(subref, G_VOID|G_DISCARD); |
| 57 |
FREETMPS; |
| 58 |
LEAVE; |
| 59 |
} |