1 #ifndef _INC_PERL_XSUB_H
2 #define _INC_PERL_XSUB_H 1
4 #define ST(off) PL_stack_base[ax + (off)]
6 #if defined(CYGWIN) && defined(USE_DYNAMIC_LOADING)
7 # define XS(name) __declspec(dllexport) void name(pTHXo_ CV* cv)
9 # define XS(name) void name(pTHXo_ CV* cv)
14 I32 ax = mark - PL_stack_base + 1; \
17 #define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
18 ? PAD_SV(PL_op->op_targ) : sv_newmortal())
20 #define XSANY CvXSUBANY(cv)
22 #define dXSI32 I32 ix = XSANY.any_i32
25 # define XSINTERFACE_CVT(ret,name) ret (*name)(...)
27 # define XSINTERFACE_CVT(ret,name) ret (*name)()
29 #define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION)
30 #define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,cv))(f))
31 #define XSINTERFACE_FUNC_SET(cv,f) \
32 CvXSUBANY(cv).any_dptr = (void (*) (pTHXo_ void*))(f)
34 #define XSRETURN(off) \
36 PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
40 /* Simple macros to put new mortal values onto the stack. */
41 /* Typically used to return values from XS functions. */
42 #define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )
43 #define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )
44 #define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))
45 #define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n)))
46 #define XST_mNO(i) (ST(i) = &PL_sv_no )
47 #define XST_mYES(i) (ST(i) = &PL_sv_yes )
48 #define XST_mUNDEF(i) (ST(i) = &PL_sv_undef)
50 #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END
51 #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END
52 #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END
53 #define XSRETURN_PVN(v) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END
54 #define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END
55 #define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END
56 #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
57 #define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END
59 #define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
62 # define XS_VERSION_BOOTCHECK \
64 SV *tmpsv; STRLEN n_a; \
65 char *vn = Nullch, *module = SvPV(ST(0),n_a); \
66 if (items >= 2) /* version supplied as bootstrap arg */ \
69 /* XXX GV_ADDWARN */ \
70 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
71 vn = "XS_VERSION"), FALSE); \
72 if (!tmpsv || !SvOK(tmpsv)) \
73 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
74 vn = "VERSION"), FALSE); \
76 if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \
77 Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %_", \
79 vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
80 vn ? vn : "bootstrap parameter", tmpsv); \
83 # define XS_VERSION_BOOTCHECK
86 #if 1 /* for compatibility */
87 # define VTBL_sv &PL_vtbl_sv
88 # define VTBL_env &PL_vtbl_env
89 # define VTBL_envelem &PL_vtbl_envelem
90 # define VTBL_sig &PL_vtbl_sig
91 # define VTBL_sigelem &PL_vtbl_sigelem
92 # define VTBL_pack &PL_vtbl_pack
93 # define VTBL_packelem &PL_vtbl_packelem
94 # define VTBL_dbline &PL_vtbl_dbline
95 # define VTBL_isa &PL_vtbl_isa
96 # define VTBL_isaelem &PL_vtbl_isaelem
97 # define VTBL_arylen &PL_vtbl_arylen
98 # define VTBL_glob &PL_vtbl_glob
99 # define VTBL_mglob &PL_vtbl_mglob
100 # define VTBL_nkeys &PL_vtbl_nkeys
101 # define VTBL_taint &PL_vtbl_taint
102 # define VTBL_substr &PL_vtbl_substr
103 # define VTBL_vec &PL_vtbl_vec
104 # define VTBL_pos &PL_vtbl_pos
105 # define VTBL_bm &PL_vtbl_bm
106 # define VTBL_fm &PL_vtbl_fm
107 # define VTBL_uvar &PL_vtbl_uvar
108 # define VTBL_defelem &PL_vtbl_defelem
109 # define VTBL_regexp &PL_vtbl_regexp
110 # define VTBL_regdata &PL_vtbl_regdata
111 # define VTBL_regdatum &PL_vtbl_regdatum
112 # ifdef USE_LOCALE_COLLATE
113 # define VTBL_collxfrm &PL_vtbl_collxfrm
115 # define VTBL_amagic &PL_vtbl_amagic
116 # define VTBL_amagicelem &PL_vtbl_amagicelem
119 #if defined(PERL_OBJECT) || defined(PERL_CAPI)
120 # include "perlapi.h"
121 # include "objXSUB.h"
122 #endif /* PERL_OBJECT || PERL_CAPI */
124 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE)
127 # define aTHX PERL_GET_THX
131 #if (defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)) && !defined(PERL_CORE)
148 # define mkdir PerlDir_mkdir
149 # define chdir PerlDir_chdir
150 # define rmdir PerlDir_rmdir
151 # define closedir PerlDir_close
152 # define opendir PerlDir_open
153 # define readdir PerlDir_read
154 # define rewinddir PerlDir_rewind
155 # define seekdir PerlDir_seek
156 # define telldir PerlDir_tell
157 # define putenv PerlEnv_putenv
158 # define getenv PerlEnv_getenv
159 # define uname PerlEnv_uname
160 # define stdin PerlIO_stdin()
161 # define stdout PerlIO_stdout()
162 # define stderr PerlIO_stderr()
163 # define fopen PerlIO_open
164 # define fclose PerlIO_close
165 # define feof PerlIO_eof
166 # define ferror PerlIO_error
167 # define fclearerr PerlIO_clearerr
168 # define getc PerlIO_getc
169 # define fputc(c, f) PerlIO_putc(f,c)
170 # define fputs(s, f) PerlIO_puts(f,s)
171 # define fflush PerlIO_flush
172 # define ungetc(c, f) PerlIO_ungetc((f),(c))
173 # define fileno PerlIO_fileno
174 # define fdopen PerlIO_fdopen
175 # define freopen PerlIO_reopen
176 # define fread(b,s,c,f) PerlIO_read((f),(b),(s*c))
177 # define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c))
178 # define setbuf PerlIO_setbuf
179 # define setvbuf PerlIO_setvbuf
180 # define setlinebuf PerlIO_setlinebuf
181 # define stdoutf PerlIO_stdoutf
182 # define vfprintf PerlIO_vprintf
183 # define ftell PerlIO_tell
184 # define fseek PerlIO_seek
185 # define fgetpos PerlIO_getpos
186 # define fsetpos PerlIO_setpos
187 # define frewind PerlIO_rewind
188 # define tmpfile PerlIO_tmpfile
189 # define access PerlLIO_access
190 # define chmod PerlLIO_chmod
191 # define chsize PerlLIO_chsize
192 # define close PerlLIO_close
193 # define dup PerlLIO_dup
194 # define dup2 PerlLIO_dup2
195 # define flock PerlLIO_flock
196 # define fstat PerlLIO_fstat
197 # define ioctl PerlLIO_ioctl
198 # define isatty PerlLIO_isatty
199 # define link PerlLIO_link
200 # define lseek PerlLIO_lseek
201 # define lstat PerlLIO_lstat
202 # define mktemp PerlLIO_mktemp
203 # define open PerlLIO_open
204 # define read PerlLIO_read
205 # define rename PerlLIO_rename
206 # define setmode PerlLIO_setmode
207 # define stat(buf,sb) PerlLIO_stat(buf,sb)
208 # define tmpnam PerlLIO_tmpnam
209 # define umask PerlLIO_umask
210 # define unlink PerlLIO_unlink
211 # define utime PerlLIO_utime
212 # define write PerlLIO_write
213 # define malloc PerlMem_malloc
214 # define realloc PerlMem_realloc
215 # define free PerlMem_free
216 # define abort PerlProc_abort
217 # define exit PerlProc_exit
218 # define _exit PerlProc__exit
219 # define execl PerlProc_execl
220 # define execv PerlProc_execv
221 # define execvp PerlProc_execvp
222 # define getuid PerlProc_getuid
223 # define geteuid PerlProc_geteuid
224 # define getgid PerlProc_getgid
225 # define getegid PerlProc_getegid
226 # define getlogin PerlProc_getlogin
227 # define kill PerlProc_kill
228 # define killpg PerlProc_killpg
229 # define pause PerlProc_pause
230 # define popen PerlProc_popen
231 # define pclose PerlProc_pclose
232 # define pipe PerlProc_pipe
233 # define setuid PerlProc_setuid
234 # define setgid PerlProc_setgid
235 # define sleep PerlProc_sleep
236 # define times PerlProc_times
237 # define wait PerlProc_wait
238 # define setjmp PerlProc_setjmp
239 # define longjmp PerlProc_longjmp
240 # define signal PerlProc_signal
241 # define getpid PerlProc_getpid
242 # define htonl PerlSock_htonl
243 # define htons PerlSock_htons
244 # define ntohl PerlSock_ntohl
245 # define ntohs PerlSock_ntohs
246 # define accept PerlSock_accept
247 # define bind PerlSock_bind
248 # define connect PerlSock_connect
249 # define endhostent PerlSock_endhostent
250 # define endnetent PerlSock_endnetent
251 # define endprotoent PerlSock_endprotoent
252 # define endservent PerlSock_endservent
253 # define gethostbyaddr PerlSock_gethostbyaddr
254 # define gethostbyname PerlSock_gethostbyname
255 # define gethostent PerlSock_gethostent
256 # define gethostname PerlSock_gethostname
257 # define getnetbyaddr PerlSock_getnetbyaddr
258 # define getnetbyname PerlSock_getnetbyname
259 # define getnetent PerlSock_getnetent
260 # define getpeername PerlSock_getpeername
261 # define getprotobyname PerlSock_getprotobyname
262 # define getprotobynumber PerlSock_getprotobynumber
263 # define getprotoent PerlSock_getprotoent
264 # define getservbyname PerlSock_getservbyname
265 # define getservbyport PerlSock_getservbyport
266 # define getservent PerlSock_getservent
267 # define getsockname PerlSock_getsockname
268 # define getsockopt PerlSock_getsockopt
269 # define inet_addr PerlSock_inet_addr
270 # define inet_ntoa PerlSock_inet_ntoa
271 # define listen PerlSock_listen
272 # define recv PerlSock_recv
273 # define recvfrom PerlSock_recvfrom
274 # define select PerlSock_select
275 # define send PerlSock_send
276 # define sendto PerlSock_sendto
277 # define sethostent PerlSock_sethostent
278 # define setnetent PerlSock_setnetent
279 # define setprotoent PerlSock_setprotoent
280 # define setservent PerlSock_setservent
281 # define setsockopt PerlSock_setsockopt
282 # define shutdown PerlSock_shutdown
283 # define socket PerlSock_socket
284 # define socketpair PerlSock_socketpair
285 # endif /* NO_XSLOCKS */
286 #endif /* PERL_CAPI */
288 #endif /* _INC_PERL_XSUB_H */ /* include guard */