Commit | Line | Data |
---|---|---|
eb1102fc NIS |
1 | /* XSUB.h |
2 | * | |
699a97de | 3 | * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
1129b882 | 4 | * 2003, 2004, 2005, 2006, 2007, 2008 by Larry Wall and others |
eb1102fc NIS |
5 | * |
6 | * You may distribute under the terms of either the GNU General Public | |
7 | * License or the Artistic License, as specified in the README file. | |
8 | * | |
9 | */ | |
10 | ||
6a5bc5ac KW |
11 | #ifndef PERL_XSUB_H_ |
12 | #define PERL_XSUB_H_ 1 | |
b4ba0ab9 | 13 | |
954c1994 GS |
14 | /* first, some documentation for xsubpp-generated items */ |
15 | ||
16 | /* | |
dcccc8ff | 17 | =head1 C<xsubpp> variables and internal functions |
ccfc67b7 | 18 | |
954c1994 GS |
19 | =for apidoc Amn|char*|CLASS |
20 | Variable which is setup by C<xsubpp> to indicate the | |
fbe13c60 KW |
21 | class name for a C++ XS constructor. This is always a C<char*>. See |
22 | C<L</THIS>>. | |
954c1994 GS |
23 | |
24 | =for apidoc Amn|(whatever)|RETVAL | |
25 | Variable which is setup by C<xsubpp> to hold the return value for an | |
72d33970 | 26 | XSUB. This is always the proper type for the XSUB. See |
954c1994 GS |
27 | L<perlxs/"The RETVAL Variable">. |
28 | ||
29 | =for apidoc Amn|(whatever)|THIS | |
30 | Variable which is setup by C<xsubpp> to designate the object in a C++ | |
fbe13c60 | 31 | XSUB. This is always the proper type for the C++ object. See C<L</CLASS>> and |
954c1994 GS |
32 | L<perlxs/"Using XS With C++">. |
33 | ||
9f2ea798 DM |
34 | =for apidoc Amn|I32|ax |
35 | Variable which is setup by C<xsubpp> to indicate the stack base offset, | |
36 | used by the C<ST>, C<XSprePUSH> and C<XSRETURN> macros. The C<dMARK> macro | |
37 | must be called prior to setup the C<MARK> variable. | |
38 | ||
954c1994 GS |
39 | =for apidoc Amn|I32|items |
40 | Variable which is setup by C<xsubpp> to indicate the number of | |
41 | items on the stack. See L<perlxs/"Variable-length Parameter Lists">. | |
42 | ||
43 | =for apidoc Amn|I32|ix | |
44 | Variable which is setup by C<xsubpp> to indicate which of an | |
45 | XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">. | |
46 | ||
47 | =for apidoc Am|SV*|ST|int ix | |
48 | Used to access elements on the XSUB's stack. | |
49 | ||
50 | =for apidoc AmU||XS | |
51 | Macro to declare an XSUB and its C parameter list. This is handled by | |
796b6530 | 52 | C<xsubpp>. It is the same as using the more explicit C<XS_EXTERNAL> macro. |
954c1994 | 53 | |
e64345f8 S |
54 | =for apidoc AmU||XS_INTERNAL |
55 | Macro to declare an XSUB and its C parameter list without exporting the symbols. | |
56 | This is handled by C<xsubpp> and generally preferable over exporting the XSUB | |
0cb93b3a | 57 | symbols unnecessarily. |
e64345f8 S |
58 | |
59 | =for apidoc AmU||XS_EXTERNAL | |
60 | Macro to declare an XSUB and its C parameter list explicitly exporting the symbols. | |
e64345f8 | 61 | |
9f2ea798 DM |
62 | =for apidoc Ams||dAX |
63 | Sets up the C<ax> variable. | |
64 | This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>. | |
65 | ||
557b887a SS |
66 | =for apidoc Ams||dAXMARK |
67 | Sets up the C<ax> variable and stack marker variable C<mark>. | |
68 | This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>. | |
69 | ||
9f2ea798 DM |
70 | =for apidoc Ams||dITEMS |
71 | Sets up the C<items> variable. | |
72 | This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>. | |
73 | ||
954c1994 | 74 | =for apidoc Ams||dXSARGS |
796b6530 | 75 | Sets up stack and mark pointers for an XSUB, calling C<dSP> and C<dMARK>. |
9f2ea798 DM |
76 | Sets up the C<ax> and C<items> variables by calling C<dAX> and C<dITEMS>. |
77 | This is usually handled automatically by C<xsubpp>. | |
954c1994 GS |
78 | |
79 | =for apidoc Ams||dXSI32 | |
80 | Sets up the C<ix> variable for an XSUB which has aliases. This is usually | |
81 | handled automatically by C<xsubpp>. | |
82 | ||
88037a85 | 83 | =for apidoc Ams||dUNDERBAR |
72d33970 FC |
84 | Sets up any variable needed by the C<UNDERBAR> macro. It used to define |
85 | C<padoff_du>, but it is currently a noop. However, it is strongly advised | |
483ce06a | 86 | to still use it for ensuring past and future compatibility. |
88037a85 RGS |
87 | |
88 | =for apidoc AmU||UNDERBAR | |
796b6530 KW |
89 | The SV* corresponding to the C<$_> variable. Works even if there |
90 | is a lexical C<$_> in scope. | |
88037a85 | 91 | |
954c1994 GS |
92 | =cut |
93 | */ | |
94 | ||
53c1dcc0 | 95 | #ifndef PERL_UNUSED_ARG |
c707756e | 96 | # define PERL_UNUSED_ARG(x) ((void)x) |
ad73156c | 97 | #endif |
53c1dcc0 AL |
98 | #ifndef PERL_UNUSED_VAR |
99 | # define PERL_UNUSED_VAR(x) ((void)x) | |
100 | #endif | |
ad73156c | 101 | |
3280af22 | 102 | #define ST(off) PL_stack_base[ax + (off)] |
a0d0e21e | 103 | |
081304ca AMS |
104 | /* XSPROTO() is also used by SWIG like this: |
105 | * | |
106 | * typedef XSPROTO(SwigPerlWrapper); | |
107 | * typedef SwigPerlWrapper *SwigPerlWrapperPtr; | |
108 | * | |
109 | * This code needs to be compilable under both C and C++. | |
110 | * | |
111 | * Don't forget to change the __attribute__unused__ version of XS() | |
112 | * below too if you change XSPROTO() here. | |
113 | */ | |
e64345f8 | 114 | |
ab1478f7 S |
115 | /* XS_INTERNAL is the explicit static-linkage variant of the default |
116 | * XS macro. | |
e64345f8 | 117 | * |
ab1478f7 S |
118 | * XS_EXTERNAL is the same as XS_INTERNAL except it does not include |
119 | * "STATIC", ie. it exports XSUB symbols. You probably don't want that. | |
e64345f8 S |
120 | */ |
121 | ||
53dfb2b7 | 122 | #define XSPROTO(name) void name(pTHX_ CV* cv __attribute__unused__) |
081304ca | 123 | |
27da23d5 | 124 | #undef XS |
e64345f8 S |
125 | #undef XS_EXTERNAL |
126 | #undef XS_INTERNAL | |
d308986b | 127 | #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING) |
ab1478f7 | 128 | # define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name) |
fe6ca737 | 129 | # define XS_INTERNAL(name) STATIC XSPROTO(name) |
f12ee906 | 130 | #elif defined(__SYMBIAN32__) |
ab1478f7 S |
131 | # define XS_EXTERNAL(name) EXPORT_C XSPROTO(name) |
132 | # define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name) | |
f12ee906 AC |
133 | #elif defined(__cplusplus) |
134 | # define XS_EXTERNAL(name) extern "C" XSPROTO(name) | |
135 | # define XS_INTERNAL(name) static XSPROTO(name) | |
136 | #elif defined(HASATTRIBUTE_UNUSED) | |
137 | # define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__) | |
138 | # define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__) | |
139 | #else | |
140 | # define XS_EXTERNAL(name) XSPROTO(name) | |
141 | # define XS_INTERNAL(name) STATIC XSPROTO(name) | |
a0d0e21e LW |
142 | #endif |
143 | ||
0cb93b3a S |
144 | /* We do export xsub symbols by default for the public XS macro. |
145 | * Try explicitly using XS_INTERNAL/XS_EXTERNAL instead, please. */ | |
146 | #define XS(name) XS_EXTERNAL(name) | |
e64345f8 | 147 | |
514696af | 148 | #define dAX const I32 ax = (I32)(MARK - PL_stack_base + 1) |
9f2ea798 | 149 | |
557b887a | 150 | #define dAXMARK \ |
a3b680e6 | 151 | I32 ax = POPMARK; \ |
eb578fdb | 152 | SV **mark = PL_stack_base + ax++ |
557b887a | 153 | |
514696af | 154 | #define dITEMS I32 items = (I32)(SP - MARK) |
9f2ea798 | 155 | |
c707756e | 156 | #define dXSARGS \ |
557b887a | 157 | dSP; dAXMARK; dITEMS |
9a189793 DD |
158 | /* These 3 macros are replacements for dXSARGS macro only in bootstrap. |
159 | They factor out common code in every BOOT XSUB. Computation of vars mark | |
160 | and items will optimize away in most BOOT functions. Var ax can never be | |
161 | optimized away since BOOT must return &PL_sv_yes by default from xsubpp. | |
162 | Note these macros are not drop in replacements for dXSARGS since they set | |
163 | PL_xsubfilename. */ | |
c707756e | 164 | #define dXSBOOTARGSXSAPIVERCHK \ |
9a189793 | 165 | I32 ax = XS_BOTHVERSION_SETXSUBFN_POPMARK_BOOTCHECK; \ |
db6e00bd | 166 | SV **mark = PL_stack_base + ax; dSP; dITEMS |
c707756e | 167 | #define dXSBOOTARGSAPIVERCHK \ |
9a189793 DD |
168 | I32 ax = XS_APIVERSION_SETXSUBFN_POPMARK_BOOTCHECK; \ |
169 | SV **mark = PL_stack_base + ax; dSP; dITEMS | |
170 | /* dXSBOOTARGSNOVERCHK has no API in xsubpp to choose it so do | |
171 | #undef dXSBOOTARGSXSAPIVERCHK | |
172 | #define dXSBOOTARGSXSAPIVERCHK dXSBOOTARGSNOVERCHK */ | |
c707756e | 173 | #define dXSBOOTARGSNOVERCHK \ |
9a189793 | 174 | I32 ax = XS_SETXSUBFN_POPMARK; \ |
db6e00bd | 175 | SV **mark = PL_stack_base + ax; dSP; dITEMS |
a0d0e21e | 176 | |
a3b680e6 | 177 | #define dXSTARG SV * const targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \ |
8a7fc0dc GS |
178 | ? PAD_SV(PL_op->op_targ) : sv_newmortal()) |
179 | ||
b26a54d0 GS |
180 | /* Should be used before final PUSHi etc. if not in PPCODE section. */ |
181 | #define XSprePUSH (sp = PL_stack_base + ax - 1) | |
182 | ||
a0d0e21e LW |
183 | #define XSANY CvXSUBANY(cv) |
184 | ||
185 | #define dXSI32 I32 ix = XSANY.any_i32 | |
186 | ||
cfc02341 IZ |
187 | #ifdef __cplusplus |
188 | # define XSINTERFACE_CVT(ret,name) ret (*name)(...) | |
4ef0c66e | 189 | # define XSINTERFACE_CVT_ANON(ret) ret (*)(...) |
cfc02341 IZ |
190 | #else |
191 | # define XSINTERFACE_CVT(ret,name) ret (*name)() | |
4ef0c66e | 192 | # define XSINTERFACE_CVT_ANON(ret) ret (*)() |
cfc02341 IZ |
193 | #endif |
194 | #define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION) | |
4ef0c66e | 195 | #define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT_ANON(ret))(f)) |
cfc02341 | 196 | #define XSINTERFACE_FUNC_SET(cv,f) \ |
a12c3db7 | 197 | CvXSUBANY(cv).any_dxptr = (void (*) (pTHX_ void*))(f) |
cfc02341 | 198 | |
483ce06a VP |
199 | #define dUNDERBAR dNOOP |
200 | #define UNDERBAR find_rundefsv() | |
88037a85 | 201 | |
748a9306 LW |
202 | /* Simple macros to put new mortal values onto the stack. */ |
203 | /* Typically used to return values from XS functions. */ | |
954c1994 GS |
204 | |
205 | /* | |
ccfc67b7 JH |
206 | =head1 Stack Manipulation Macros |
207 | ||
954c1994 GS |
208 | =for apidoc Am|void|XST_mIV|int pos|IV iv |
209 | Place an integer into the specified position C<pos> on the stack. The | |
210 | value is stored in a new mortal SV. | |
211 | ||
212 | =for apidoc Am|void|XST_mNV|int pos|NV nv | |
213 | Place a double into the specified position C<pos> on the stack. The value | |
214 | is stored in a new mortal SV. | |
215 | ||
216 | =for apidoc Am|void|XST_mPV|int pos|char* str | |
217 | Place a copy of a string into the specified position C<pos> on the stack. | |
218 | The value is stored in a new mortal SV. | |
219 | ||
220 | =for apidoc Am|void|XST_mNO|int pos | |
221 | Place C<&PL_sv_no> into the specified position C<pos> on the | |
222 | stack. | |
223 | ||
224 | =for apidoc Am|void|XST_mYES|int pos | |
225 | Place C<&PL_sv_yes> into the specified position C<pos> on the | |
226 | stack. | |
227 | ||
228 | =for apidoc Am|void|XST_mUNDEF|int pos | |
229 | Place C<&PL_sv_undef> into the specified position C<pos> on the | |
230 | stack. | |
231 | ||
232 | =for apidoc Am|void|XSRETURN|int nitems | |
233 | Return from XSUB, indicating number of items on the stack. This is usually | |
234 | handled by C<xsubpp>. | |
235 | ||
236 | =for apidoc Am|void|XSRETURN_IV|IV iv | |
237 | Return an integer from an XSUB immediately. Uses C<XST_mIV>. | |
238 | ||
108ccc45 JH |
239 | =for apidoc Am|void|XSRETURN_UV|IV uv |
240 | Return an integer from an XSUB immediately. Uses C<XST_mUV>. | |
241 | ||
954c1994 | 242 | =for apidoc Am|void|XSRETURN_NV|NV nv |
d1be9408 | 243 | Return a double from an XSUB immediately. Uses C<XST_mNV>. |
954c1994 GS |
244 | |
245 | =for apidoc Am|void|XSRETURN_PV|char* str | |
246 | Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>. | |
247 | ||
248 | =for apidoc Ams||XSRETURN_NO | |
249 | Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>. | |
250 | ||
251 | =for apidoc Ams||XSRETURN_YES | |
252 | Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>. | |
253 | ||
254 | =for apidoc Ams||XSRETURN_UNDEF | |
255 | Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>. | |
256 | ||
257 | =for apidoc Ams||XSRETURN_EMPTY | |
258 | Return an empty list from an XSUB immediately. | |
259 | ||
ccfc67b7 JH |
260 | =head1 Variables created by C<xsubpp> and C<xsubpp> internal functions |
261 | ||
c578083c | 262 | =for apidoc AmU||newXSproto|char* name|XSUBADDR_t f|char* filename|const char *proto |
954c1994 GS |
263 | Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to |
264 | the subs. | |
265 | ||
266 | =for apidoc AmU||XS_VERSION | |
267 | The version identifier for an XS module. This is usually | |
fbe13c60 KW |
268 | handled automatically by C<ExtUtils::MakeMaker>. See |
269 | C<L</XS_VERSION_BOOTCHECK>>. | |
954c1994 GS |
270 | |
271 | =for apidoc Ams||XS_VERSION_BOOTCHECK | |
796b6530 | 272 | Macro to verify that a PM module's C<$VERSION> variable matches the XS |
954c1994 GS |
273 | module's C<XS_VERSION> variable. This is usually handled automatically by |
274 | C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">. | |
275 | ||
1e8125c6 FR |
276 | =for apidoc Ams||XS_APIVERSION_BOOTCHECK |
277 | Macro to verify that the perl api version an XS module has been compiled against | |
278 | matches the api version of the perl interpreter it's being loaded into. | |
279 | ||
dcccc8ff | 280 | =head1 Exception Handling (simple) Macros |
0ca3a874 MHM |
281 | |
282 | =for apidoc Ams||dXCPT | |
2dfe1b17 | 283 | Set up necessary local variables for exception handling. |
0ca3a874 MHM |
284 | See L<perlguts/"Exception Handling">. |
285 | ||
286 | =for apidoc AmU||XCPT_TRY_START | |
287 | Starts a try block. See L<perlguts/"Exception Handling">. | |
288 | ||
289 | =for apidoc AmU||XCPT_TRY_END | |
290 | Ends a try block. See L<perlguts/"Exception Handling">. | |
291 | ||
292 | =for apidoc AmU||XCPT_CATCH | |
293 | Introduces a catch block. See L<perlguts/"Exception Handling">. | |
294 | ||
295 | =for apidoc Ams||XCPT_RETHROW | |
296 | Rethrows a previously caught exception. See L<perlguts/"Exception Handling">. | |
297 | ||
954c1994 GS |
298 | =cut |
299 | */ | |
300 | ||
4633a7c4 | 301 | #define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) ) |
108ccc45 | 302 | #define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) ) |
4633a7c4 LW |
303 | #define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) ) |
304 | #define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0))) | |
ad25789c | 305 | #define XST_mPVN(i,v,n) (ST(i) = newSVpvn_flags(v,n, SVs_TEMP)) |
3280af22 NIS |
306 | #define XST_mNO(i) (ST(i) = &PL_sv_no ) |
307 | #define XST_mYES(i) (ST(i) = &PL_sv_yes ) | |
308 | #define XST_mUNDEF(i) (ST(i) = &PL_sv_undef) | |
954c1994 GS |
309 | |
310 | #define XSRETURN(off) \ | |
311 | STMT_START { \ | |
61f9802b | 312 | const IV tmpXSoff = (off); \ |
9e77582c | 313 | assert(tmpXSoff >= 0);\ |
a02b2239 | 314 | PL_stack_sp = PL_stack_base + ax + (tmpXSoff - 1); \ |
954c1994 GS |
315 | return; \ |
316 | } STMT_END | |
317 | ||
80b92232 | 318 | #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END |
108ccc45 | 319 | #define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END |
80b92232 | 320 | #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END |
321 | #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END | |
954c1994 | 322 | #define XSRETURN_PVN(v,n) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END |
80b92232 | 323 | #define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END |
324 | #define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END | |
325 | #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END | |
326 | #define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END | |
382b8d97 | 327 | |
77004dee | 328 | #define newXSproto(a,b,c,d) newXS_flags(a,b,c,d,0) |
720fb644 | 329 | |
330 | #ifdef XS_VERSION | |
ddb5125f | 331 | # define XS_VERSION_BOOTCHECK \ |
9a189793 DD |
332 | Perl_xs_handshake(HS_KEY(FALSE, FALSE, "", XS_VERSION), HS_CXT, __FILE__, \ |
333 | items, ax, XS_VERSION) | |
720fb644 | 334 | #else |
c6af7a1a | 335 | # define XS_VERSION_BOOTCHECK |
720fb644 | 336 | #endif |
76e3520e | 337 | |
1e8125c6 | 338 | #define XS_APIVERSION_BOOTCHECK \ |
9a189793 DD |
339 | Perl_xs_handshake(HS_KEY(FALSE, FALSE, "v" PERL_API_VERSION_STRING, ""), \ |
340 | HS_CXT, __FILE__, items, ax, "v" PERL_API_VERSION_STRING) | |
db6e00bd DD |
341 | /* public API, this is a combination of XS_VERSION_BOOTCHECK and |
342 | XS_APIVERSION_BOOTCHECK in 1, and is backportable */ | |
343 | #ifdef XS_VERSION | |
344 | # define XS_BOTHVERSION_BOOTCHECK \ | |
9a189793 DD |
345 | Perl_xs_handshake(HS_KEY(FALSE, FALSE, "v" PERL_API_VERSION_STRING, XS_VERSION), \ |
346 | HS_CXT, __FILE__, items, ax, "v" PERL_API_VERSION_STRING, XS_VERSION) | |
db6e00bd DD |
347 | #else |
348 | /* should this be a #error? if you want both checked, you better supply XS_VERSION right? */ | |
349 | # define XS_BOTHVERSION_BOOTCHECK XS_APIVERSION_BOOTCHECK | |
350 | #endif | |
351 | ||
352 | /* private API */ | |
9a189793 DD |
353 | #define XS_APIVERSION_POPMARK_BOOTCHECK \ |
354 | Perl_xs_handshake(HS_KEY(FALSE, TRUE, "v" PERL_API_VERSION_STRING, ""), \ | |
355 | HS_CXT, __FILE__, "v" PERL_API_VERSION_STRING) | |
db6e00bd DD |
356 | #ifdef XS_VERSION |
357 | # define XS_BOTHVERSION_POPMARK_BOOTCHECK \ | |
9a189793 DD |
358 | Perl_xs_handshake(HS_KEY(FALSE, TRUE, "v" PERL_API_VERSION_STRING, XS_VERSION), \ |
359 | HS_CXT, __FILE__, "v" PERL_API_VERSION_STRING, XS_VERSION) | |
db6e00bd DD |
360 | #else |
361 | /* should this be a #error? if you want both checked, you better supply XS_VERSION right? */ | |
362 | # define XS_BOTHVERSION_POPMARK_BOOTCHECK XS_APIVERSION_POPMARK_BOOTCHECK | |
363 | #endif | |
1e8125c6 | 364 | |
9a189793 DD |
365 | #define XS_APIVERSION_SETXSUBFN_POPMARK_BOOTCHECK \ |
366 | Perl_xs_handshake(HS_KEY(TRUE, TRUE, "v" PERL_API_VERSION_STRING, ""), \ | |
367 | HS_CXT, __FILE__, "v" PERL_API_VERSION_STRING) | |
368 | #ifdef XS_VERSION | |
369 | # define XS_BOTHVERSION_SETXSUBFN_POPMARK_BOOTCHECK \ | |
370 | Perl_xs_handshake(HS_KEY(TRUE, TRUE, "v" PERL_API_VERSION_STRING, XS_VERSION),\ | |
371 | HS_CXT, __FILE__, "v" PERL_API_VERSION_STRING, XS_VERSION) | |
372 | #else | |
373 | /* should this be a #error? if you want both checked, you better supply XS_VERSION right? */ | |
374 | # define XS_BOTHVERSION_SETXSUBFN_POPMARK_BOOTCHECK XS_APIVERSION_SETXSUBFN_POPMARK_BOOTCHECK | |
375 | #endif | |
376 | ||
377 | /* For a normal bootstrap without API or XS version checking. | |
378 | Useful for static XS modules or debugging/testing scenarios. | |
379 | If this macro gets heavily used in the future, it should separated into | |
380 | a separate function independent of Perl_xs_handshake for efficiency */ | |
381 | #define XS_SETXSUBFN_POPMARK \ | |
382 | Perl_xs_handshake(HS_KEY(TRUE, TRUE, "", "") | HSf_NOCHK, HS_CXT, __FILE__) | |
383 | ||
9b5c3821 MHM |
384 | #ifdef NO_XSLOCKS |
385 | # define dXCPT dJMPENV; int rEtV = 0 | |
386 | # define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) | |
387 | # define XCPT_TRY_END JMPENV_POP; | |
388 | # define XCPT_CATCH if (rEtV != 0) | |
389 | # define XCPT_RETHROW JMPENV_JUMP(rEtV) | |
390 | #endif | |
0ca3a874 | 391 | |
1e8125c6 FR |
392 | /* |
393 | The DBM_setFilter & DBM_ckFilter macros are only used by | |
394 | the *DB*_File modules | |
6a31061a PM |
395 | */ |
396 | ||
397 | #define DBM_setFilter(db_type,code) \ | |
891c2e08 | 398 | STMT_START { \ |
6a31061a PM |
399 | if (db_type) \ |
400 | RETVAL = sv_mortalcopy(db_type) ; \ | |
401 | ST(0) = RETVAL ; \ | |
402 | if (db_type && (code == &PL_sv_undef)) { \ | |
1cbe4e6f | 403 | SvREFCNT_dec_NN(db_type) ; \ |
6a31061a PM |
404 | db_type = NULL ; \ |
405 | } \ | |
406 | else if (code) { \ | |
407 | if (db_type) \ | |
408 | sv_setsv(db_type, code) ; \ | |
409 | else \ | |
410 | db_type = newSVsv(code) ; \ | |
411 | } \ | |
891c2e08 | 412 | } STMT_END |
6a31061a PM |
413 | |
414 | #define DBM_ckFilter(arg,type,name) \ | |
891c2e08 | 415 | STMT_START { \ |
6a31061a PM |
416 | if (db->type) { \ |
417 | if (db->filtering) { \ | |
418 | croak("recursion detected in %s", name) ; \ | |
419 | } \ | |
420 | ENTER ; \ | |
421 | SAVETMPS ; \ | |
422 | SAVEINT(db->filtering) ; \ | |
423 | db->filtering = TRUE ; \ | |
414bf5ae | 424 | SAVE_DEFSV ; \ |
5bbd4290 PM |
425 | if (name[7] == 's') \ |
426 | arg = newSVsv(arg); \ | |
414bf5ae | 427 | DEFSV_set(arg) ; \ |
6a31061a PM |
428 | SvTEMP_off(arg) ; \ |
429 | PUSHMARK(SP) ; \ | |
430 | PUTBACK ; \ | |
431 | (void) perl_call_sv(db->type, G_DISCARD); \ | |
432 | SPAGAIN ; \ | |
433 | PUTBACK ; \ | |
434 | FREETMPS ; \ | |
435 | LEAVE ; \ | |
5bbd4290 PM |
436 | if (name[7] == 's'){ \ |
437 | arg = sv_2mortal(arg); \ | |
438 | } \ | |
891c2e08 | 439 | } } STMT_END |
6a31061a | 440 | |
51371543 | 441 | #if 1 /* for compatibility */ |
dc9e4912 GS |
442 | # define VTBL_sv &PL_vtbl_sv |
443 | # define VTBL_env &PL_vtbl_env | |
444 | # define VTBL_envelem &PL_vtbl_envelem | |
dc9e4912 GS |
445 | # define VTBL_sigelem &PL_vtbl_sigelem |
446 | # define VTBL_pack &PL_vtbl_pack | |
447 | # define VTBL_packelem &PL_vtbl_packelem | |
448 | # define VTBL_dbline &PL_vtbl_dbline | |
449 | # define VTBL_isa &PL_vtbl_isa | |
450 | # define VTBL_isaelem &PL_vtbl_isaelem | |
451 | # define VTBL_arylen &PL_vtbl_arylen | |
c696a6a4 | 452 | # define VTBL_glob &PL_vtbl_glob |
dc9e4912 GS |
453 | # define VTBL_mglob &PL_vtbl_mglob |
454 | # define VTBL_nkeys &PL_vtbl_nkeys | |
455 | # define VTBL_taint &PL_vtbl_taint | |
456 | # define VTBL_substr &PL_vtbl_substr | |
457 | # define VTBL_vec &PL_vtbl_vec | |
458 | # define VTBL_pos &PL_vtbl_pos | |
459 | # define VTBL_bm &PL_vtbl_bm | |
460 | # define VTBL_fm &PL_vtbl_fm | |
461 | # define VTBL_uvar &PL_vtbl_uvar | |
462 | # define VTBL_defelem &PL_vtbl_defelem | |
463 | # define VTBL_regexp &PL_vtbl_regexp | |
464 | # define VTBL_regdata &PL_vtbl_regdata | |
465 | # define VTBL_regdatum &PL_vtbl_regdatum | |
466 | # ifdef USE_LOCALE_COLLATE | |
467 | # define VTBL_collxfrm &PL_vtbl_collxfrm | |
468 | # endif | |
9e7bc3e8 JD |
469 | # define VTBL_amagic &PL_vtbl_amagic |
470 | # define VTBL_amagicelem &PL_vtbl_amagicelem | |
dc9e4912 GS |
471 | #endif |
472 | ||
6f4183fe | 473 | #include "perlapi.h" |
c6af7a1a | 474 | |
e8ee3774 | 475 | #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE) |
c5be433b GS |
476 | # undef aTHX |
477 | # undef aTHX_ | |
54aff467 GS |
478 | # define aTHX PERL_GET_THX |
479 | # define aTHX_ aTHX, | |
54aff467 GS |
480 | #endif |
481 | ||
acfe0abc | 482 | #if defined(PERL_IMPLICIT_SYS) && !defined(PERL_CORE) |
c6af7a1a | 483 | # ifndef NO_XSLOCKS |
2986a63f JH |
484 | # if defined (NETWARE) && defined (USE_STDIO) |
485 | # define times PerlProc_times | |
486 | # define setuid PerlProc_setuid | |
487 | # define setgid PerlProc_setgid | |
488 | # define getpid PerlProc_getpid | |
489 | # define pause PerlProc_pause | |
490 | # define exit PerlProc_exit | |
491 | # define _exit PerlProc__exit | |
492 | # else | |
c6af7a1a GS |
493 | # undef closedir |
494 | # undef opendir | |
495 | # undef stdin | |
496 | # undef stdout | |
497 | # undef stderr | |
498 | # undef feof | |
499 | # undef ferror | |
500 | # undef fgetpos | |
501 | # undef ioctl | |
502 | # undef getlogin | |
503 | # undef setjmp | |
504 | # undef getc | |
505 | # undef ungetc | |
506 | # undef fileno | |
507 | ||
cb69f87a | 508 | /* Following symbols were giving redefinition errors while building extensions - sgp 17th Oct 2000 */ |
2986a63f JH |
509 | #ifdef NETWARE |
510 | # undef readdir | |
511 | # undef fstat | |
512 | # undef stat | |
513 | # undef longjmp | |
514 | # undef endhostent | |
515 | # undef endnetent | |
516 | # undef endprotoent | |
517 | # undef endservent | |
518 | # undef gethostbyaddr | |
519 | # undef gethostbyname | |
520 | # undef gethostent | |
521 | # undef getnetbyaddr | |
522 | # undef getnetbyname | |
523 | # undef getnetent | |
524 | # undef getprotobyname | |
525 | # undef getprotobynumber | |
526 | # undef getprotoent | |
527 | # undef getservbyname | |
528 | # undef getservbyport | |
529 | # undef getservent | |
530 | # undef inet_ntoa | |
531 | # undef sethostent | |
532 | # undef setnetent | |
533 | # undef setprotoent | |
534 | # undef setservent | |
535 | #endif /* NETWARE */ | |
536 | ||
fa58a56f S |
537 | /* to avoid warnings: "xyz" redefined */ |
538 | #ifdef WIN32 | |
539 | # undef popen | |
540 | # undef pclose | |
541 | #endif /* WIN32 */ | |
542 | ||
1018e26f NIS |
543 | # undef socketpair |
544 | ||
c6af7a1a GS |
545 | # define mkdir PerlDir_mkdir |
546 | # define chdir PerlDir_chdir | |
547 | # define rmdir PerlDir_rmdir | |
548 | # define closedir PerlDir_close | |
549 | # define opendir PerlDir_open | |
550 | # define readdir PerlDir_read | |
551 | # define rewinddir PerlDir_rewind | |
552 | # define seekdir PerlDir_seek | |
553 | # define telldir PerlDir_tell | |
554 | # define putenv PerlEnv_putenv | |
555 | # define getenv PerlEnv_getenv | |
b2af26b1 | 556 | # define uname PerlEnv_uname |
197357d0 GS |
557 | # define stdin PerlSIO_stdin |
558 | # define stdout PerlSIO_stdout | |
559 | # define stderr PerlSIO_stderr | |
f9415d23 NIS |
560 | # define fopen PerlSIO_fopen |
561 | # define fclose PerlSIO_fclose | |
562 | # define feof PerlSIO_feof | |
563 | # define ferror PerlSIO_ferror | |
b6d726d6 | 564 | # define clearerr PerlSIO_clearerr |
f9415d23 | 565 | # define getc PerlSIO_getc |
20c8f8f9 | 566 | # define fgets PerlSIO_fgets |
f9415d23 NIS |
567 | # define fputc PerlSIO_fputc |
568 | # define fputs PerlSIO_fputs | |
569 | # define fflush PerlSIO_fflush | |
570 | # define ungetc PerlSIO_ungetc | |
571 | # define fileno PerlSIO_fileno | |
572 | # define fdopen PerlSIO_fdopen | |
573 | # define freopen PerlSIO_freopen | |
574 | # define fread PerlSIO_fread | |
575 | # define fwrite PerlSIO_fwrite | |
22a46b6e NIS |
576 | # define setbuf PerlSIO_setbuf |
577 | # define setvbuf PerlSIO_setvbuf | |
578 | # define setlinebuf PerlSIO_setlinebuf | |
1f59ddd9 GS |
579 | # define stdoutf PerlSIO_stdoutf |
580 | # define vfprintf PerlSIO_vprintf | |
f9415d23 NIS |
581 | # define ftell PerlSIO_ftell |
582 | # define fseek PerlSIO_fseek | |
583 | # define fgetpos PerlSIO_fgetpos | |
584 | # define fsetpos PerlSIO_fsetpos | |
585 | # define frewind PerlSIO_rewind | |
586 | # define tmpfile PerlSIO_tmpfile | |
c6af7a1a GS |
587 | # define access PerlLIO_access |
588 | # define chmod PerlLIO_chmod | |
589 | # define chsize PerlLIO_chsize | |
590 | # define close PerlLIO_close | |
591 | # define dup PerlLIO_dup | |
592 | # define dup2 PerlLIO_dup2 | |
593 | # define flock PerlLIO_flock | |
594 | # define fstat PerlLIO_fstat | |
595 | # define ioctl PerlLIO_ioctl | |
596 | # define isatty PerlLIO_isatty | |
6b980173 | 597 | # define link PerlLIO_link |
c6af7a1a GS |
598 | # define lseek PerlLIO_lseek |
599 | # define lstat PerlLIO_lstat | |
600 | # define mktemp PerlLIO_mktemp | |
601 | # define open PerlLIO_open | |
602 | # define read PerlLIO_read | |
603 | # define rename PerlLIO_rename | |
604 | # define setmode PerlLIO_setmode | |
4f49e16e | 605 | # define stat(buf,sb) PerlLIO_stat(buf,sb) |
c6af7a1a GS |
606 | # define tmpnam PerlLIO_tmpnam |
607 | # define umask PerlLIO_umask | |
608 | # define unlink PerlLIO_unlink | |
609 | # define utime PerlLIO_utime | |
610 | # define write PerlLIO_write | |
611 | # define malloc PerlMem_malloc | |
5ace197f | 612 | # define calloc PerlMem_calloc |
c6af7a1a GS |
613 | # define realloc PerlMem_realloc |
614 | # define free PerlMem_free | |
615 | # define abort PerlProc_abort | |
616 | # define exit PerlProc_exit | |
617 | # define _exit PerlProc__exit | |
618 | # define execl PerlProc_execl | |
619 | # define execv PerlProc_execv | |
620 | # define execvp PerlProc_execvp | |
621 | # define getuid PerlProc_getuid | |
622 | # define geteuid PerlProc_geteuid | |
623 | # define getgid PerlProc_getgid | |
624 | # define getegid PerlProc_getegid | |
625 | # define getlogin PerlProc_getlogin | |
626 | # define kill PerlProc_kill | |
627 | # define killpg PerlProc_killpg | |
628 | # define pause PerlProc_pause | |
629 | # define popen PerlProc_popen | |
630 | # define pclose PerlProc_pclose | |
631 | # define pipe PerlProc_pipe | |
632 | # define setuid PerlProc_setuid | |
633 | # define setgid PerlProc_setgid | |
634 | # define sleep PerlProc_sleep | |
635 | # define times PerlProc_times | |
636 | # define wait PerlProc_wait | |
637 | # define setjmp PerlProc_setjmp | |
638 | # define longjmp PerlProc_longjmp | |
639 | # define signal PerlProc_signal | |
7766f137 | 640 | # define getpid PerlProc_getpid |
57ab3dfe | 641 | # define gettimeofday PerlProc_gettimeofday |
c6af7a1a GS |
642 | # define htonl PerlSock_htonl |
643 | # define htons PerlSock_htons | |
644 | # define ntohl PerlSock_ntohl | |
645 | # define ntohs PerlSock_ntohs | |
646 | # define accept PerlSock_accept | |
647 | # define bind PerlSock_bind | |
648 | # define connect PerlSock_connect | |
649 | # define endhostent PerlSock_endhostent | |
650 | # define endnetent PerlSock_endnetent | |
651 | # define endprotoent PerlSock_endprotoent | |
652 | # define endservent PerlSock_endservent | |
653 | # define gethostbyaddr PerlSock_gethostbyaddr | |
654 | # define gethostbyname PerlSock_gethostbyname | |
655 | # define gethostent PerlSock_gethostent | |
656 | # define gethostname PerlSock_gethostname | |
657 | # define getnetbyaddr PerlSock_getnetbyaddr | |
658 | # define getnetbyname PerlSock_getnetbyname | |
659 | # define getnetent PerlSock_getnetent | |
660 | # define getpeername PerlSock_getpeername | |
661 | # define getprotobyname PerlSock_getprotobyname | |
662 | # define getprotobynumber PerlSock_getprotobynumber | |
663 | # define getprotoent PerlSock_getprotoent | |
664 | # define getservbyname PerlSock_getservbyname | |
665 | # define getservbyport PerlSock_getservbyport | |
666 | # define getservent PerlSock_getservent | |
667 | # define getsockname PerlSock_getsockname | |
668 | # define getsockopt PerlSock_getsockopt | |
669 | # define inet_addr PerlSock_inet_addr | |
670 | # define inet_ntoa PerlSock_inet_ntoa | |
671 | # define listen PerlSock_listen | |
672 | # define recv PerlSock_recv | |
673 | # define recvfrom PerlSock_recvfrom | |
674 | # define select PerlSock_select | |
675 | # define send PerlSock_send | |
676 | # define sendto PerlSock_sendto | |
677 | # define sethostent PerlSock_sethostent | |
678 | # define setnetent PerlSock_setnetent | |
679 | # define setprotoent PerlSock_setprotoent | |
680 | # define setservent PerlSock_setservent | |
681 | # define setsockopt PerlSock_setsockopt | |
682 | # define shutdown PerlSock_shutdown | |
683 | # define socket PerlSock_socket | |
684 | # define socketpair PerlSock_socketpair | |
2986a63f | 685 | # endif /* NETWARE && USE_STDIO */ |
21c5e947 | 686 | |
72e6b643 SH |
687 | # undef fd_set |
688 | # undef FD_SET | |
689 | # undef FD_CLR | |
690 | # undef FD_ISSET | |
691 | # undef FD_ZERO | |
692 | # define fd_set Perl_fd_set | |
693 | # define FD_SET(n,p) PERL_FD_SET(n,p) | |
694 | # define FD_CLR(n,p) PERL_FD_CLR(n,p) | |
695 | # define FD_ISSET(n,p) PERL_FD_ISSET(n,p) | |
696 | # define FD_ZERO(p) PERL_FD_ZERO(p) | |
21c5e947 | 697 | |
c6af7a1a | 698 | # endif /* NO_XSLOCKS */ |
acfe0abc | 699 | #endif /* PERL_IMPLICIT_SYS && !PERL_CORE */ |
b4ba0ab9 | 700 | |
6a5bc5ac | 701 | #endif /* PERL_XSUB_H_ */ /* include guard */ |
ad73156c AL |
702 | |
703 | /* | |
14d04a33 | 704 | * ex: set ts=8 sts=4 sw=4 et: |
ad73156c | 705 | */ |