1 | #ifndef _INC_PERL_XSUB_H |
---|
2 | #define _INC_PERL_XSUB_H 1 |
---|
3 | |
---|
4 | /* first, some documentation for xsubpp-generated items */ |
---|
5 | |
---|
6 | /* |
---|
7 | =for apidoc Amn|char*|CLASS |
---|
8 | Variable which is setup by C<xsubpp> to indicate the |
---|
9 | class name for a C++ XS constructor. This is always a C<char*>. See C<THIS>. |
---|
10 | |
---|
11 | =for apidoc Amn|(whatever)|RETVAL |
---|
12 | Variable which is setup by C<xsubpp> to hold the return value for an |
---|
13 | XSUB. This is always the proper type for the XSUB. See |
---|
14 | L<perlxs/"The RETVAL Variable">. |
---|
15 | |
---|
16 | =for apidoc Amn|(whatever)|THIS |
---|
17 | Variable which is setup by C<xsubpp> to designate the object in a C++ |
---|
18 | XSUB. This is always the proper type for the C++ object. See C<CLASS> and |
---|
19 | L<perlxs/"Using XS With C++">. |
---|
20 | |
---|
21 | =for apidoc Amn|I32|items |
---|
22 | Variable which is setup by C<xsubpp> to indicate the number of |
---|
23 | items on the stack. See L<perlxs/"Variable-length Parameter Lists">. |
---|
24 | |
---|
25 | =for apidoc Amn|I32|ix |
---|
26 | Variable which is setup by C<xsubpp> to indicate which of an |
---|
27 | XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">. |
---|
28 | |
---|
29 | =for apidoc Am|SV*|ST|int ix |
---|
30 | Used to access elements on the XSUB's stack. |
---|
31 | |
---|
32 | =for apidoc AmU||XS |
---|
33 | Macro to declare an XSUB and its C parameter list. This is handled by |
---|
34 | C<xsubpp>. |
---|
35 | |
---|
36 | =for apidoc Ams||dXSARGS |
---|
37 | Sets up stack and mark pointers for an XSUB, calling dSP and dMARK. This |
---|
38 | is usually handled automatically by C<xsubpp>. Declares the C<items> |
---|
39 | variable to indicate the number of items on the stack. |
---|
40 | |
---|
41 | =for apidoc Ams||dXSI32 |
---|
42 | Sets up the C<ix> variable for an XSUB which has aliases. This is usually |
---|
43 | handled automatically by C<xsubpp>. |
---|
44 | |
---|
45 | =cut |
---|
46 | */ |
---|
47 | |
---|
48 | #define ST(off) PL_stack_base[ax + (off)] |
---|
49 | |
---|
50 | #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING) |
---|
51 | # define XS(name) __declspec(dllexport) void name(pTHXo_ CV* cv) |
---|
52 | #else |
---|
53 | # define XS(name) void name(pTHXo_ CV* cv) |
---|
54 | #endif |
---|
55 | |
---|
56 | #define dXSARGS \ |
---|
57 | dSP; dMARK; \ |
---|
58 | I32 ax = mark - PL_stack_base + 1; \ |
---|
59 | I32 items = sp - mark |
---|
60 | |
---|
61 | #define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \ |
---|
62 | ? PAD_SV(PL_op->op_targ) : sv_newmortal()) |
---|
63 | |
---|
64 | /* Should be used before final PUSHi etc. if not in PPCODE section. */ |
---|
65 | #define XSprePUSH (sp = PL_stack_base + ax - 1) |
---|
66 | |
---|
67 | #define XSANY CvXSUBANY(cv) |
---|
68 | |
---|
69 | #define dXSI32 I32 ix = XSANY.any_i32 |
---|
70 | |
---|
71 | #ifdef __cplusplus |
---|
72 | # define XSINTERFACE_CVT(ret,name) ret (*name)(...) |
---|
73 | #else |
---|
74 | # define XSINTERFACE_CVT(ret,name) ret (*name)() |
---|
75 | #endif |
---|
76 | #define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION) |
---|
77 | #define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,cv))(f)) |
---|
78 | #define XSINTERFACE_FUNC_SET(cv,f) \ |
---|
79 | CvXSUBANY(cv).any_dptr = (void (*) (pTHXo_ void*))(f) |
---|
80 | |
---|
81 | /* Simple macros to put new mortal values onto the stack. */ |
---|
82 | /* Typically used to return values from XS functions. */ |
---|
83 | |
---|
84 | /* |
---|
85 | =for apidoc Am|void|XST_mIV|int pos|IV iv |
---|
86 | Place an integer into the specified position C<pos> on the stack. The |
---|
87 | value is stored in a new mortal SV. |
---|
88 | |
---|
89 | =for apidoc Am|void|XST_mNV|int pos|NV nv |
---|
90 | Place a double into the specified position C<pos> on the stack. The value |
---|
91 | is stored in a new mortal SV. |
---|
92 | |
---|
93 | =for apidoc Am|void|XST_mPV|int pos|char* str |
---|
94 | Place a copy of a string into the specified position C<pos> on the stack. |
---|
95 | The value is stored in a new mortal SV. |
---|
96 | |
---|
97 | =for apidoc Am|void|XST_mNO|int pos |
---|
98 | Place C<&PL_sv_no> into the specified position C<pos> on the |
---|
99 | stack. |
---|
100 | |
---|
101 | =for apidoc Am|void|XST_mYES|int pos |
---|
102 | Place C<&PL_sv_yes> into the specified position C<pos> on the |
---|
103 | stack. |
---|
104 | |
---|
105 | =for apidoc Am|void|XST_mUNDEF|int pos |
---|
106 | Place C<&PL_sv_undef> into the specified position C<pos> on the |
---|
107 | stack. |
---|
108 | |
---|
109 | =for apidoc Am|void|XSRETURN|int nitems |
---|
110 | Return from XSUB, indicating number of items on the stack. This is usually |
---|
111 | handled by C<xsubpp>. |
---|
112 | |
---|
113 | =for apidoc Am|void|XSRETURN_IV|IV iv |
---|
114 | Return an integer from an XSUB immediately. Uses C<XST_mIV>. |
---|
115 | |
---|
116 | =for apidoc Am|void|XSRETURN_NV|NV nv |
---|
117 | Return an double from an XSUB immediately. Uses C<XST_mNV>. |
---|
118 | |
---|
119 | =for apidoc Am|void|XSRETURN_PV|char* str |
---|
120 | Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>. |
---|
121 | |
---|
122 | =for apidoc Ams||XSRETURN_NO |
---|
123 | Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>. |
---|
124 | |
---|
125 | =for apidoc Ams||XSRETURN_YES |
---|
126 | Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>. |
---|
127 | |
---|
128 | =for apidoc Ams||XSRETURN_UNDEF |
---|
129 | Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>. |
---|
130 | |
---|
131 | =for apidoc Ams||XSRETURN_EMPTY |
---|
132 | Return an empty list from an XSUB immediately. |
---|
133 | |
---|
134 | =for apidoc AmU||newXSproto |
---|
135 | Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to |
---|
136 | the subs. |
---|
137 | |
---|
138 | =for apidoc AmU||XS_VERSION |
---|
139 | The version identifier for an XS module. This is usually |
---|
140 | handled automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>. |
---|
141 | |
---|
142 | =for apidoc Ams||XS_VERSION_BOOTCHECK |
---|
143 | Macro to verify that a PM module's $VERSION variable matches the XS |
---|
144 | module's C<XS_VERSION> variable. This is usually handled automatically by |
---|
145 | C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">. |
---|
146 | |
---|
147 | =cut |
---|
148 | */ |
---|
149 | |
---|
150 | #define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) ) |
---|
151 | #define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) ) |
---|
152 | #define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0))) |
---|
153 | #define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n))) |
---|
154 | #define XST_mNO(i) (ST(i) = &PL_sv_no ) |
---|
155 | #define XST_mYES(i) (ST(i) = &PL_sv_yes ) |
---|
156 | #define XST_mUNDEF(i) (ST(i) = &PL_sv_undef) |
---|
157 | |
---|
158 | #define XSRETURN(off) \ |
---|
159 | STMT_START { \ |
---|
160 | PL_stack_sp = PL_stack_base + ax + ((off) - 1); \ |
---|
161 | return; \ |
---|
162 | } STMT_END |
---|
163 | |
---|
164 | #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END |
---|
165 | #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END |
---|
166 | #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END |
---|
167 | #define XSRETURN_PVN(v,n) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END |
---|
168 | #define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END |
---|
169 | #define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END |
---|
170 | #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END |
---|
171 | #define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END |
---|
172 | |
---|
173 | #define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d) |
---|
174 | |
---|
175 | #ifdef XS_VERSION |
---|
176 | # define XS_VERSION_BOOTCHECK \ |
---|
177 | STMT_START { \ |
---|
178 | SV *tmpsv; STRLEN n_a; \ |
---|
179 | char *vn = Nullch, *module = SvPV(ST(0),n_a); \ |
---|
180 | if (items >= 2) /* version supplied as bootstrap arg */ \ |
---|
181 | tmpsv = ST(1); \ |
---|
182 | else { \ |
---|
183 | /* XXX GV_ADDWARN */ \ |
---|
184 | tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \ |
---|
185 | vn = "XS_VERSION"), FALSE); \ |
---|
186 | if (!tmpsv || !SvOK(tmpsv)) \ |
---|
187 | tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \ |
---|
188 | vn = "VERSION"), FALSE); \ |
---|
189 | } \ |
---|
190 | if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \ |
---|
191 | Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %"SVf,\ |
---|
192 | module, XS_VERSION, \ |
---|
193 | vn ? "$" : "", vn ? module : "", vn ? "::" : "", \ |
---|
194 | vn ? vn : "bootstrap parameter", tmpsv); \ |
---|
195 | } STMT_END |
---|
196 | #else |
---|
197 | # define XS_VERSION_BOOTCHECK |
---|
198 | #endif |
---|
199 | |
---|
200 | #if 1 /* for compatibility */ |
---|
201 | # define VTBL_sv &PL_vtbl_sv |
---|
202 | # define VTBL_env &PL_vtbl_env |
---|
203 | # define VTBL_envelem &PL_vtbl_envelem |
---|
204 | # define VTBL_sig &PL_vtbl_sig |
---|
205 | # define VTBL_sigelem &PL_vtbl_sigelem |
---|
206 | # define VTBL_pack &PL_vtbl_pack |
---|
207 | # define VTBL_packelem &PL_vtbl_packelem |
---|
208 | # define VTBL_dbline &PL_vtbl_dbline |
---|
209 | # define VTBL_isa &PL_vtbl_isa |
---|
210 | # define VTBL_isaelem &PL_vtbl_isaelem |
---|
211 | # define VTBL_arylen &PL_vtbl_arylen |
---|
212 | # define VTBL_glob &PL_vtbl_glob |
---|
213 | # define VTBL_mglob &PL_vtbl_mglob |
---|
214 | # define VTBL_nkeys &PL_vtbl_nkeys |
---|
215 | # define VTBL_taint &PL_vtbl_taint |
---|
216 | # define VTBL_substr &PL_vtbl_substr |
---|
217 | # define VTBL_vec &PL_vtbl_vec |
---|
218 | # define VTBL_pos &PL_vtbl_pos |
---|
219 | # define VTBL_bm &PL_vtbl_bm |
---|
220 | # define VTBL_fm &PL_vtbl_fm |
---|
221 | # define VTBL_uvar &PL_vtbl_uvar |
---|
222 | # define VTBL_defelem &PL_vtbl_defelem |
---|
223 | # define VTBL_regexp &PL_vtbl_regexp |
---|
224 | # define VTBL_regdata &PL_vtbl_regdata |
---|
225 | # define VTBL_regdatum &PL_vtbl_regdatum |
---|
226 | # ifdef USE_LOCALE_COLLATE |
---|
227 | # define VTBL_collxfrm &PL_vtbl_collxfrm |
---|
228 | # endif |
---|
229 | # define VTBL_amagic &PL_vtbl_amagic |
---|
230 | # define VTBL_amagicelem &PL_vtbl_amagicelem |
---|
231 | #endif |
---|
232 | |
---|
233 | #include "perlapi.h" |
---|
234 | #include "objXSUB.h" |
---|
235 | |
---|
236 | #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE) |
---|
237 | # undef aTHX |
---|
238 | # undef aTHX_ |
---|
239 | # define aTHX PERL_GET_THX |
---|
240 | # define aTHX_ aTHX, |
---|
241 | #endif |
---|
242 | |
---|
243 | #if (defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)) && !defined(PERL_CORE) |
---|
244 | # ifndef NO_XSLOCKS |
---|
245 | # undef closedir |
---|
246 | # undef opendir |
---|
247 | # undef stdin |
---|
248 | # undef stdout |
---|
249 | # undef stderr |
---|
250 | # undef feof |
---|
251 | # undef ferror |
---|
252 | # undef fgetpos |
---|
253 | # undef ioctl |
---|
254 | # undef getlogin |
---|
255 | # undef setjmp |
---|
256 | # undef getc |
---|
257 | # undef ungetc |
---|
258 | # undef fileno |
---|
259 | |
---|
260 | # define mkdir PerlDir_mkdir |
---|
261 | # define chdir PerlDir_chdir |
---|
262 | # define rmdir PerlDir_rmdir |
---|
263 | # define closedir PerlDir_close |
---|
264 | # define opendir PerlDir_open |
---|
265 | # define readdir PerlDir_read |
---|
266 | # define rewinddir PerlDir_rewind |
---|
267 | # define seekdir PerlDir_seek |
---|
268 | # define telldir PerlDir_tell |
---|
269 | # define putenv PerlEnv_putenv |
---|
270 | # define getenv PerlEnv_getenv |
---|
271 | # define uname PerlEnv_uname |
---|
272 | # define stdin PerlIO_stdin() |
---|
273 | # define stdout PerlIO_stdout() |
---|
274 | # define stderr PerlIO_stderr() |
---|
275 | # define fopen PerlIO_open |
---|
276 | # define fclose PerlIO_close |
---|
277 | # define feof PerlIO_eof |
---|
278 | # define ferror PerlIO_error |
---|
279 | # define fclearerr PerlIO_clearerr |
---|
280 | # define getc PerlIO_getc |
---|
281 | # define fputc(c, f) PerlIO_putc(f,c) |
---|
282 | # define fputs(s, f) PerlIO_puts(f,s) |
---|
283 | # define fflush PerlIO_flush |
---|
284 | # define ungetc(c, f) PerlIO_ungetc((f),(c)) |
---|
285 | # define fileno PerlIO_fileno |
---|
286 | # define fdopen PerlIO_fdopen |
---|
287 | # define freopen PerlIO_reopen |
---|
288 | # define fread(b,s,c,f) PerlIO_read((f),(b),(s*c)) |
---|
289 | # define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c)) |
---|
290 | # define setbuf PerlIO_setbuf |
---|
291 | # define setvbuf PerlIO_setvbuf |
---|
292 | # define setlinebuf PerlIO_setlinebuf |
---|
293 | # define stdoutf PerlIO_stdoutf |
---|
294 | # define vfprintf PerlIO_vprintf |
---|
295 | # define ftell PerlIO_tell |
---|
296 | # define fseek PerlIO_seek |
---|
297 | # define fgetpos PerlIO_getpos |
---|
298 | # define fsetpos PerlIO_setpos |
---|
299 | # define frewind PerlIO_rewind |
---|
300 | # define tmpfile PerlIO_tmpfile |
---|
301 | # define access PerlLIO_access |
---|
302 | # define chmod PerlLIO_chmod |
---|
303 | # define chsize PerlLIO_chsize |
---|
304 | # define close PerlLIO_close |
---|
305 | # define dup PerlLIO_dup |
---|
306 | # define dup2 PerlLIO_dup2 |
---|
307 | # define flock PerlLIO_flock |
---|
308 | # define fstat PerlLIO_fstat |
---|
309 | # define ioctl PerlLIO_ioctl |
---|
310 | # define isatty PerlLIO_isatty |
---|
311 | # define link PerlLIO_link |
---|
312 | # define lseek PerlLIO_lseek |
---|
313 | # define lstat PerlLIO_lstat |
---|
314 | # define mktemp PerlLIO_mktemp |
---|
315 | # define open PerlLIO_open |
---|
316 | # define read PerlLIO_read |
---|
317 | # define rename PerlLIO_rename |
---|
318 | # define setmode PerlLIO_setmode |
---|
319 | # define stat(buf,sb) PerlLIO_stat(buf,sb) |
---|
320 | # define tmpnam PerlLIO_tmpnam |
---|
321 | # define umask PerlLIO_umask |
---|
322 | # define unlink PerlLIO_unlink |
---|
323 | # define utime PerlLIO_utime |
---|
324 | # define write PerlLIO_write |
---|
325 | # define malloc PerlMem_malloc |
---|
326 | # define realloc PerlMem_realloc |
---|
327 | # define free PerlMem_free |
---|
328 | # define abort PerlProc_abort |
---|
329 | # define exit PerlProc_exit |
---|
330 | # define _exit PerlProc__exit |
---|
331 | # define execl PerlProc_execl |
---|
332 | # define execv PerlProc_execv |
---|
333 | # define execvp PerlProc_execvp |
---|
334 | # define getuid PerlProc_getuid |
---|
335 | # define geteuid PerlProc_geteuid |
---|
336 | # define getgid PerlProc_getgid |
---|
337 | # define getegid PerlProc_getegid |
---|
338 | # define getlogin PerlProc_getlogin |
---|
339 | # define kill PerlProc_kill |
---|
340 | # define killpg PerlProc_killpg |
---|
341 | # define pause PerlProc_pause |
---|
342 | # define popen PerlProc_popen |
---|
343 | # define pclose PerlProc_pclose |
---|
344 | # define pipe PerlProc_pipe |
---|
345 | # define setuid PerlProc_setuid |
---|
346 | # define setgid PerlProc_setgid |
---|
347 | # define sleep PerlProc_sleep |
---|
348 | # define times PerlProc_times |
---|
349 | # define wait PerlProc_wait |
---|
350 | # define setjmp PerlProc_setjmp |
---|
351 | # define longjmp PerlProc_longjmp |
---|
352 | # define signal PerlProc_signal |
---|
353 | # define getpid PerlProc_getpid |
---|
354 | # define htonl PerlSock_htonl |
---|
355 | # define htons PerlSock_htons |
---|
356 | # define ntohl PerlSock_ntohl |
---|
357 | # define ntohs PerlSock_ntohs |
---|
358 | # define accept PerlSock_accept |
---|
359 | # define bind PerlSock_bind |
---|
360 | # define connect PerlSock_connect |
---|
361 | # define endhostent PerlSock_endhostent |
---|
362 | # define endnetent PerlSock_endnetent |
---|
363 | # define endprotoent PerlSock_endprotoent |
---|
364 | # define endservent PerlSock_endservent |
---|
365 | # define gethostbyaddr PerlSock_gethostbyaddr |
---|
366 | # define gethostbyname PerlSock_gethostbyname |
---|
367 | # define gethostent PerlSock_gethostent |
---|
368 | # define gethostname PerlSock_gethostname |
---|
369 | # define getnetbyaddr PerlSock_getnetbyaddr |
---|
370 | # define getnetbyname PerlSock_getnetbyname |
---|
371 | # define getnetent PerlSock_getnetent |
---|
372 | # define getpeername PerlSock_getpeername |
---|
373 | # define getprotobyname PerlSock_getprotobyname |
---|
374 | # define getprotobynumber PerlSock_getprotobynumber |
---|
375 | # define getprotoent PerlSock_getprotoent |
---|
376 | # define getservbyname PerlSock_getservbyname |
---|
377 | # define getservbyport PerlSock_getservbyport |
---|
378 | # define getservent PerlSock_getservent |
---|
379 | # define getsockname PerlSock_getsockname |
---|
380 | # define getsockopt PerlSock_getsockopt |
---|
381 | # define inet_addr PerlSock_inet_addr |
---|
382 | # define inet_ntoa PerlSock_inet_ntoa |
---|
383 | # define listen PerlSock_listen |
---|
384 | # define recv PerlSock_recv |
---|
385 | # define recvfrom PerlSock_recvfrom |
---|
386 | # define select PerlSock_select |
---|
387 | # define send PerlSock_send |
---|
388 | # define sendto PerlSock_sendto |
---|
389 | # define sethostent PerlSock_sethostent |
---|
390 | # define setnetent PerlSock_setnetent |
---|
391 | # define setprotoent PerlSock_setprotoent |
---|
392 | # define setservent PerlSock_setservent |
---|
393 | # define setsockopt PerlSock_setsockopt |
---|
394 | # define shutdown PerlSock_shutdown |
---|
395 | # define socket PerlSock_socket |
---|
396 | # define socketpair PerlSock_socketpair |
---|
397 | # endif /* NO_XSLOCKS */ |
---|
398 | #endif /* PERL_CAPI */ |
---|
399 | |
---|
400 | #endif /* _INC_PERL_XSUB_H */ /* include guard */ |
---|