This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
add newer malloc.c from Ilya Zakharevich <ilya@math.ohio-state.edu>
[perl5.git] / XSUB.h
CommitLineData
4633a7c4 1#define ST(off) 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
13#define dXSARGS \
3c78fafa 14 dSP; dMARK; \
a0d0e21e
LW
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
0e4ced38
GS
22#define XSRETURN(off) \
23 STMT_START { \
24 stack_sp = stack_base + ax + ((off) - 1); \
25 return; \
26 } STMT_END
a0d0e21e 27
748a9306
LW
28/* Simple macros to put new mortal values onto the stack. */
29/* Typically used to return values from XS functions. */
4633a7c4
LW
30#define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )
31#define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )
32#define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))
33#define XST_mNO(i) (ST(i) = &sv_no )
34#define XST_mYES(i) (ST(i) = &sv_yes )
35#define XST_mUNDEF(i) (ST(i) = &sv_undef)
748a9306 36
80b92232
PP
37#define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END
38#define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END
39#define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END
40#define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END
41#define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END
42#define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
43#define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END
382b8d97 44
37120919 45#define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
720fb644
PP
46
47#ifdef XS_VERSION
48# define XS_VERSION_BOOTCHECK \
774d564b 49 STMT_START { \
ae66e5c8 50 char *vn = Nullch, *module = SvPV(ST(0),na); \
774d564b
PP
51 if (items >= 2) /* version supplied as bootstrap arg */ \
52 Sv = ST(1); \
53 else { \
46fc3d4c 54 /* XXX GV_ADDWARN */ \
392e9e90
CS
55 Sv = perl_get_sv(form("%s::%s", module, \
56 vn = "XS_VERSION"), FALSE); \
46fc3d4c 57 if (!Sv || !SvOK(Sv)) \
392e9e90
CS
58 Sv = perl_get_sv(form("%s::%s", module, \
59 vn = "VERSION"), FALSE); \
774d564b 60 } \
ae66e5c8
CS
61 if (Sv && (!SvOK(Sv) || strNE(XS_VERSION, SvPV(Sv, na)))) \
62 croak("%s object version %s does not match %s%s%s%s %_", \
63 module, XS_VERSION, \
64 vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
65 vn ? vn : "bootstrap parameter", Sv); \
80b92232 66 } STMT_END
720fb644
PP
67#else
68# define XS_VERSION_BOOTCHECK
69#endif
76e3520e
GS
70
71#ifdef PERL_OBJECT
72#include "ObjXSub.h"
565764a8
DL
73#ifndef NO_XSLOCKS
74#ifdef WIN32
75#include "XSLock.h"
76#endif /* WIN32 */
77#endif /* NO_XSLOCKS */
e3b8966e
GS
78#else
79#ifdef PERL_CAPI
80#include "PerlCAPI.h"
81#endif
565764a8 82#endif /* PERL_OBJECT */