This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
sundry cleanups for clean build on windows
[perl5.git] / XSUB.h
CommitLineData
3280af22 1#define ST(off) PL_stack_base[ax + (off)]
a0d0e21e 2
0cb96387
GS
3#if defined(CYGWIN32) && defined(USE_DYNAMIC_LOADING)
4# define XS(name) __declspec(dllexport) void name(pTHXo_ CV* cv)
cea2e8a9 5#else
0cb96387 6# define XS(name) void name(pTHXo_ CV* cv)
a0d0e21e
LW
7#endif
8
9#define dXSARGS \
3c78fafa 10 dSP; dMARK; \
3280af22 11 I32 ax = mark - PL_stack_base + 1; \
a0d0e21e
LW
12 I32 items = sp - mark
13
14#define XSANY CvXSUBANY(cv)
15
16#define dXSI32 I32 ix = XSANY.any_i32
17
cfc02341
IZ
18#ifdef __cplusplus
19# define XSINTERFACE_CVT(ret,name) ret (*name)(...)
20#else
21# define XSINTERFACE_CVT(ret,name) ret (*name)()
22#endif
23#define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION)
73c4f7a1 24#define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,cv))(f))
cfc02341 25#define XSINTERFACE_FUNC_SET(cv,f) \
cea2e8a9 26 CvXSUBANY(cv).any_dptr = (void (*) (pTHX_ void*))(f)
cfc02341 27
0e4ced38
GS
28#define XSRETURN(off) \
29 STMT_START { \
3280af22 30 PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
0e4ced38
GS
31 return; \
32 } STMT_END
a0d0e21e 33
748a9306
LW
34/* Simple macros to put new mortal values onto the stack. */
35/* Typically used to return values from XS functions. */
4633a7c4
LW
36#define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )
37#define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )
38#define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))
79cb57f6 39#define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n)))
3280af22
NIS
40#define XST_mNO(i) (ST(i) = &PL_sv_no )
41#define XST_mYES(i) (ST(i) = &PL_sv_yes )
42#define XST_mUNDEF(i) (ST(i) = &PL_sv_undef)
748a9306 43
80b92232
PP
44#define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END
45#define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END
46#define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END
79cb57f6 47#define XSRETURN_PVN(v) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END
80b92232
PP
48#define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END
49#define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END
50#define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
51#define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END
382b8d97 52
37120919 53#define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
720fb644
PP
54
55#ifdef XS_VERSION
c6af7a1a 56# define XS_VERSION_BOOTCHECK \
774d564b 57 STMT_START { \
2d8e6c8d
GS
58 SV *tmpsv; STRLEN n_a; \
59 char *vn = Nullch, *module = SvPV(ST(0),n_a); \
774d564b 60 if (items >= 2) /* version supplied as bootstrap arg */ \
6b88bc9c 61 tmpsv = ST(1); \
774d564b 62 else { \
46fc3d4c 63 /* XXX GV_ADDWARN */ \
cea2e8a9 64 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
864dbfa3 65 vn = "XS_VERSION"), FALSE); \
6b88bc9c 66 if (!tmpsv || !SvOK(tmpsv)) \
cea2e8a9 67 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
864dbfa3 68 vn = "VERSION"), FALSE); \
774d564b 69 } \
2d8e6c8d 70 if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \
cea2e8a9 71 Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %_", \
ae66e5c8
CS
72 module, XS_VERSION, \
73 vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
6b88bc9c 74 vn ? vn : "bootstrap parameter", tmpsv); \
80b92232 75 } STMT_END
720fb644 76#else
c6af7a1a 77# define XS_VERSION_BOOTCHECK
720fb644 78#endif
76e3520e 79
dc9e4912
GS
80#ifdef PERL_CAPI
81# define VTBL_sv get_vtbl(want_vtbl_sv)
82# define VTBL_env get_vtbl(want_vtbl_env)
83# define VTBL_envelem get_vtbl(want_vtbl_envelem)
84# define VTBL_sig get_vtbl(want_vtbl_sig)
85# define VTBL_sigelem get_vtbl(want_vtbl_sigelem)
86# define VTBL_pack get_vtbl(want_vtbl_pack)
87# define VTBL_packelem get_vtbl(want_vtbl_packelem)
88# define VTBL_dbline get_vtbl(want_vtbl_dbline)
89# define VTBL_isa get_vtbl(want_vtbl_isa)
90# define VTBL_isaelem get_vtbl(want_vtbl_isaelem)
91# define VTBL_arylen get_vtbl(want_vtbl_arylen)
92# define VTBL_glob get_vtbl(want_vtbl_glob)
93# define VTBL_mglob get_vtbl(want_vtbl_mglob)
94# define VTBL_nkeys get_vtbl(want_vtbl_nkeys)
95# define VTBL_taint get_vtbl(want_vtbl_taint)
96# define VTBL_substr get_vtbl(want_vtbl_substr)
97# define VTBL_vec get_vtbl(want_vtbl_vec)
98# define VTBL_pos get_vtbl(want_vtbl_pos)
99# define VTBL_bm get_vtbl(want_vtbl_bm)
100# define VTBL_fm get_vtbl(want_vtbl_fm)
101# define VTBL_uvar get_vtbl(want_vtbl_uvar)
102# define VTBL_defelem get_vtbl(want_vtbl_defelem)
103# define VTBL_regexp get_vtbl(want_vtbl_regexp)
104# define VTBL_regdata get_vtbl(want_vtbl_regdata)
105# define VTBL_regdatum get_vtbl(want_vtbl_regdatum)
106# ifdef USE_LOCALE_COLLATE
107# define VTBL_collxfrm get_vtbl(want_vtbl_collxfrm)
108# endif
9e7bc3e8
JD
109# define VTBL_amagic get_vtbl(want_vtbl_amagic)
110# define VTBL_amagicelem get_vtbl(want_vtbl_amagicelem)
dc9e4912
GS
111#else
112# define VTBL_sv &PL_vtbl_sv
113# define VTBL_env &PL_vtbl_env
114# define VTBL_envelem &PL_vtbl_envelem
115# define VTBL_sig &PL_vtbl_sig
116# define VTBL_sigelem &PL_vtbl_sigelem
117# define VTBL_pack &PL_vtbl_pack
118# define VTBL_packelem &PL_vtbl_packelem
119# define VTBL_dbline &PL_vtbl_dbline
120# define VTBL_isa &PL_vtbl_isa
121# define VTBL_isaelem &PL_vtbl_isaelem
122# define VTBL_arylen &PL_vtbl_arylen
123# define VTBL_glob &PL_vtbl_glob
124# define VTBL_mglob &PL_vtbl_mglob
125# define VTBL_nkeys &PL_vtbl_nkeys
126# define VTBL_taint &PL_vtbl_taint
127# define VTBL_substr &PL_vtbl_substr
128# define VTBL_vec &PL_vtbl_vec
129# define VTBL_pos &PL_vtbl_pos
130# define VTBL_bm &PL_vtbl_bm
131# define VTBL_fm &PL_vtbl_fm
132# define VTBL_uvar &PL_vtbl_uvar
133# define VTBL_defelem &PL_vtbl_defelem
134# define VTBL_regexp &PL_vtbl_regexp
135# define VTBL_regdata &PL_vtbl_regdata
136# define VTBL_regdatum &PL_vtbl_regdatum
137# ifdef USE_LOCALE_COLLATE
138# define VTBL_collxfrm &PL_vtbl_collxfrm
139# endif
9e7bc3e8
JD
140# define VTBL_amagic &PL_vtbl_amagic
141# define VTBL_amagicelem &PL_vtbl_amagicelem
dc9e4912
GS
142#endif
143
76e3520e 144#ifdef PERL_OBJECT
c6af7a1a
GS
145# include "objXSUB.h"
146
0cb96387
GS
147# undef aTHXo
148# define aTHXo pPerl
149# undef aTHXo_
150# define aTHXo_ aTHXo,
151# undef _aTHXo
152# define _aTHXo ,aTHXo
c6af7a1a
GS
153
154# undef SAVEDESTRUCTOR
155# define SAVEDESTRUCTOR(f,p) \
156 pPerl->Perl_save_destructor((FUNC_NAME_TO_PTR(f)),(p))
157
158# ifdef WIN32
159# ifndef WIN32IO_IS_STDIO
160# undef errno
161# define errno ErrorNo()
162# endif
c6af7a1a
GS
163# undef NtCrypt
164# define NtCrypt pPerl->NtCrypt
165# undef NtGetLib
166# define NtGetLib pPerl->NtGetLib
167# undef NtGetArchLib
168# define NtGetArchLib pPerl->NtGetArchLib
169# undef NtGetSiteLib
170# define NtGetSiteLib pPerl->NtGetSiteLib
171# undef NtGetBin
172# define NtGetBin pPerl->NtGetBin
173# undef NtGetDebugScriptStr
174# define NtGetDebugScriptStr pPerl->NtGetDebugScriptStr
0cb96387
GS
175# undef fprintf
176# define fprintf pPerl->fprintf
c6af7a1a
GS
177# endif /* WIN32 */
178
179# ifndef NO_XSLOCKS
180# undef closedir
181# undef opendir
182# undef stdin
183# undef stdout
184# undef stderr
185# undef feof
186# undef ferror
187# undef fgetpos
188# undef ioctl
189# undef getlogin
190# undef setjmp
191# undef getc
192# undef ungetc
193# undef fileno
194
195# define mkdir PerlDir_mkdir
196# define chdir PerlDir_chdir
197# define rmdir PerlDir_rmdir
198# define closedir PerlDir_close
199# define opendir PerlDir_open
200# define readdir PerlDir_read
201# define rewinddir PerlDir_rewind
202# define seekdir PerlDir_seek
203# define telldir PerlDir_tell
204# define putenv PerlEnv_putenv
205# define getenv PerlEnv_getenv
b2af26b1 206# define uname PerlEnv_uname
c6af7a1a
GS
207# define stdin PerlIO_stdin()
208# define stdout PerlIO_stdout()
209# define stderr PerlIO_stderr()
210# define fopen PerlIO_open
211# define fclose PerlIO_close
212# define feof PerlIO_eof
213# define ferror PerlIO_error
214# define fclearerr PerlIO_clearerr
215# define getc PerlIO_getc
216# define fputc(c, f) PerlIO_putc(f,c)
217# define fputs(s, f) PerlIO_puts(f,s)
218# define fflush PerlIO_flush
219# define ungetc(c, f) PerlIO_ungetc((f),(c))
220# define fileno PerlIO_fileno
221# define fdopen PerlIO_fdopen
222# define freopen PerlIO_reopen
223# define fread(b,s,c,f) PerlIO_read((f),(b),(s*c))
224# define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c))
225# define setbuf PerlIO_setbuf
226# define setvbuf PerlIO_setvbuf
227# define setlinebuf PerlIO_setlinebuf
228# define stdoutf PerlIO_stdoutf
229# define vfprintf PerlIO_vprintf
230# define ftell PerlIO_tell
231# define fseek PerlIO_seek
232# define fgetpos PerlIO_getpos
233# define fsetpos PerlIO_setpos
234# define frewind PerlIO_rewind
235# define tmpfile PerlIO_tmpfile
236# define access PerlLIO_access
237# define chmod PerlLIO_chmod
238# define chsize PerlLIO_chsize
239# define close PerlLIO_close
240# define dup PerlLIO_dup
241# define dup2 PerlLIO_dup2
242# define flock PerlLIO_flock
243# define fstat PerlLIO_fstat
244# define ioctl PerlLIO_ioctl
245# define isatty PerlLIO_isatty
246# define lseek PerlLIO_lseek
247# define lstat PerlLIO_lstat
248# define mktemp PerlLIO_mktemp
249# define open PerlLIO_open
250# define read PerlLIO_read
251# define rename PerlLIO_rename
252# define setmode PerlLIO_setmode
253# define stat PerlLIO_stat
254# define tmpnam PerlLIO_tmpnam
255# define umask PerlLIO_umask
256# define unlink PerlLIO_unlink
257# define utime PerlLIO_utime
258# define write PerlLIO_write
259# define malloc PerlMem_malloc
260# define realloc PerlMem_realloc
261# define free PerlMem_free
262# define abort PerlProc_abort
263# define exit PerlProc_exit
264# define _exit PerlProc__exit
265# define execl PerlProc_execl
266# define execv PerlProc_execv
267# define execvp PerlProc_execvp
268# define getuid PerlProc_getuid
269# define geteuid PerlProc_geteuid
270# define getgid PerlProc_getgid
271# define getegid PerlProc_getegid
272# define getlogin PerlProc_getlogin
273# define kill PerlProc_kill
274# define killpg PerlProc_killpg
275# define pause PerlProc_pause
276# define popen PerlProc_popen
277# define pclose PerlProc_pclose
278# define pipe PerlProc_pipe
279# define setuid PerlProc_setuid
280# define setgid PerlProc_setgid
281# define sleep PerlProc_sleep
282# define times PerlProc_times
283# define wait PerlProc_wait
284# define setjmp PerlProc_setjmp
285# define longjmp PerlProc_longjmp
286# define signal PerlProc_signal
287# define htonl PerlSock_htonl
288# define htons PerlSock_htons
289# define ntohl PerlSock_ntohl
290# define ntohs PerlSock_ntohs
291# define accept PerlSock_accept
292# define bind PerlSock_bind
293# define connect PerlSock_connect
294# define endhostent PerlSock_endhostent
295# define endnetent PerlSock_endnetent
296# define endprotoent PerlSock_endprotoent
297# define endservent PerlSock_endservent
298# define gethostbyaddr PerlSock_gethostbyaddr
299# define gethostbyname PerlSock_gethostbyname
300# define gethostent PerlSock_gethostent
301# define gethostname PerlSock_gethostname
302# define getnetbyaddr PerlSock_getnetbyaddr
303# define getnetbyname PerlSock_getnetbyname
304# define getnetent PerlSock_getnetent
305# define getpeername PerlSock_getpeername
306# define getprotobyname PerlSock_getprotobyname
307# define getprotobynumber PerlSock_getprotobynumber
308# define getprotoent PerlSock_getprotoent
309# define getservbyname PerlSock_getservbyname
310# define getservbyport PerlSock_getservbyport
311# define getservent PerlSock_getservent
312# define getsockname PerlSock_getsockname
313# define getsockopt PerlSock_getsockopt
314# define inet_addr PerlSock_inet_addr
315# define inet_ntoa PerlSock_inet_ntoa
316# define listen PerlSock_listen
317# define recv PerlSock_recv
318# define recvfrom PerlSock_recvfrom
319# define select PerlSock_select
320# define send PerlSock_send
321# define sendto PerlSock_sendto
322# define sethostent PerlSock_sethostent
323# define setnetent PerlSock_setnetent
324# define setprotoent PerlSock_setprotoent
325# define setservent PerlSock_setservent
326# define setsockopt PerlSock_setsockopt
327# define shutdown PerlSock_shutdown
328# define socket PerlSock_socket
329# define socketpair PerlSock_socketpair
330
331# ifdef WIN32
332# include "XSlock.h"
333# endif /* WIN32 */
334# endif /* NO_XSLOCKS */
e3b8966e 335#else
c6af7a1a
GS
336# ifdef PERL_CAPI
337# include "perlCAPI.h"
338# endif
565764a8 339#endif /* PERL_OBJECT */