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