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