$VERSION "a5" doesn't quite work.
[p5sagit/p5-mst-13.2.git] / XSUB.h
CommitLineData
b4ba0ab9 1#ifndef _INC_PERL_XSUB_H
2#define _INC_PERL_XSUB_H 1
3
954c1994 4/* first, some documentation for xsubpp-generated items */
5
6/*
7=for apidoc Amn|char*|CLASS
8Variable which is setup by C<xsubpp> to indicate the
9class name for a C++ XS constructor. This is always a C<char*>. See C<THIS>.
10
11=for apidoc Amn|(whatever)|RETVAL
12Variable which is setup by C<xsubpp> to hold the return value for an
13XSUB. This is always the proper type for the XSUB. See
14L<perlxs/"The RETVAL Variable">.
15
16=for apidoc Amn|(whatever)|THIS
17Variable which is setup by C<xsubpp> to designate the object in a C++
18XSUB. This is always the proper type for the C++ object. See C<CLASS> and
19L<perlxs/"Using XS With C++">.
20
9f2ea798 21=for apidoc Amn|I32|ax
22Variable which is setup by C<xsubpp> to indicate the stack base offset,
23used by the C<ST>, C<XSprePUSH> and C<XSRETURN> macros. The C<dMARK> macro
24must be called prior to setup the C<MARK> variable.
25
954c1994 26=for apidoc Amn|I32|items
27Variable which is setup by C<xsubpp> to indicate the number of
28items on the stack. See L<perlxs/"Variable-length Parameter Lists">.
29
30=for apidoc Amn|I32|ix
31Variable which is setup by C<xsubpp> to indicate which of an
32XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">.
33
34=for apidoc Am|SV*|ST|int ix
35Used to access elements on the XSUB's stack.
36
37=for apidoc AmU||XS
38Macro to declare an XSUB and its C parameter list. This is handled by
39C<xsubpp>.
40
9f2ea798 41=for apidoc Ams||dAX
42Sets up the C<ax> variable.
43This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
44
45=for apidoc Ams||dITEMS
46Sets up the C<items> variable.
47This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.
48
954c1994 49=for apidoc Ams||dXSARGS
9f2ea798 50Sets up stack and mark pointers for an XSUB, calling dSP and dMARK.
51Sets up the C<ax> and C<items> variables by calling C<dAX> and C<dITEMS>.
52This is usually handled automatically by C<xsubpp>.
954c1994 53
54=for apidoc Ams||dXSI32
55Sets up the C<ix> variable for an XSUB which has aliases. This is usually
56handled automatically by C<xsubpp>.
57
58=cut
59*/
60
3280af22 61#define ST(off) PL_stack_base[ax + (off)]
a0d0e21e 62
d308986b 63#if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
acfe0abc 64# define XS(name) __declspec(dllexport) void name(pTHX_ CV* cv)
cea2e8a9 65#else
acfe0abc 66# define XS(name) void name(pTHX_ CV* cv)
a0d0e21e 67#endif
68
349b520e 69#define dAX I32 ax = MARK - PL_stack_base + 1
9f2ea798 70
71#define dITEMS I32 items = SP - MARK
72
a0d0e21e 73#define dXSARGS \
3c78fafa 74 dSP; dMARK; \
9f2ea798 75 dAX; dITEMS
a0d0e21e 76
8a7fc0dc 77#define dXSTARG SV * targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \
78 ? PAD_SV(PL_op->op_targ) : sv_newmortal())
79
b26a54d0 80/* Should be used before final PUSHi etc. if not in PPCODE section. */
81#define XSprePUSH (sp = PL_stack_base + ax - 1)
82
a0d0e21e 83#define XSANY CvXSUBANY(cv)
84
85#define dXSI32 I32 ix = XSANY.any_i32
86
cfc02341 87#ifdef __cplusplus
88# define XSINTERFACE_CVT(ret,name) ret (*name)(...)
89#else
90# define XSINTERFACE_CVT(ret,name) ret (*name)()
91#endif
92#define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION)
2554589c 93#define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT(ret,))(f))
cfc02341 94#define XSINTERFACE_FUNC_SET(cv,f) \
acfe0abc 95 CvXSUBANY(cv).any_dptr = (void (*) (pTHX_ void*))(f)
cfc02341 96
748a9306 97/* Simple macros to put new mortal values onto the stack. */
98/* Typically used to return values from XS functions. */
954c1994 99
100/*
101=for apidoc Am|void|XST_mIV|int pos|IV iv
102Place an integer into the specified position C<pos> on the stack. The
103value is stored in a new mortal SV.
104
105=for apidoc Am|void|XST_mNV|int pos|NV nv
106Place a double into the specified position C<pos> on the stack. The value
107is stored in a new mortal SV.
108
109=for apidoc Am|void|XST_mPV|int pos|char* str
110Place a copy of a string into the specified position C<pos> on the stack.
111The value is stored in a new mortal SV.
112
113=for apidoc Am|void|XST_mNO|int pos
114Place C<&PL_sv_no> into the specified position C<pos> on the
115stack.
116
117=for apidoc Am|void|XST_mYES|int pos
118Place C<&PL_sv_yes> into the specified position C<pos> on the
119stack.
120
121=for apidoc Am|void|XST_mUNDEF|int pos
122Place C<&PL_sv_undef> into the specified position C<pos> on the
123stack.
124
125=for apidoc Am|void|XSRETURN|int nitems
126Return from XSUB, indicating number of items on the stack. This is usually
127handled by C<xsubpp>.
128
129=for apidoc Am|void|XSRETURN_IV|IV iv
130Return an integer from an XSUB immediately. Uses C<XST_mIV>.
131
132=for apidoc Am|void|XSRETURN_NV|NV nv
d1be9408 133Return a double from an XSUB immediately. Uses C<XST_mNV>.
954c1994 134
135=for apidoc Am|void|XSRETURN_PV|char* str
136Return a copy of a string from an XSUB immediately. Uses C<XST_mPV>.
137
138=for apidoc Ams||XSRETURN_NO
139Return C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.
140
141=for apidoc Ams||XSRETURN_YES
142Return C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.
143
144=for apidoc Ams||XSRETURN_UNDEF
145Return C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.
146
147=for apidoc Ams||XSRETURN_EMPTY
148Return an empty list from an XSUB immediately.
149
150=for apidoc AmU||newXSproto
151Used by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes to
152the subs.
153
154=for apidoc AmU||XS_VERSION
155The version identifier for an XS module. This is usually
156handled automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>.
157
158=for apidoc Ams||XS_VERSION_BOOTCHECK
159Macro to verify that a PM module's $VERSION variable matches the XS
160module's C<XS_VERSION> variable. This is usually handled automatically by
161C<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.
162
163=cut
164*/
165
4633a7c4 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)))
79cb57f6 169#define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n)))
3280af22 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)
954c1994 173
174#define XSRETURN(off) \
175 STMT_START { \
176 PL_stack_sp = PL_stack_base + ax + ((off) - 1); \
177 return; \
178 } STMT_END
179
80b92232 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
954c1994 183#define XSRETURN_PVN(v,n) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END
80b92232 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
382b8d97 188
37120919 189#define newXSproto(a,b,c,d) sv_setpv((SV*)newXS(a,b,c), d)
720fb644 190
191#ifdef XS_VERSION
c6af7a1a 192# define XS_VERSION_BOOTCHECK \
774d564b 193 STMT_START { \
2d8e6c8d 194 SV *tmpsv; STRLEN n_a; \
195 char *vn = Nullch, *module = SvPV(ST(0),n_a); \
774d564b 196 if (items >= 2) /* version supplied as bootstrap arg */ \
6b88bc9c 197 tmpsv = ST(1); \
774d564b 198 else { \
46fc3d4c 199 /* XXX GV_ADDWARN */ \
cea2e8a9 200 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
864dbfa3 201 vn = "XS_VERSION"), FALSE); \
6b88bc9c 202 if (!tmpsv || !SvOK(tmpsv)) \
cea2e8a9 203 tmpsv = get_sv(Perl_form(aTHX_ "%s::%s", module, \
864dbfa3 204 vn = "VERSION"), FALSE); \
774d564b 205 } \
2d8e6c8d 206 if (tmpsv && (!SvOK(tmpsv) || strNE(XS_VERSION, SvPV(tmpsv, n_a)))) \
894356b3 207 Perl_croak(aTHX_ "%s object version %s does not match %s%s%s%s %"SVf,\
ae66e5c8 208 module, XS_VERSION, \
209 vn ? "$" : "", vn ? module : "", vn ? "::" : "", \
6b88bc9c 210 vn ? vn : "bootstrap parameter", tmpsv); \
80b92232 211 } STMT_END
720fb644 212#else
c6af7a1a 213# define XS_VERSION_BOOTCHECK
720fb644 214#endif
76e3520e 215
51371543 216#if 1 /* for compatibility */
dc9e4912 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
244# endif
9e7bc3e8 245# define VTBL_amagic &PL_vtbl_amagic
246# define VTBL_amagicelem &PL_vtbl_amagicelem
dc9e4912 247#endif
248
6f4183fe 249#include "perlapi.h"
c6af7a1a 250
e8ee3774 251#if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE)
c5be433b 252# undef aTHX
253# undef aTHX_
54aff467 254# define aTHX PERL_GET_THX
255# define aTHX_ aTHX,
54aff467 256#endif
257
acfe0abc 258#if defined(PERL_IMPLICIT_SYS) && !defined(PERL_CORE)
c6af7a1a 259# ifndef NO_XSLOCKS
2986a63f 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
268# else
c6af7a1a 269# undef closedir
270# undef opendir
271# undef stdin
272# undef stdout
273# undef stderr
274# undef feof
275# undef ferror
276# undef fgetpos
277# undef ioctl
278# undef getlogin
279# undef setjmp
280# undef getc
281# undef ungetc
282# undef fileno
283
2986a63f 284//Following symbols were giving redefinition errors while building extensions - sgp 17th Oct 2000
285#ifdef NETWARE
286# undef readdir
287# undef fstat
288# undef stat
289# undef longjmp
290# undef endhostent
291# undef endnetent
292# undef endprotoent
293# undef endservent
294# undef gethostbyaddr
295# undef gethostbyname
296# undef gethostent
297# undef getnetbyaddr
298# undef getnetbyname
299# undef getnetent
300# undef getprotobyname
301# undef getprotobynumber
302# undef getprotoent
303# undef getservbyname
304# undef getservbyport
305# undef getservent
306# undef inet_ntoa
307# undef sethostent
308# undef setnetent
309# undef setprotoent
310# undef setservent
311#endif /* NETWARE */
312
c6af7a1a 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
b2af26b1 324# define uname PerlEnv_uname
c6af7a1a 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
6b980173 364# define link PerlLIO_link
c6af7a1a 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
4f49e16e 372# define stat(buf,sb) PerlLIO_stat(buf,sb)
c6af7a1a 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
7766f137 406# define getpid PerlProc_getpid
c6af7a1a 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
2986a63f 450# endif /* NETWARE && USE_STDIO */
c6af7a1a 451# endif /* NO_XSLOCKS */
acfe0abc 452#endif /* PERL_IMPLICIT_SYS && !PERL_CORE */
b4ba0ab9 453
cfeeb022 454#endif /* _INC_PERL_XSUB_H */ /* include guard */