This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[win32] integrate mainline
[perl5.git] / XSUB.h
CommitLineData
4633a7c4 1#define ST(off) stack_base[ax + (off)]
a0d0e21e
LW
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
9#define dXSARGS \
4e35701f 10 dSP; dMARK; \
a0d0e21e
LW
11 I32 ax = mark - stack_base + 1; \
12 I32 items = sp - mark
13
14#define XSANY CvXSUBANY(cv)
15
16#define dXSI32 I32 ix = XSANY.any_i32
17
0e4ced38
GS
18#define XSRETURN(off) \
19 STMT_START { \
20 stack_sp = stack_base + ax + ((off) - 1); \
21 return; \
22 } STMT_END
a0d0e21e 23
748a9306
LW
24/* Simple macros to put new mortal values onto the stack. */
25/* Typically used to return values from XS functions. */
4633a7c4
LW
26#define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )
27#define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )
28#define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))
29#define XST_mNO(i) (ST(i) = &sv_no )
30#define XST_mYES(i) (ST(i) = &sv_yes )
31#define XST_mUNDEF(i) (ST(i) = &sv_undef)
748a9306 32
80b92232
PP
33#define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END
34#define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END
35#define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END
36#define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END
37#define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END
38#define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
39#define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END
382b8d97 40
37120919 41#define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
720fb644
PP
42
43#ifdef XS_VERSION
44# define XS_VERSION_BOOTCHECK \
774d564b 45 STMT_START { \
ae66e5c8 46 char *vn = Nullch, *module = SvPV(ST(0),na); \
774d564b
PP
47 if (items >= 2) /* version supplied as bootstrap arg */ \
48 Sv = ST(1); \
49 else { \
46fc3d4c 50 /* XXX GV_ADDWARN */ \
392e9e90
CS
51 Sv = perl_get_sv(form("%s::%s", module, \
52 vn = "XS_VERSION"), FALSE); \
46fc3d4c 53 if (!Sv || !SvOK(Sv)) \
392e9e90
CS
54 Sv = perl_get_sv(form("%s::%s", module, \
55 vn = "VERSION"), FALSE); \
774d564b 56 } \
ae66e5c8
CS
57 if (Sv && (!SvOK(Sv) || strNE(XS_VERSION, SvPV(Sv, na)))) \
58 croak("%s object version %s does not match %s%s%s%s %_", \
59 module, XS_VERSION, \
60 vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
61 vn ? vn : "bootstrap parameter", Sv); \
80b92232 62 } STMT_END
720fb644
PP
63#else
64# define XS_VERSION_BOOTCHECK
65#endif