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