This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
change#3612 was buggy and failed to build Tk; applied Ilya's
[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) \
51371543 26 CvXSUBANY(cv).any_dptr = (void (*) (pTHXo_ 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
51371543 80#if 1 /* for compatibility */
dc9e4912
GS
81# define VTBL_sv &PL_vtbl_sv
82# define VTBL_env &PL_vtbl_env
83# define VTBL_envelem &PL_vtbl_envelem
84# define VTBL_sig &PL_vtbl_sig
85# define VTBL_sigelem &PL_vtbl_sigelem
86# define VTBL_pack &PL_vtbl_pack
87# define VTBL_packelem &PL_vtbl_packelem
88# define VTBL_dbline &PL_vtbl_dbline
89# define VTBL_isa &PL_vtbl_isa
90# define VTBL_isaelem &PL_vtbl_isaelem
91# define VTBL_arylen &PL_vtbl_arylen
92# define VTBL_glob &PL_vtbl_glob
93# define VTBL_mglob &PL_vtbl_mglob
94# define VTBL_nkeys &PL_vtbl_nkeys
95# define VTBL_taint &PL_vtbl_taint
96# define VTBL_substr &PL_vtbl_substr
97# define VTBL_vec &PL_vtbl_vec
98# define VTBL_pos &PL_vtbl_pos
99# define VTBL_bm &PL_vtbl_bm
100# define VTBL_fm &PL_vtbl_fm
101# define VTBL_uvar &PL_vtbl_uvar
102# define VTBL_defelem &PL_vtbl_defelem
103# define VTBL_regexp &PL_vtbl_regexp
104# define VTBL_regdata &PL_vtbl_regdata
105# define VTBL_regdatum &PL_vtbl_regdatum
106# ifdef USE_LOCALE_COLLATE
107# define VTBL_collxfrm &PL_vtbl_collxfrm
108# endif
9e7bc3e8
JD
109# define VTBL_amagic &PL_vtbl_amagic
110# define VTBL_amagicelem &PL_vtbl_amagicelem
dc9e4912
GS
111#endif
112
76e3520e 113#ifdef PERL_OBJECT
51371543
GS
114
115# include "perlapi.h"
c6af7a1a
GS
116# include "objXSUB.h"
117
0cb96387
GS
118# undef aTHXo
119# define aTHXo pPerl
120# undef aTHXo_
121# define aTHXo_ aTHXo,
122# undef _aTHXo
123# define _aTHXo ,aTHXo
c6af7a1a 124
c6af7a1a 125# ifdef WIN32
0cb96387
GS
126# undef fprintf
127# define fprintf pPerl->fprintf
c6af7a1a
GS
128# endif /* WIN32 */
129
130# ifndef NO_XSLOCKS
131# undef closedir
132# undef opendir
133# undef stdin
134# undef stdout
135# undef stderr
136# undef feof
137# undef ferror
138# undef fgetpos
139# undef ioctl
140# undef getlogin
141# undef setjmp
142# undef getc
143# undef ungetc
144# undef fileno
145
146# define mkdir PerlDir_mkdir
147# define chdir PerlDir_chdir
148# define rmdir PerlDir_rmdir
149# define closedir PerlDir_close
150# define opendir PerlDir_open
151# define readdir PerlDir_read
152# define rewinddir PerlDir_rewind
153# define seekdir PerlDir_seek
154# define telldir PerlDir_tell
155# define putenv PerlEnv_putenv
156# define getenv PerlEnv_getenv
b2af26b1 157# define uname PerlEnv_uname
c6af7a1a
GS
158# define stdin PerlIO_stdin()
159# define stdout PerlIO_stdout()
160# define stderr PerlIO_stderr()
161# define fopen PerlIO_open
162# define fclose PerlIO_close
163# define feof PerlIO_eof
164# define ferror PerlIO_error
165# define fclearerr PerlIO_clearerr
166# define getc PerlIO_getc
167# define fputc(c, f) PerlIO_putc(f,c)
168# define fputs(s, f) PerlIO_puts(f,s)
169# define fflush PerlIO_flush
170# define ungetc(c, f) PerlIO_ungetc((f),(c))
171# define fileno PerlIO_fileno
172# define fdopen PerlIO_fdopen
173# define freopen PerlIO_reopen
174# define fread(b,s,c,f) PerlIO_read((f),(b),(s*c))
175# define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c))
176# define setbuf PerlIO_setbuf
177# define setvbuf PerlIO_setvbuf
178# define setlinebuf PerlIO_setlinebuf
179# define stdoutf PerlIO_stdoutf
180# define vfprintf PerlIO_vprintf
181# define ftell PerlIO_tell
182# define fseek PerlIO_seek
183# define fgetpos PerlIO_getpos
184# define fsetpos PerlIO_setpos
185# define frewind PerlIO_rewind
186# define tmpfile PerlIO_tmpfile
187# define access PerlLIO_access
188# define chmod PerlLIO_chmod
189# define chsize PerlLIO_chsize
190# define close PerlLIO_close
191# define dup PerlLIO_dup
192# define dup2 PerlLIO_dup2
193# define flock PerlLIO_flock
194# define fstat PerlLIO_fstat
195# define ioctl PerlLIO_ioctl
196# define isatty PerlLIO_isatty
197# define lseek PerlLIO_lseek
198# define lstat PerlLIO_lstat
199# define mktemp PerlLIO_mktemp
200# define open PerlLIO_open
201# define read PerlLIO_read
202# define rename PerlLIO_rename
203# define setmode PerlLIO_setmode
204# define stat PerlLIO_stat
205# define tmpnam PerlLIO_tmpnam
206# define umask PerlLIO_umask
207# define unlink PerlLIO_unlink
208# define utime PerlLIO_utime
209# define write PerlLIO_write
210# define malloc PerlMem_malloc
211# define realloc PerlMem_realloc
212# define free PerlMem_free
213# define abort PerlProc_abort
214# define exit PerlProc_exit
215# define _exit PerlProc__exit
216# define execl PerlProc_execl
217# define execv PerlProc_execv
218# define execvp PerlProc_execvp
219# define getuid PerlProc_getuid
220# define geteuid PerlProc_geteuid
221# define getgid PerlProc_getgid
222# define getegid PerlProc_getegid
223# define getlogin PerlProc_getlogin
224# define kill PerlProc_kill
225# define killpg PerlProc_killpg
226# define pause PerlProc_pause
227# define popen PerlProc_popen
228# define pclose PerlProc_pclose
229# define pipe PerlProc_pipe
230# define setuid PerlProc_setuid
231# define setgid PerlProc_setgid
232# define sleep PerlProc_sleep
233# define times PerlProc_times
234# define wait PerlProc_wait
235# define setjmp PerlProc_setjmp
236# define longjmp PerlProc_longjmp
237# define signal PerlProc_signal
238# define htonl PerlSock_htonl
239# define htons PerlSock_htons
240# define ntohl PerlSock_ntohl
241# define ntohs PerlSock_ntohs
242# define accept PerlSock_accept
243# define bind PerlSock_bind
244# define connect PerlSock_connect
245# define endhostent PerlSock_endhostent
246# define endnetent PerlSock_endnetent
247# define endprotoent PerlSock_endprotoent
248# define endservent PerlSock_endservent
249# define gethostbyaddr PerlSock_gethostbyaddr
250# define gethostbyname PerlSock_gethostbyname
251# define gethostent PerlSock_gethostent
252# define gethostname PerlSock_gethostname
253# define getnetbyaddr PerlSock_getnetbyaddr
254# define getnetbyname PerlSock_getnetbyname
255# define getnetent PerlSock_getnetent
256# define getpeername PerlSock_getpeername
257# define getprotobyname PerlSock_getprotobyname
258# define getprotobynumber PerlSock_getprotobynumber
259# define getprotoent PerlSock_getprotoent
260# define getservbyname PerlSock_getservbyname
261# define getservbyport PerlSock_getservbyport
262# define getservent PerlSock_getservent
263# define getsockname PerlSock_getsockname
264# define getsockopt PerlSock_getsockopt
265# define inet_addr PerlSock_inet_addr
266# define inet_ntoa PerlSock_inet_ntoa
267# define listen PerlSock_listen
268# define recv PerlSock_recv
269# define recvfrom PerlSock_recvfrom
270# define select PerlSock_select
271# define send PerlSock_send
272# define sendto PerlSock_sendto
273# define sethostent PerlSock_sethostent
274# define setnetent PerlSock_setnetent
275# define setprotoent PerlSock_setprotoent
276# define setservent PerlSock_setservent
277# define setsockopt PerlSock_setsockopt
278# define shutdown PerlSock_shutdown
279# define socket PerlSock_socket
280# define socketpair PerlSock_socketpair
c6af7a1a
GS
281# ifdef WIN32
282# include "XSlock.h"
51371543 283# endif
c6af7a1a 284# endif /* NO_XSLOCKS */
51371543 285
565764a8 286#endif /* PERL_OBJECT */