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(pTHXo_ CV* cv)
66 # define XS(name) void name(pTHXo_ 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 (*) (pTHXo_ 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 an 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
252 #if defined(PERL_IMPLICIT_CONTEXT) && !defined(PERL_NO_GET_CONTEXT) && !defined(PERL_CORE)
255 # define aTHX PERL_GET_THX
259 #if (defined(PERL_CAPI) || defined(PERL_IMPLICIT_SYS)) && !defined(PERL_CORE)
261 # if defined (NETWARE) && defined (USE_STDIO)
262 # define times PerlProc_times
263 # define setuid PerlProc_setuid
264 # define setgid PerlProc_setgid
265 # define getpid PerlProc_getpid
266 # define pause PerlProc_pause
267 # define exit PerlProc_exit
268 # define _exit PerlProc__exit
285 //Following symbols were giving redefinition errors while building extensions - sgp 17th Oct 2000
295 # undef gethostbyaddr
296 # undef gethostbyname
301 # undef getprotobyname
302 # undef getprotobynumber
304 # undef getservbyname
305 # undef getservbyport
314 # define mkdir PerlDir_mkdir
315 # define chdir PerlDir_chdir
316 # define rmdir PerlDir_rmdir
317 # define closedir PerlDir_close
318 # define opendir PerlDir_open
319 # define readdir PerlDir_read
320 # define rewinddir PerlDir_rewind
321 # define seekdir PerlDir_seek
322 # define telldir PerlDir_tell
323 # define putenv PerlEnv_putenv
324 # define getenv PerlEnv_getenv
325 # define uname PerlEnv_uname
326 # define stdin PerlIO_stdin()
327 # define stdout PerlIO_stdout()
328 # define stderr PerlIO_stderr()
329 # define fopen PerlIO_open
330 # define fclose PerlIO_close
331 # define feof PerlIO_eof
332 # define ferror PerlIO_error
333 # define fclearerr PerlIO_clearerr
334 # define getc PerlIO_getc
335 # define fputc(c, f) PerlIO_putc(f,c)
336 # define fputs(s, f) PerlIO_puts(f,s)
337 # define fflush PerlIO_flush
338 # define ungetc(c, f) PerlIO_ungetc((f),(c))
339 # define fileno PerlIO_fileno
340 # define fdopen PerlIO_fdopen
341 # define freopen PerlIO_reopen
342 # define fread(b,s,c,f) PerlIO_read((f),(b),(s*c))
343 # define fwrite(b,s,c,f) PerlIO_write((f),(b),(s*c))
344 # define setbuf PerlIO_setbuf
345 # define setvbuf PerlIO_setvbuf
346 # define setlinebuf PerlIO_setlinebuf
347 # define stdoutf PerlIO_stdoutf
348 # define vfprintf PerlIO_vprintf
349 # define ftell PerlIO_tell
350 # define fseek PerlIO_seek
351 # define fgetpos PerlIO_getpos
352 # define fsetpos PerlIO_setpos
353 # define frewind PerlIO_rewind
354 # define tmpfile PerlIO_tmpfile
355 # define access PerlLIO_access
356 # define chmod PerlLIO_chmod
357 # define chsize PerlLIO_chsize
358 # define close PerlLIO_close
359 # define dup PerlLIO_dup
360 # define dup2 PerlLIO_dup2
361 # define flock PerlLIO_flock
362 # define fstat PerlLIO_fstat
363 # define ioctl PerlLIO_ioctl
364 # define isatty PerlLIO_isatty
365 # define link PerlLIO_link
366 # define lseek PerlLIO_lseek
367 # define lstat PerlLIO_lstat
368 # define mktemp PerlLIO_mktemp
369 # define open PerlLIO_open
370 # define read PerlLIO_read
371 # define rename PerlLIO_rename
372 # define setmode PerlLIO_setmode
373 # define stat(buf,sb) PerlLIO_stat(buf,sb)
374 # define tmpnam PerlLIO_tmpnam
375 # define umask PerlLIO_umask
376 # define unlink PerlLIO_unlink
377 # define utime PerlLIO_utime
378 # define write PerlLIO_write
379 # define malloc PerlMem_malloc
380 # define realloc PerlMem_realloc
381 # define free PerlMem_free
382 # define abort PerlProc_abort
383 # define exit PerlProc_exit
384 # define _exit PerlProc__exit
385 # define execl PerlProc_execl
386 # define execv PerlProc_execv
387 # define execvp PerlProc_execvp
388 # define getuid PerlProc_getuid
389 # define geteuid PerlProc_geteuid
390 # define getgid PerlProc_getgid
391 # define getegid PerlProc_getegid
392 # define getlogin PerlProc_getlogin
393 # define kill PerlProc_kill
394 # define killpg PerlProc_killpg
395 # define pause PerlProc_pause
396 # define popen PerlProc_popen
397 # define pclose PerlProc_pclose
398 # define pipe PerlProc_pipe
399 # define setuid PerlProc_setuid
400 # define setgid PerlProc_setgid
401 # define sleep PerlProc_sleep
402 # define times PerlProc_times
403 # define wait PerlProc_wait
404 # define setjmp PerlProc_setjmp
405 # define longjmp PerlProc_longjmp
406 # define signal PerlProc_signal
407 # define getpid PerlProc_getpid
408 # define htonl PerlSock_htonl
409 # define htons PerlSock_htons
410 # define ntohl PerlSock_ntohl
411 # define ntohs PerlSock_ntohs
412 # define accept PerlSock_accept
413 # define bind PerlSock_bind
414 # define connect PerlSock_connect
415 # define endhostent PerlSock_endhostent
416 # define endnetent PerlSock_endnetent
417 # define endprotoent PerlSock_endprotoent
418 # define endservent PerlSock_endservent
419 # define gethostbyaddr PerlSock_gethostbyaddr
420 # define gethostbyname PerlSock_gethostbyname
421 # define gethostent PerlSock_gethostent
422 # define gethostname PerlSock_gethostname
423 # define getnetbyaddr PerlSock_getnetbyaddr
424 # define getnetbyname PerlSock_getnetbyname
425 # define getnetent PerlSock_getnetent
426 # define getpeername PerlSock_getpeername
427 # define getprotobyname PerlSock_getprotobyname
428 # define getprotobynumber PerlSock_getprotobynumber
429 # define getprotoent PerlSock_getprotoent
430 # define getservbyname PerlSock_getservbyname
431 # define getservbyport PerlSock_getservbyport
432 # define getservent PerlSock_getservent
433 # define getsockname PerlSock_getsockname
434 # define getsockopt PerlSock_getsockopt
435 # define inet_addr PerlSock_inet_addr
436 # define inet_ntoa PerlSock_inet_ntoa
437 # define listen PerlSock_listen
438 # define recv PerlSock_recv
439 # define recvfrom PerlSock_recvfrom
440 # define select PerlSock_select
441 # define send PerlSock_send
442 # define sendto PerlSock_sendto
443 # define sethostent PerlSock_sethostent
444 # define setnetent PerlSock_setnetent
445 # define setprotoent PerlSock_setprotoent
446 # define setservent PerlSock_setservent
447 # define setsockopt PerlSock_setsockopt
448 # define shutdown PerlSock_shutdown
449 # define socket PerlSock_socket
450 # define socketpair PerlSock_socketpair
451 # endif /* NETWARE && USE_STDIO */
452 # endif /* NO_XSLOCKS */
453 #endif /* PERL_CAPI */
455 #endif /* _INC_PERL_XSUB_H */ /* include guard */