1 #ifndef _INC_PERL_XSUB_H
2 #define _INC_PERL_XSUB_H 1
4 /* first, some documentation for xsubpp-generated items */
7 =for apidoc Amn|char*|CLASS
8 Variable which is setup by C<xsubpp> to indicate the
9 class name for a C++ XS constructor. This is always a C<char*>. See C<THIS>.
11 =for apidoc Amn|(whatever)|RETVAL
12 Variable which is setup by C<xsubpp> to hold the return value for an
13 XSUB. This is always the proper type for the XSUB. See
14 L<perlxs/"The RETVAL Variable">.
16 =for apidoc Amn|(whatever)|THIS
17 Variable which is setup by C<xsubpp> to designate the object in a C++
18 XSUB. This is always the proper type for the C++ object. See C<CLASS> and
19 L<perlxs/"Using XS With C++">.
21 =for apidoc Amn|I32|ax
22 Variable which is setup by C<xsubpp> to indicate the stack base offset,
23 used by the C<ST>, C<XSprePUSH> and C<XSRETURN> macros. The C<dMARK> macro
24 must be called prior to setup the C<MARK> variable.
26 =for apidoc Amn|I32|items
27 Variable which is setup by C<xsubpp> to indicate the number of
28 items on the stack. See L<perlxs/"Variable-length Parameter Lists">.
30 =for apidoc Amn|I32|ix
31 Variable which is setup by C<xsubpp> to indicate which of an
32 XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">.
34 =for apidoc Am|SV*|ST|int ix
35 Used to access elements on the XSUB's stack.
38 Macro to declare an XSUB and its C parameter list. This is handled by
42 Sets up the C<ax> variable.
43 This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
45 =for apidoc Ams||dITEMS
46 Sets up the C<items> variable.
47 This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
49 =for apidoc Ams||dXSARGS
50 Sets up stack and mark pointers for an XSUB, calling dSP and dMARK.
51 Sets up the C<ax> and C<items> variables by calling C<dAX> and C<dITEMS>.
52 This is usually handled automatically by C<xsubpp>.
54 =for apidoc Ams||dXSI32
55 Sets up the C<ix> variable for an XSUB which has aliases. This is usually
56 handled automatically by C<xsubpp>.
61 #define ST(off) PL_stack_base[ax + (off)]
63 #if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
64 # define XS(name) __declspec(dllexport) void name(pTHX_ CV* cv)
66 # define XS(name) void name(pTHX_ CV* cv)
69 #define dAX I32 ax = MARK - PL_stack_base + 1
71 #define dITEMS I32 items = SP - MARK
77 #define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
78 ? PAD_SV(PL_op->op_targ) : sv_newmortal())
80 /* Should be used before final PUSHi etc. if not in PPCODE section. */
81 #define XSprePUSH (sp = PL_stack_base + ax - 1)
83 #define XSANY CvXSUBANY(cv)
85 #define dXSI32 I32 ix = XSANY.any_i32
88 # define XSINTERFACE_CVT(ret,name) ret (*name)(...)
90 # define XSINTERFACE_CVT(ret,name) ret (*name)()
92 #define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION)
93 #define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,))(f))
94 #define XSINTERFACE_FUNC_SET(cv,f) \
95 CvXSUBANY(cv).any_dptr = (void (*) (pTHX_ void*))(f)
97 /* Simple macros to put new mortal values onto the stack. */
98 /* Typically used to return values from XS functions. */
101 =for apidoc Am|void|XST_mIV|int pos|IV iv
102 Place an integer into the specified position C<pos> on the stack. The
103 value is stored in a new mortal SV.
105 =for apidoc Am|void|XST_mNV|int pos|NV nv
106 Place a double into the specified position C<pos> on the stack. The value
107 is stored in a new mortal SV.
109 =for apidoc Am|void|XST_mPV|int pos|char* str
110 Place a copy of a string into the specified position C<pos> on the stack.
111 The value is stored in a new mortal SV.
113 =for apidoc Am|void|XST_mNO|int pos
114 Place C<&PL_sv_no> into the specified position C<pos> on the
117 =for apidoc Am|void|XST_mYES|int pos
118 Place C<&PL_sv_yes> into the specified position C<pos> on the
121 =for apidoc Am|void|XST_mUNDEF|int pos
122 Place C<&PL_sv_undef> into the specified position C<pos> on the
125 =for apidoc Am|void|XSRETURN|int nitems
126 Return from XSUB, indicating number of items on the stack. This is usually
127 handled by C<xsubpp>.
129 =for apidoc Am|void|XSRETURN_IV|IV iv
130 Return an integer from an XSUB immediately. Uses C<XST_mIV>.
132 =for apidoc Am|void|XSRETURN_NV|NV nv
133 Return a double from an XSUB immediately. Uses C<XST_mNV>.
135 =for apidoc Am|void|XSRETURN_PV|char* str
136 Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
138 =for apidoc Ams||XSRETURN_NO
139 Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
141 =for apidoc Ams||XSRETURN_YES
142 Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
144 =for apidoc Ams||XSRETURN_UNDEF
145 Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
147 =for apidoc Ams||XSRETURN_EMPTY
148 Return an empty list from an XSUB immediately.
150 =for apidoc AmU||newXSproto
151 Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to
154 =for apidoc AmU||XS_VERSION
155 The version identifier for an XS module. This is usually
156 handled automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>.
158 =for apidoc Ams||XS_VERSION_BOOTCHECK
159 Macro to verify that a PM module's $VERSION variable matches the XS
160 module's C<XS_VERSION> variable. This is usually handled automatically by
161 C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.
166 #define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )
167 #define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )
168 #define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))
169 #define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n)))
170 #define XST_mNO(i) (ST(i) = &PL_sv_no )
171 #define XST_mYES(i) (ST(i) = &PL_sv_yes )
172 #define XST_mUNDEF(i) (ST(i) = &PL_sv_undef)
174 #define XSRETURN(off) \
176 PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
180 #define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END
181 #define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END
182 #define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END
183 #define XSRETURN_PVN(v,n) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END
184 #define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END
185 #define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END
186 #define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END
187 #define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END
189 #define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
192 # define XS_VERSION_BOOTCHECK \
194 SV *tmpsv; STRLEN n_a; \
195 char *vn = Nullch, *module = SvPV(ST(0),n_a); \
196 if (items >= 2) /* version supplied as bootstrap arg */ \
199 /* XXX GV_ADDWARN */ \
200 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
201 vn = "XS_VERSION"), FALSE); \
202 if (!tmpsv || !SvOK(tmpsv)) \
203 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
204 vn = "VERSION"), FALSE); \
206 if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \
207 Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %"SVf,\
208 module, XS_VERSION, \
209 vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
210 vn ? vn : "bootstrap parameter", tmpsv); \
213 # define XS_VERSION_BOOTCHECK
216 #if 1 /* for compatibility */
217 # define VTBL_sv &PL_vtbl_sv
218 # define VTBL_env &PL_vtbl_env
219 # define VTBL_envelem &PL_vtbl_envelem
220 # define VTBL_sig &PL_vtbl_sig
221 # define VTBL_sigelem &PL_vtbl_sigelem
222 # define VTBL_pack &PL_vtbl_pack
223 # define VTBL_packelem &PL_vtbl_packelem
224 # define VTBL_dbline &PL_vtbl_dbline
225 # define VTBL_isa &PL_vtbl_isa
226 # define VTBL_isaelem &PL_vtbl_isaelem
227 # define VTBL_arylen &PL_vtbl_arylen
228 # define VTBL_glob &PL_vtbl_glob
229 # define VTBL_mglob &PL_vtbl_mglob
230 # define VTBL_nkeys &PL_vtbl_nkeys
231 # define VTBL_taint &PL_vtbl_taint
232 # define VTBL_substr &PL_vtbl_substr
233 # define VTBL_vec &PL_vtbl_vec
234 # define VTBL_pos &PL_vtbl_pos
235 # define VTBL_bm &PL_vtbl_bm
236 # define VTBL_fm &PL_vtbl_fm
237 # define VTBL_uvar &PL_vtbl_uvar
238 # define VTBL_defelem &PL_vtbl_defelem
239 # define VTBL_regexp &PL_vtbl_regexp
240 # define VTBL_regdata &PL_vtbl_regdata
241 # define VTBL_regdatum &PL_vtbl_regdatum
242 # ifdef USE_LOCALE_COLLATE
243 # define VTBL_collxfrm &PL_vtbl_collxfrm
245 # define VTBL_amagic &PL_vtbl_amagic
246 # define VTBL_amagicelem &PL_vtbl_amagicelem
251 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE)
254 # define aTHX PERL_GET_THX
258 #if defined(PERL_IMPLICIT_SYS) && !defined(PERL_CORE)
260 # if defined (NETWARE) && defined (USE_STDIO)
261 # define times PerlProc_times
262 # define setuid PerlProc_setuid
263 # define setgid PerlProc_setgid
264 # define getpid PerlProc_getpid
265 # define pause PerlProc_pause
266 # define exit PerlProc_exit
267 # define _exit PerlProc__exit
284 //Following symbols were giving redefinition errors while building extensions - sgp 17th Oct 2000
294 # undef gethostbyaddr
295 # undef gethostbyname
300 # undef getprotobyname
301 # undef getprotobynumber
303 # undef getservbyname
304 # undef getservbyport
313 # define mkdir PerlDir_mkdir
314 # define chdir PerlDir_chdir
315 # define rmdir PerlDir_rmdir
316 # define closedir PerlDir_close
317 # define opendir PerlDir_open
318 # define readdir PerlDir_read
319 # define rewinddir PerlDir_rewind
320 # define seekdir PerlDir_seek
321 # define telldir PerlDir_tell
322 # define putenv PerlEnv_putenv
323 # define getenv PerlEnv_getenv
324 # define uname PerlEnv_uname
325 # define stdin PerlIO_stdin()
326 # define stdout PerlIO_stdout()
327 # define stderr PerlIO_stderr()
328 # define fopen PerlIO_open
329 # define fclose PerlIO_close
330 # define feof PerlIO_eof
331 # define ferror PerlIO_error
332 # define fclearerr PerlIO_clearerr
333 # define getc PerlIO_getc
334 # define fputc(c, f) PerlIO_putc(f,c)
335 # define fputs(s, f) PerlIO_puts(f,s)
336 # define fflush PerlIO_flush
337 # define ungetc(c, f) PerlIO_ungetc((f),(c))
338 # define fileno PerlIO_fileno
339 # define fdopen PerlIO_fdopen
340 # define freopen PerlIO_reopen
341 # define fread(b,s,c,f) PerlIO_read((f),(b),(s*c))
342 # define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c))
343 # define setbuf PerlIO_setbuf
344 # define setvbuf PerlIO_setvbuf
345 # define setlinebuf PerlIO_setlinebuf
346 # define stdoutf PerlIO_stdoutf
347 # define vfprintf PerlIO_vprintf
348 # define ftell PerlIO_tell
349 # define fseek PerlIO_seek
350 # define fgetpos PerlIO_getpos
351 # define fsetpos PerlIO_setpos
352 # define frewind PerlIO_rewind
353 # define tmpfile PerlIO_tmpfile
354 # define access PerlLIO_access
355 # define chmod PerlLIO_chmod
356 # define chsize PerlLIO_chsize
357 # define close PerlLIO_close
358 # define dup PerlLIO_dup
359 # define dup2 PerlLIO_dup2
360 # define flock PerlLIO_flock
361 # define fstat PerlLIO_fstat
362 # define ioctl PerlLIO_ioctl
363 # define isatty PerlLIO_isatty
364 # define link PerlLIO_link
365 # define lseek PerlLIO_lseek
366 # define lstat PerlLIO_lstat
367 # define mktemp PerlLIO_mktemp
368 # define open PerlLIO_open
369 # define read PerlLIO_read
370 # define rename PerlLIO_rename
371 # define setmode PerlLIO_setmode
372 # define stat(buf,sb) PerlLIO_stat(buf,sb)
373 # define tmpnam PerlLIO_tmpnam
374 # define umask PerlLIO_umask
375 # define unlink PerlLIO_unlink
376 # define utime PerlLIO_utime
377 # define write PerlLIO_write
378 # define malloc PerlMem_malloc
379 # define realloc PerlMem_realloc
380 # define free PerlMem_free
381 # define abort PerlProc_abort
382 # define exit PerlProc_exit
383 # define _exit PerlProc__exit
384 # define execl PerlProc_execl
385 # define execv PerlProc_execv
386 # define execvp PerlProc_execvp
387 # define getuid PerlProc_getuid
388 # define geteuid PerlProc_geteuid
389 # define getgid PerlProc_getgid
390 # define getegid PerlProc_getegid
391 # define getlogin PerlProc_getlogin
392 # define kill PerlProc_kill
393 # define killpg PerlProc_killpg
394 # define pause PerlProc_pause
395 # define popen PerlProc_popen
396 # define pclose PerlProc_pclose
397 # define pipe PerlProc_pipe
398 # define setuid PerlProc_setuid
399 # define setgid PerlProc_setgid
400 # define sleep PerlProc_sleep
401 # define times PerlProc_times
402 # define wait PerlProc_wait
403 # define setjmp PerlProc_setjmp
404 # define longjmp PerlProc_longjmp
405 # define signal PerlProc_signal
406 # define getpid PerlProc_getpid
407 # define htonl PerlSock_htonl
408 # define htons PerlSock_htons
409 # define ntohl PerlSock_ntohl
410 # define ntohs PerlSock_ntohs
411 # define accept PerlSock_accept
412 # define bind PerlSock_bind
413 # define connect PerlSock_connect
414 # define endhostent PerlSock_endhostent
415 # define endnetent PerlSock_endnetent
416 # define endprotoent PerlSock_endprotoent
417 # define endservent PerlSock_endservent
418 # define gethostbyaddr PerlSock_gethostbyaddr
419 # define gethostbyname PerlSock_gethostbyname
420 # define gethostent PerlSock_gethostent
421 # define gethostname PerlSock_gethostname
422 # define getnetbyaddr PerlSock_getnetbyaddr
423 # define getnetbyname PerlSock_getnetbyname
424 # define getnetent PerlSock_getnetent
425 # define getpeername PerlSock_getpeername
426 # define getprotobyname PerlSock_getprotobyname
427 # define getprotobynumber PerlSock_getprotobynumber
428 # define getprotoent PerlSock_getprotoent
429 # define getservbyname PerlSock_getservbyname
430 # define getservbyport PerlSock_getservbyport
431 # define getservent PerlSock_getservent
432 # define getsockname PerlSock_getsockname
433 # define getsockopt PerlSock_getsockopt
434 # define inet_addr PerlSock_inet_addr
435 # define inet_ntoa PerlSock_inet_ntoa
436 # define listen PerlSock_listen
437 # define recv PerlSock_recv
438 # define recvfrom PerlSock_recvfrom
439 # define select PerlSock_select
440 # define send PerlSock_send
441 # define sendto PerlSock_sendto
442 # define sethostent PerlSock_sethostent
443 # define setnetent PerlSock_setnetent
444 # define setprotoent PerlSock_setprotoent
445 # define setservent PerlSock_setservent
446 # define setsockopt PerlSock_setsockopt
447 # define shutdown PerlSock_shutdown
448 # define socket PerlSock_socket
449 # define socketpair PerlSock_socketpair
450 # endif /* NETWARE && USE_STDIO */
451 # endif /* NO_XSLOCKS */
452 #endif /* PERL_IMPLICIT_SYS && !PERL_CORE */
454 #endif /* _INC_PERL_XSUB_H */ /* include guard */