Commit | Line | Data |
4633a7c4 |
1 | #define ST(off) stack_base[ax + (off)] |
a0d0e21e |
2 | |
3 | #ifdef CAN_PROTOTYPE |
76e3520e |
4 | #ifdef PERL_OBJECT |
e3b8966e |
5 | #define XS(name) void name(CV* cv, CPerlObj* pPerl) |
76e3520e |
6 | #else |
a0d0e21e |
7 | #define XS(name) void name(CV* cv) |
76e3520e |
8 | #endif |
a0d0e21e |
9 | #else |
10 | #define XS(name) void name(cv) CV* cv; |
11 | #endif |
12 | |
13 | #define dXSARGS \ |
3c78fafa |
14 | dSP; dMARK; \ |
a0d0e21e |
15 | I32 ax = mark - stack_base + 1; \ |
16 | I32 items = sp - mark |
17 | |
18 | #define XSANY CvXSUBANY(cv) |
19 | |
20 | #define dXSI32 I32 ix = XSANY.any_i32 |
21 | |
cfc02341 |
22 | #ifdef __cplusplus |
23 | # define XSINTERFACE_CVT(ret,name) ret (*name)(...) |
24 | #else |
25 | # define XSINTERFACE_CVT(ret,name) ret (*name)() |
26 | #endif |
27 | #define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION) |
28 | #define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,))(f)) |
29 | #define XSINTERFACE_FUNC_SET(cv,f) \ |
30 | CvXSUBANY(cv).any_dptr = (void (*) _((void*)))(f) |
31 | |
0e4ced38 |
32 | #define XSRETURN(off) \ |
33 | STMT_START { \ |
34 | stack_sp = stack_base + ax + ((off) - 1); \ |
35 | return; \ |
36 | } STMT_END |
a0d0e21e |
37 | |
748a9306 |
38 | /* Simple macros to put new mortal values onto the stack. */ |
39 | /* Typically used to return values from XS functions. */ |
4633a7c4 |
40 | #define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) ) |
41 | #define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) ) |
42 | #define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0))) |
43 | #define XST_mNO(i) (ST(i) = &sv_no ) |
44 | #define XST_mYES(i) (ST(i) = &sv_yes ) |
45 | #define XST_mUNDEF(i) (ST(i) = &sv_undef) |
748a9306 |
46 | |
80b92232 |
47 | #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END |
48 | #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END |
49 | #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END |
50 | #define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END |
51 | #define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END |
52 | #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END |
53 | #define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END |
382b8d97 |
54 | |
37120919 |
55 | #define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d) |
720fb644 |
56 | |
57 | #ifdef XS_VERSION |
58 | # define XS_VERSION_BOOTCHECK \ |
774d564b |
59 | STMT_START { \ |
ae66e5c8 |
60 | char *vn = Nullch, *module = SvPV(ST(0),na); \ |
774d564b |
61 | if (items >= 2) /* version supplied as bootstrap arg */ \ |
62 | Sv = ST(1); \ |
63 | else { \ |
46fc3d4c |
64 | /* XXX GV_ADDWARN */ \ |
392e9e90 |
65 | Sv = perl_get_sv(form("%s::%s", module, \ |
66 | vn = "XS_VERSION"), FALSE); \ |
46fc3d4c |
67 | if (!Sv || !SvOK(Sv)) \ |
392e9e90 |
68 | Sv = perl_get_sv(form("%s::%s", module, \ |
69 | vn = "VERSION"), FALSE); \ |
774d564b |
70 | } \ |
ae66e5c8 |
71 | if (Sv && (!SvOK(Sv) || strNE(XS_VERSION, SvPV(Sv, na)))) \ |
72 | croak("%s object version %s does not match %s%s%s%s %_", \ |
73 | module, XS_VERSION, \ |
74 | vn ? "$" : "", vn ? module : "", vn ? "::" : "", \ |
75 | vn ? vn : "bootstrap parameter", Sv); \ |
80b92232 |
76 | } STMT_END |
720fb644 |
77 | #else |
78 | # define XS_VERSION_BOOTCHECK |
79 | #endif |
76e3520e |
80 | |
81 | #ifdef PERL_OBJECT |
82 | #include "ObjXSub.h" |
565764a8 |
83 | #ifndef NO_XSLOCKS |
84 | #ifdef WIN32 |
85 | #include "XSLock.h" |
86 | #endif /* WIN32 */ |
87 | #endif /* NO_XSLOCKS */ |
e3b8966e |
88 | #else |
89 | #ifdef PERL_CAPI |
90 | #include "PerlCAPI.h" |
91 | #endif |
565764a8 |
92 | #endif /* PERL_OBJECT */ |