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