Commit | Line | Data |
b4ba0ab9 |
1 | #ifndef _INC_PERL_XSUB_H |
2 | #define _INC_PERL_XSUB_H 1 |
3 | |
3280af22 |
4 | #define ST(off) PL_stack_base[ax + (off)] |
a0d0e21e |
5 | |
873b149f |
6 | #if defined(CYGWIN) && defined(USE_DYNAMIC_LOADING) |
0cb96387 |
7 | # define XS(name) __declspec(dllexport) void name(pTHXo_ CV* cv) |
cea2e8a9 |
8 | #else |
0cb96387 |
9 | # define XS(name) void name(pTHXo_ CV* cv) |
a0d0e21e |
10 | #endif |
11 | |
12 | #define dXSARGS \ |
3c78fafa |
13 | dSP; dMARK; \ |
3280af22 |
14 | I32 ax = mark - PL_stack_base + 1; \ |
a0d0e21e |
15 | I32 items = sp - mark |
16 | |
8a7fc0dc |
17 | #define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \ |
18 | ? PAD_SV(PL_op->op_targ) : sv_newmortal()) |
19 | |
b26a54d0 |
20 | /* Should be used before final PUSHi etc. if not in PPCODE section. */ |
21 | #define XSprePUSH (sp = PL_stack_base + ax - 1) |
22 | |
a0d0e21e |
23 | #define XSANY CvXSUBANY(cv) |
24 | |
25 | #define dXSI32 I32 ix = XSANY.any_i32 |
26 | |
cfc02341 |
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) |
73c4f7a1 |
33 | #define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,cv))(f)) |
cfc02341 |
34 | #define XSINTERFACE_FUNC_SET(cv,f) \ |
51371543 |
35 | CvXSUBANY(cv).any_dptr = (void (*) (pTHXo_ void*))(f) |
cfc02341 |
36 | |
0e4ced38 |
37 | #define XSRETURN(off) \ |
38 | STMT_START { \ |
3280af22 |
39 | PL_stack_sp = PL_stack_base + ax + ((off) - 1); \ |
0e4ced38 |
40 | return; \ |
41 | } STMT_END |
a0d0e21e |
42 | |
748a9306 |
43 | /* Simple macros to put new mortal values onto the stack. */ |
44 | /* Typically used to return values from XS functions. */ |
4633a7c4 |
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))) |
79cb57f6 |
48 | #define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n))) |
3280af22 |
49 | #define XST_mNO(i) (ST(i) = &PL_sv_no ) |
50 | #define XST_mYES(i) (ST(i) = &PL_sv_yes ) |
51 | #define XST_mUNDEF(i) (ST(i) = &PL_sv_undef) |
748a9306 |
52 | |
80b92232 |
53 | #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END |
54 | #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END |
55 | #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END |
79cb57f6 |
56 | #define XSRETURN_PVN(v) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END |
80b92232 |
57 | #define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END |
58 | #define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END |
59 | #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END |
60 | #define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END |
382b8d97 |
61 | |
37120919 |
62 | #define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d) |
720fb644 |
63 | |
64 | #ifdef XS_VERSION |
c6af7a1a |
65 | # define XS_VERSION_BOOTCHECK \ |
774d564b |
66 | STMT_START { \ |
2d8e6c8d |
67 | SV *tmpsv; STRLEN n_a; \ |
68 | char *vn = Nullch, *module = SvPV(ST(0),n_a); \ |
774d564b |
69 | if (items >= 2) /* version supplied as bootstrap arg */ \ |
6b88bc9c |
70 | tmpsv = ST(1); \ |
774d564b |
71 | else { \ |
46fc3d4c |
72 | /* XXX GV_ADDWARN */ \ |
cea2e8a9 |
73 | tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \ |
864dbfa3 |
74 | vn = "XS_VERSION"), FALSE); \ |
6b88bc9c |
75 | if (!tmpsv || !SvOK(tmpsv)) \ |
cea2e8a9 |
76 | tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \ |
864dbfa3 |
77 | vn = "VERSION"), FALSE); \ |
774d564b |
78 | } \ |
2d8e6c8d |
79 | if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \ |
cea2e8a9 |
80 | Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %_", \ |
ae66e5c8 |
81 | module, XS_VERSION, \ |
82 | vn ? "$" : "", vn ? module : "", vn ? "::" : "", \ |
6b88bc9c |
83 | vn ? vn : "bootstrap parameter", tmpsv); \ |
80b92232 |
84 | } STMT_END |
720fb644 |
85 | #else |
c6af7a1a |
86 | # define XS_VERSION_BOOTCHECK |
720fb644 |
87 | #endif |
76e3520e |
88 | |
51371543 |
89 | #if 1 /* for compatibility */ |
dc9e4912 |
90 | # define VTBL_sv &PL_vtbl_sv |
91 | # define VTBL_env &PL_vtbl_env |
92 | # define VTBL_envelem &PL_vtbl_envelem |
93 | # define VTBL_sig &PL_vtbl_sig |
94 | # define VTBL_sigelem &PL_vtbl_sigelem |
95 | # define VTBL_pack &PL_vtbl_pack |
96 | # define VTBL_packelem &PL_vtbl_packelem |
97 | # define VTBL_dbline &PL_vtbl_dbline |
98 | # define VTBL_isa &PL_vtbl_isa |
99 | # define VTBL_isaelem &PL_vtbl_isaelem |
100 | # define VTBL_arylen &PL_vtbl_arylen |
101 | # define VTBL_glob &PL_vtbl_glob |
102 | # define VTBL_mglob &PL_vtbl_mglob |
103 | # define VTBL_nkeys &PL_vtbl_nkeys |
104 | # define VTBL_taint &PL_vtbl_taint |
105 | # define VTBL_substr &PL_vtbl_substr |
106 | # define VTBL_vec &PL_vtbl_vec |
107 | # define VTBL_pos &PL_vtbl_pos |
108 | # define VTBL_bm &PL_vtbl_bm |
109 | # define VTBL_fm &PL_vtbl_fm |
110 | # define VTBL_uvar &PL_vtbl_uvar |
111 | # define VTBL_defelem &PL_vtbl_defelem |
112 | # define VTBL_regexp &PL_vtbl_regexp |
113 | # define VTBL_regdata &PL_vtbl_regdata |
114 | # define VTBL_regdatum &PL_vtbl_regdatum |
115 | # ifdef USE_LOCALE_COLLATE |
116 | # define VTBL_collxfrm &PL_vtbl_collxfrm |
117 | # endif |
9e7bc3e8 |
118 | # define VTBL_amagic &PL_vtbl_amagic |
119 | # define VTBL_amagicelem &PL_vtbl_amagicelem |
dc9e4912 |
120 | #endif |
121 | |
c5be433b |
122 | #if defined(PERL_OBJECT) || defined(PERL_CAPI) |
51371543 |
123 | # include "perlapi.h" |
c6af7a1a |
124 | # include "objXSUB.h" |
c5be433b |
125 | #endif /* PERL_OBJECT || PERL_CAPI */ |
c6af7a1a |
126 | |
e8ee3774 |
127 | #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE) |
c5be433b |
128 | # undef aTHX |
129 | # undef aTHX_ |
54aff467 |
130 | # define aTHX PERL_GET_THX |
131 | # define aTHX_ aTHX, |
54aff467 |
132 | #endif |
133 | |
32e30700 |
134 | #if (defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)) && !defined(PERL_CORE) |
c6af7a1a |
135 | # ifndef NO_XSLOCKS |
136 | # undef closedir |
137 | # undef opendir |
138 | # undef stdin |
139 | # undef stdout |
140 | # undef stderr |
141 | # undef feof |
142 | # undef ferror |
143 | # undef fgetpos |
144 | # undef ioctl |
145 | # undef getlogin |
146 | # undef setjmp |
147 | # undef getc |
148 | # undef ungetc |
149 | # undef fileno |
150 | |
151 | # define mkdir PerlDir_mkdir |
152 | # define chdir PerlDir_chdir |
153 | # define rmdir PerlDir_rmdir |
154 | # define closedir PerlDir_close |
155 | # define opendir PerlDir_open |
156 | # define readdir PerlDir_read |
157 | # define rewinddir PerlDir_rewind |
158 | # define seekdir PerlDir_seek |
159 | # define telldir PerlDir_tell |
160 | # define putenv PerlEnv_putenv |
161 | # define getenv PerlEnv_getenv |
b2af26b1 |
162 | # define uname PerlEnv_uname |
c6af7a1a |
163 | # define stdin PerlIO_stdin() |
164 | # define stdout PerlIO_stdout() |
165 | # define stderr PerlIO_stderr() |
166 | # define fopen PerlIO_open |
167 | # define fclose PerlIO_close |
168 | # define feof PerlIO_eof |
169 | # define ferror PerlIO_error |
170 | # define fclearerr PerlIO_clearerr |
171 | # define getc PerlIO_getc |
172 | # define fputc(c, f) PerlIO_putc(f,c) |
173 | # define fputs(s, f) PerlIO_puts(f,s) |
174 | # define fflush PerlIO_flush |
175 | # define ungetc(c, f) PerlIO_ungetc((f),(c)) |
176 | # define fileno PerlIO_fileno |
177 | # define fdopen PerlIO_fdopen |
178 | # define freopen PerlIO_reopen |
179 | # define fread(b,s,c,f) PerlIO_read((f),(b),(s*c)) |
180 | # define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c)) |
181 | # define setbuf PerlIO_setbuf |
182 | # define setvbuf PerlIO_setvbuf |
183 | # define setlinebuf PerlIO_setlinebuf |
184 | # define stdoutf PerlIO_stdoutf |
185 | # define vfprintf PerlIO_vprintf |
186 | # define ftell PerlIO_tell |
187 | # define fseek PerlIO_seek |
188 | # define fgetpos PerlIO_getpos |
189 | # define fsetpos PerlIO_setpos |
190 | # define frewind PerlIO_rewind |
191 | # define tmpfile PerlIO_tmpfile |
192 | # define access PerlLIO_access |
193 | # define chmod PerlLIO_chmod |
194 | # define chsize PerlLIO_chsize |
195 | # define close PerlLIO_close |
196 | # define dup PerlLIO_dup |
197 | # define dup2 PerlLIO_dup2 |
198 | # define flock PerlLIO_flock |
199 | # define fstat PerlLIO_fstat |
200 | # define ioctl PerlLIO_ioctl |
201 | # define isatty PerlLIO_isatty |
6b980173 |
202 | # define link PerlLIO_link |
c6af7a1a |
203 | # define lseek PerlLIO_lseek |
204 | # define lstat PerlLIO_lstat |
205 | # define mktemp PerlLIO_mktemp |
206 | # define open PerlLIO_open |
207 | # define read PerlLIO_read |
208 | # define rename PerlLIO_rename |
209 | # define setmode PerlLIO_setmode |
4f49e16e |
210 | # define stat(buf,sb) PerlLIO_stat(buf,sb) |
c6af7a1a |
211 | # define tmpnam PerlLIO_tmpnam |
212 | # define umask PerlLIO_umask |
213 | # define unlink PerlLIO_unlink |
214 | # define utime PerlLIO_utime |
215 | # define write PerlLIO_write |
216 | # define malloc PerlMem_malloc |
217 | # define realloc PerlMem_realloc |
218 | # define free PerlMem_free |
219 | # define abort PerlProc_abort |
220 | # define exit PerlProc_exit |
221 | # define _exit PerlProc__exit |
222 | # define execl PerlProc_execl |
223 | # define execv PerlProc_execv |
224 | # define execvp PerlProc_execvp |
225 | # define getuid PerlProc_getuid |
226 | # define geteuid PerlProc_geteuid |
227 | # define getgid PerlProc_getgid |
228 | # define getegid PerlProc_getegid |
229 | # define getlogin PerlProc_getlogin |
230 | # define kill PerlProc_kill |
231 | # define killpg PerlProc_killpg |
232 | # define pause PerlProc_pause |
233 | # define popen PerlProc_popen |
234 | # define pclose PerlProc_pclose |
235 | # define pipe PerlProc_pipe |
236 | # define setuid PerlProc_setuid |
237 | # define setgid PerlProc_setgid |
238 | # define sleep PerlProc_sleep |
239 | # define times PerlProc_times |
240 | # define wait PerlProc_wait |
241 | # define setjmp PerlProc_setjmp |
242 | # define longjmp PerlProc_longjmp |
243 | # define signal PerlProc_signal |
7766f137 |
244 | # define getpid PerlProc_getpid |
c6af7a1a |
245 | # define htonl PerlSock_htonl |
246 | # define htons PerlSock_htons |
247 | # define ntohl PerlSock_ntohl |
248 | # define ntohs PerlSock_ntohs |
249 | # define accept PerlSock_accept |
250 | # define bind PerlSock_bind |
251 | # define connect PerlSock_connect |
252 | # define endhostent PerlSock_endhostent |
253 | # define endnetent PerlSock_endnetent |
254 | # define endprotoent PerlSock_endprotoent |
255 | # define endservent PerlSock_endservent |
256 | # define gethostbyaddr PerlSock_gethostbyaddr |
257 | # define gethostbyname PerlSock_gethostbyname |
258 | # define gethostent PerlSock_gethostent |
259 | # define gethostname PerlSock_gethostname |
260 | # define getnetbyaddr PerlSock_getnetbyaddr |
261 | # define getnetbyname PerlSock_getnetbyname |
262 | # define getnetent PerlSock_getnetent |
263 | # define getpeername PerlSock_getpeername |
264 | # define getprotobyname PerlSock_getprotobyname |
265 | # define getprotobynumber PerlSock_getprotobynumber |
266 | # define getprotoent PerlSock_getprotoent |
267 | # define getservbyname PerlSock_getservbyname |
268 | # define getservbyport PerlSock_getservbyport |
269 | # define getservent PerlSock_getservent |
270 | # define getsockname PerlSock_getsockname |
271 | # define getsockopt PerlSock_getsockopt |
272 | # define inet_addr PerlSock_inet_addr |
273 | # define inet_ntoa PerlSock_inet_ntoa |
274 | # define listen PerlSock_listen |
275 | # define recv PerlSock_recv |
276 | # define recvfrom PerlSock_recvfrom |
277 | # define select PerlSock_select |
278 | # define send PerlSock_send |
279 | # define sendto PerlSock_sendto |
280 | # define sethostent PerlSock_sethostent |
281 | # define setnetent PerlSock_setnetent |
282 | # define setprotoent PerlSock_setprotoent |
283 | # define setservent PerlSock_setservent |
284 | # define setsockopt PerlSock_setsockopt |
285 | # define shutdown PerlSock_shutdown |
286 | # define socket PerlSock_socket |
287 | # define socketpair PerlSock_socketpair |
c6af7a1a |
288 | # endif /* NO_XSLOCKS */ |
c5be433b |
289 | #endif /* PERL_CAPI */ |
b4ba0ab9 |
290 | |
cfeeb022 |
291 | #endif /* _INC_PERL_XSUB_H */ /* include guard */ |