[win32] integrate mainline
[p5sagit/p5-mst-13.2.git] / XSUB.h
CommitLineData
4633a7c4 1#define ST(off) stack_base[ax + (off)]
a0d0e21e 2
3#ifdef CAN_PROTOTYPE
4#define XS(name) void name(CV* cv)
5#else
6#define XS(name) void name(cv) CV* cv;
7#endif
8
4a52a3da 9#if 0 /*defined(WIN32) && defined(__GNUC__)*/ /* this bug is gone in mingw32/gcc-2.8.0*/
c69f112c 10#define STRINGIFY_THINGY(x) #x
11#define FORCE_ARG_STRING(x) STRINGIFY_THINGY(x)
5b0d9cbe 12#else
13#define FORCE_ARG_STRING(x) x
14#endif
15
a0d0e21e 16#define dXSARGS \
4e35701f 17 dSP; dMARK; \
a0d0e21e 18 I32 ax = mark - stack_base + 1; \
19 I32 items = sp - mark
20
21#define XSANY CvXSUBANY(cv)
22
23#define dXSI32 I32 ix = XSANY.any_i32
24
0e4ced38 25#define XSRETURN(off) \
26 STMT_START { \
27 stack_sp = stack_base + ax + ((off) - 1); \
28 return; \
29 } STMT_END
a0d0e21e 30
748a9306 31/* Simple macros to put new mortal values onto the stack. */
32/* Typically used to return values from XS functions. */
4633a7c4 33#define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )
34#define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )
35#define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))
36#define XST_mNO(i) (ST(i) = &sv_no )
37#define XST_mYES(i) (ST(i) = &sv_yes )
38#define XST_mUNDEF(i) (ST(i) = &sv_undef)
748a9306 39
80b92232 40#define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END
41#define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END
42#define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END
43#define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END
44#define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END
45#define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
46#define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END
382b8d97 47
37120919 48#define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
720fb644 49
50#ifdef XS_VERSION
51# define XS_VERSION_BOOTCHECK \
774d564b 52 STMT_START { \
4a52a3da 53 char *xs_version = FORCE_ARG_STRING(XS_VERSION); \
46fc3d4c 54 char *vn = "", *module = SvPV(ST(0),na); \
774d564b 55 if (items >= 2) /* version supplied as bootstrap arg */ \
56 Sv = ST(1); \
57 else { \
46fc3d4c 58 /* XXX GV_ADDWARN */ \
392e9e90 59 Sv = perl_get_sv(form("%s::%s", module, \
60 vn = "XS_VERSION"), FALSE); \
46fc3d4c 61 if (!Sv || !SvOK(Sv)) \
392e9e90 62 Sv = perl_get_sv(form("%s::%s", module, \
63 vn = "VERSION"), FALSE); \
774d564b 64 } \
5b0d9cbe 65 if (Sv && (!SvOK(Sv) || strNE(xs_version, SvPV(Sv, na)))) \
392e9e90 66 croak("%s object version %s does not match $%s::%s %_", \
5b0d9cbe 67 module, xs_version, module, vn, Sv); \
80b92232 68 } STMT_END
720fb644 69#else
70# define XS_VERSION_BOOTCHECK
71#endif