Test case for #10433/#10424.
[p5sagit/p5-mst-13.2.git] / XSUB.h
CommitLineData
b4ba0ab9 1#ifndef _INC_PERL_XSUB_H
2#define _INC_PERL_XSUB_H 1
3
954c1994 4/* first, some documentation for xsubpp-generated items */
5
6/*
7=for apidoc Amn|char*|CLASS
8Variable which is setup by C<xsubpp> to indicate the
9class name for a C++ XS constructor. This is always a C<char*>. See C<THIS>.
10
11=for apidoc Amn|(whatever)|RETVAL
12Variable which is setup by C<xsubpp> to hold the return value for an
13XSUB. This is always the proper type for the XSUB. See
14L<perlxs/"The RETVAL Variable">.
15
16=for apidoc Amn|(whatever)|THIS
17Variable which is setup by C<xsubpp> to designate the object in a C++
18XSUB. This is always the proper type for the C++ object. See C<CLASS> and
19L<perlxs/"Using XS With C++">.
20
21=for apidoc Amn|I32|items
22Variable which is setup by C<xsubpp> to indicate the number of
23items on the stack. See L<perlxs/"Variable-length Parameter Lists">.
24
25=for apidoc Amn|I32|ix
26Variable which is setup by C<xsubpp> to indicate which of an
27XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">.
28
29=for apidoc Am|SV*|ST|int ix
30Used to access elements on the XSUB's stack.
31
32=for apidoc AmU||XS
33Macro to declare an XSUB and its C parameter list. This is handled by
34C<xsubpp>.
35
36=for apidoc Ams||dXSARGS
37Sets up stack and mark pointers for an XSUB, calling dSP and dMARK. This
38is usually handled automatically by C<xsubpp>. Declares the C<items>
39variable to indicate the number of items on the stack.
40
41=for apidoc Ams||dXSI32
42Sets up the C<ix> variable for an XSUB which has aliases. This is usually
43handled automatically by C<xsubpp>.
44
45=cut
46*/
47
3280af22 48#define ST(off) PL_stack_base[ax + (off)]
a0d0e21e 49
d308986b 50#if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
0cb96387 51# define XS(name) __declspec(dllexport) void name(pTHXo_ CV* cv)
cea2e8a9 52#else
0cb96387 53# define XS(name) void name(pTHXo_ CV* cv)
a0d0e21e 54#endif
55
56#define dXSARGS \
3c78fafa 57 dSP; dMARK; \
3280af22 58 I32 ax = mark - PL_stack_base + 1; \
a0d0e21e 59 I32 items = sp - mark
60
8a7fc0dc 61#define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
62 ? PAD_SV(PL_op->op_targ) : sv_newmortal())
63
b26a54d0 64/* Should be used before final PUSHi etc. if not in PPCODE section. */
65#define XSprePUSH (sp = PL_stack_base + ax - 1)
66
a0d0e21e 67#define XSANY CvXSUBANY(cv)
68
69#define dXSI32 I32 ix = XSANY.any_i32
70
cfc02341 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)
73c4f7a1 77#define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,cv))(f))
cfc02341 78#define XSINTERFACE_FUNC_SET(cv,f) \
51371543 79 CvXSUBANY(cv).any_dptr = (void (*) (pTHXo_ void*))(f)
cfc02341 80
748a9306 81/* Simple macros to put new mortal values onto the stack. */
82/* Typically used to return values from XS functions. */
954c1994 83
84/*
85=for apidoc Am|void|XST_mIV|int pos|IV iv
86Place an integer into the specified position C<pos> on the stack. The
87value is stored in a new mortal SV.
88
89=for apidoc Am|void|XST_mNV|int pos|NV nv
90Place a double into the specified position C<pos> on the stack. The value
91is stored in a new mortal SV.
92
93=for apidoc Am|void|XST_mPV|int pos|char* str
94Place a copy of a string into the specified position C<pos> on the stack.
95The value is stored in a new mortal SV.
96
97=for apidoc Am|void|XST_mNO|int pos
98Place C<&PL_sv_no> into the specified position C<pos> on the
99stack.
100
101=for apidoc Am|void|XST_mYES|int pos
102Place C<&PL_sv_yes> into the specified position C<pos> on the
103stack.
104
105=for apidoc Am|void|XST_mUNDEF|int pos
106Place C<&PL_sv_undef> into the specified position C<pos> on the
107stack.
108
109=for apidoc Am|void|XSRETURN|int nitems
110Return from XSUB, indicating number of items on the stack. This is usually
111handled by C<xsubpp>.
112
113=for apidoc Am|void|XSRETURN_IV|IV iv
114Return an integer from an XSUB immediately. Uses C<XST_mIV>.
115
116=for apidoc Am|void|XSRETURN_NV|NV nv
117Return an double from an XSUB immediately. Uses C<XST_mNV>.
118
119=for apidoc Am|void|XSRETURN_PV|char* str
120Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
121
122=for apidoc Ams||XSRETURN_NO
123Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
124
125=for apidoc Ams||XSRETURN_YES
126Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
127
128=for apidoc Ams||XSRETURN_UNDEF
129Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
130
131=for apidoc Ams||XSRETURN_EMPTY
132Return an empty list from an XSUB immediately.
133
134=for apidoc AmU||newXSproto
135Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to
136the subs.
137
138=for apidoc AmU||XS_VERSION
139The version identifier for an XS module. This is usually
140handled automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>.
141
142=for apidoc Ams||XS_VERSION_BOOTCHECK
143Macro to verify that a PM module's $VERSION variable matches the XS
144module's C<XS_VERSION> variable. This is usually handled automatically by
145C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.
146
147=cut
148*/
149
4633a7c4 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)))
79cb57f6 153#define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n)))
3280af22 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)
954c1994 157
158#define XSRETURN(off) \
159 STMT_START { \
160 PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
161 return; \
162 } STMT_END
163
80b92232 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
954c1994 167#define XSRETURN_PVN(v,n) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END
80b92232 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
382b8d97 172
37120919 173#define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
720fb644 174
175#ifdef XS_VERSION
c6af7a1a 176# define XS_VERSION_BOOTCHECK \
774d564b 177 STMT_START { \
2d8e6c8d 178 SV *tmpsv; STRLEN n_a; \
179 char *vn = Nullch, *module = SvPV(ST(0),n_a); \
774d564b 180 if (items >= 2) /* version supplied as bootstrap arg */ \
6b88bc9c 181 tmpsv = ST(1); \
774d564b 182 else { \
46fc3d4c 183 /* XXX GV_ADDWARN */ \
cea2e8a9 184 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
864dbfa3 185 vn = "XS_VERSION"), FALSE); \
6b88bc9c 186 if (!tmpsv || !SvOK(tmpsv)) \
cea2e8a9 187 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
864dbfa3 188 vn = "VERSION"), FALSE); \
774d564b 189 } \
2d8e6c8d 190 if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \
894356b3 191 Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %"SVf,\
ae66e5c8 192 module, XS_VERSION, \
193 vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
6b88bc9c 194 vn ? vn : "bootstrap parameter", tmpsv); \
80b92232 195 } STMT_END
720fb644 196#else
c6af7a1a 197# define XS_VERSION_BOOTCHECK
720fb644 198#endif
76e3520e 199
51371543 200#if 1 /* for compatibility */
dc9e4912 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
9e7bc3e8 229# define VTBL_amagic &PL_vtbl_amagic
230# define VTBL_amagicelem &PL_vtbl_amagicelem
dc9e4912 231#endif
232
6f4183fe 233#include "perlapi.h"
234#include "objXSUB.h"
c6af7a1a 235
e8ee3774 236#if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE)
c5be433b 237# undef aTHX
238# undef aTHX_
54aff467 239# define aTHX PERL_GET_THX
240# define aTHX_ aTHX,
54aff467 241#endif
242
32e30700 243#if (defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)) && !defined(PERL_CORE)
c6af7a1a 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
b2af26b1 271# define uname PerlEnv_uname
c6af7a1a 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
6b980173 311# define link PerlLIO_link
c6af7a1a 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
4f49e16e 319# define stat(buf,sb) PerlLIO_stat(buf,sb)
c6af7a1a 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
7766f137 353# define getpid PerlProc_getpid
c6af7a1a 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
c6af7a1a 397# endif /* NO_XSLOCKS */
c5be433b 398#endif /* PERL_CAPI */
b4ba0ab9 399
cfeeb022 400#endif /* _INC_PERL_XSUB_H */ /* include guard */