📄 xsub.h
字号:
/* XSUB.h * * Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, * 2003, 2004, 2005, 2006, 2007 by Larry Wall and others * * You may distribute under the terms of either the GNU General Public * License or the Artistic License, as specified in the README file. * */#ifndef _INC_PERL_XSUB_H#define _INC_PERL_XSUB_H 1/* first, some documentation for xsubpp-generated items *//*=head1 Variables created by C<xsubpp> and C<xsubpp> internal functions=for apidoc Amn|char*|CLASSVariable which is setup by C<xsubpp> to indicate the class name for a C++ XS constructor. This is always a C<char*>. See C<THIS>.=for apidoc Amn|(whatever)|RETVALVariable which is setup by C<xsubpp> to hold the return value for an XSUB. This is always the proper type for the XSUB. See L<perlxs/"The RETVAL Variable">.=for apidoc Amn|(whatever)|THISVariable which is setup by C<xsubpp> to designate the object in a C++ XSUB. This is always the proper type for the C++ object. See C<CLASS> and L<perlxs/"Using XS With C++">.=for apidoc Amn|I32|axVariable which is setup by C<xsubpp> to indicate the stack base offset,used by the C<ST>, C<XSprePUSH> and C<XSRETURN> macros. The C<dMARK> macromust be called prior to setup the C<MARK> variable.=for apidoc Amn|I32|itemsVariable which is setup by C<xsubpp> to indicate the number of items on the stack. See L<perlxs/"Variable-length Parameter Lists">.=for apidoc Amn|I32|ixVariable which is setup by C<xsubpp> to indicate which of an XSUB's aliases was used to invoke it. See L<perlxs/"The ALIAS: Keyword">.=for apidoc Am|SV*|ST|int ixUsed to access elements on the XSUB's stack.=for apidoc AmU||XSMacro to declare an XSUB and its C parameter list. This is handled byC<xsubpp>.=for apidoc Ams||dAXSets up the C<ax> variable.This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.=for apidoc Ams||dAXMARKSets up the C<ax> variable and stack marker variable C<mark>.This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.=for apidoc Ams||dITEMSSets up the C<items> variable.This is usually handled automatically by C<xsubpp> by calling C<dXSARGS>.=for apidoc Ams||dXSARGSSets up stack and mark pointers for an XSUB, calling dSP and dMARK.Sets up the C<ax> and C<items> variables by calling C<dAX> and C<dITEMS>.This is usually handled automatically by C<xsubpp>.=for apidoc Ams||dXSI32Sets up the C<ix> variable for an XSUB which has aliases. This is usuallyhandled automatically by C<xsubpp>.=for apidoc Ams||dUNDERBARSets up the C<padoff_du> variable for an XSUB that wishes to useC<UNDERBAR>.=for apidoc AmU||UNDERBARThe SV* corresponding to the $_ variable. Works even if thereis a lexical $_ in scope.=cut*/#ifndef PERL_UNUSED_ARG# if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */# include <note.h># define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x))# else# define PERL_UNUSED_ARG(x) ((void)x)# endif#endif#ifndef PERL_UNUSED_VAR# define PERL_UNUSED_VAR(x) ((void)x)#endif#define ST(off) PL_stack_base[ax + (off)]/* XSPROTO() is also used by SWIG like this: * * typedef XSPROTO(SwigPerlWrapper); * typedef SwigPerlWrapper *SwigPerlWrapperPtr; * * This code needs to be compilable under both C and C++. * * Don't forget to change the __attribute__unused__ version of XS() * below too if you change XSPROTO() here. */#define XSPROTO(name) void name(pTHX_ CV* cv)#undef XS#if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)# define XS(name) __declspec(dllexport) XSPROTO(name)#endif#if defined(__SYMBIAN32__)# define XS(name) EXPORT_C XSPROTO(name)#endif#ifndef XS# if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)# define XS(name) void name(pTHX_ CV* cv __attribute__unused__)# else# ifdef __cplusplus# define XS(name) extern "C" XSPROTO(name)# else# define XS(name) XSPROTO(name)# endif# endif#endif#define dAX const I32 ax = (I32)(MARK - PL_stack_base + 1)#define dAXMARK \ I32 ax = POPMARK; \ register SV **mark = PL_stack_base + ax++#define dITEMS I32 items = (I32)(SP - MARK)#if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */# define dXSARGS \ NOTE(ARGUNUSED(cv)) \ dSP; dAXMARK; dITEMS#else# define dXSARGS \ dSP; dAXMARK; dITEMS#endif#define dXSTARG SV * const targ = ((PL_op->op_private & OPpENTERSUB_HASTARG) \ ? PAD_SV(PL_op->op_targ) : sv_newmortal())/* Should be used before final PUSHi etc. if not in PPCODE section. */#define XSprePUSH (sp = PL_stack_base + ax - 1)#define XSANY CvXSUBANY(cv)#define dXSI32 I32 ix = XSANY.any_i32#ifdef __cplusplus# define XSINTERFACE_CVT(ret,name) ret (*name)(...)# define XSINTERFACE_CVT_ANON(ret) ret (*)(...)#else# define XSINTERFACE_CVT(ret,name) ret (*name)()# define XSINTERFACE_CVT_ANON(ret) ret (*)()#endif#define dXSFUNCTION(ret) XSINTERFACE_CVT(ret,XSFUNCTION)#define XSINTERFACE_FUNC(ret,cv,f) ((XSINTERFACE_CVT_ANON(ret))(f))#define XSINTERFACE_FUNC_SET(cv,f) \ CvXSUBANY(cv).any_dxptr = (void (*) (pTHX_ void*))(f)#define dUNDERBAR PADOFFSET padoff_du = find_rundefsvoffset()#define UNDERBAR ((padoff_du == NOT_IN_PAD \ || PAD_COMPNAME_FLAGS_isOUR(padoff_du)) \ ? DEFSV : PAD_SVl(padoff_du))/* Simple macros to put new mortal values onto the stack. *//* Typically used to return values from XS functions. *//*=head1 Stack Manipulation Macros=for apidoc Am|void|XST_mIV|int pos|IV ivPlace an integer into the specified position C<pos> on the stack. Thevalue is stored in a new mortal SV.=for apidoc Am|void|XST_mNV|int pos|NV nvPlace a double into the specified position C<pos> on the stack. The valueis stored in a new mortal SV.=for apidoc Am|void|XST_mPV|int pos|char* strPlace a copy of a string into the specified position C<pos> on the stack. The value is stored in a new mortal SV.=for apidoc Am|void|XST_mNO|int posPlace C<&PL_sv_no> into the specified position C<pos> on thestack.=for apidoc Am|void|XST_mYES|int posPlace C<&PL_sv_yes> into the specified position C<pos> on thestack.=for apidoc Am|void|XST_mUNDEF|int posPlace C<&PL_sv_undef> into the specified position C<pos> on thestack.=for apidoc Am|void|XSRETURN|int nitemsReturn from XSUB, indicating number of items on the stack. This is usuallyhandled by C<xsubpp>.=for apidoc Am|void|XSRETURN_IV|IV ivReturn an integer from an XSUB immediately. Uses C<XST_mIV>.=for apidoc Am|void|XSRETURN_UV|IV uvReturn an integer from an XSUB immediately. Uses C<XST_mUV>.=for apidoc Am|void|XSRETURN_NV|NV nvReturn a double from an XSUB immediately. Uses C<XST_mNV>.=for apidoc Am|void|XSRETURN_PV|char* strReturn a copy of a string from an XSUB immediately. Uses C<XST_mPV>.=for apidoc Ams||XSRETURN_NOReturn C<&PL_sv_no> from an XSUB immediately. Uses C<XST_mNO>.=for apidoc Ams||XSRETURN_YESReturn C<&PL_sv_yes> from an XSUB immediately. Uses C<XST_mYES>.=for apidoc Ams||XSRETURN_UNDEFReturn C<&PL_sv_undef> from an XSUB immediately. Uses C<XST_mUNDEF>.=for apidoc Ams||XSRETURN_EMPTYReturn an empty list from an XSUB immediately.=head1 Variables created by C<xsubpp> and C<xsubpp> internal functions=for apidoc AmU||newXSproto|char* name|XSUBADDR_t f|char* filename|const char *protoUsed by C<xsubpp> to hook up XSUBs as Perl subs. Adds Perl prototypes tothe subs.=for apidoc AmU||XS_VERSIONThe version identifier for an XS module. This is usuallyhandled automatically by C<ExtUtils::MakeMaker>. See C<XS_VERSION_BOOTCHECK>.=for apidoc Ams||XS_VERSION_BOOTCHECKMacro to verify that a PM module's $VERSION variable matches the XSmodule's C<XS_VERSION> variable. This is usually handled automatically byC<xsubpp>. See L<perlxs/"The VERSIONCHECK: Keyword">.=head1 Simple Exception Handling Macros=for apidoc Ams||dXCPTSet up necessary local variables for exception handling.See L<perlguts/"Exception Handling">.=for apidoc AmU||XCPT_TRY_STARTStarts a try block. See L<perlguts/"Exception Handling">.=for apidoc AmU||XCPT_TRY_ENDEnds a try block. See L<perlguts/"Exception Handling">.=for apidoc AmU||XCPT_CATCHIntroduces a catch block. See L<perlguts/"Exception Handling">.=for apidoc Ams||XCPT_RETHROWRethrows a previously caught exception. See L<perlguts/"Exception Handling">.=cut*/#define XST_mIV(i,v) (ST(i) = sv_2mortal(newSViv(v)) )#define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) )#define XST_mNV(i,v) (ST(i) = sv_2mortal(newSVnv(v)) )#define XST_mPV(i,v) (ST(i) = sv_2mortal(newSVpv(v,0)))#define XST_mPVN(i,v,n) (ST(i) = sv_2mortal(newSVpvn(v,n)))#define XST_mNO(i) (ST(i) = &PL_sv_no )#define XST_mYES(i) (ST(i) = &PL_sv_yes )#define XST_mUNDEF(i) (ST(i) = &PL_sv_undef)#define XSRETURN(off) \ STMT_START { \ const IV tmpXSoff = (off); \ PL_stack_sp = PL_stack_base + ax + (tmpXSoff - 1); \ return; \ } STMT_END#define XSRETURN_IV(v) STMT_START { XST_mIV(0,v); XSRETURN(1); } STMT_END#define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END#define XSRETURN_NV(v) STMT_START { XST_mNV(0,v); XSRETURN(1); } STMT_END#define XSRETURN_PV(v) STMT_START { XST_mPV(0,v); XSRETURN(1); } STMT_END#define XSRETURN_PVN(v,n) STMT_START { XST_mPVN(0,v,n); XSRETURN(1); } STMT_END#define XSRETURN_NO STMT_START { XST_mNO(0); XSRETURN(1); } STMT_END#define XSRETURN_YES STMT_START { XST_mYES(0); XSRETURN(1); } STMT_END#define XSRETURN_UNDEF STMT_START { XST_mUNDEF(0); XSRETURN(1); } STMT_END#define XSRETURN_EMPTY STMT_START { XSRETURN(0); } STMT_END#define newXSproto(a,b,c,d) newXS_flags(a,b,c,d,0)#ifdef XS_VERSION# define XS_VERSION_BOOTCHECK \ STMT_START { \ SV *_sv; \ const char *vn = NULL, *module = SvPV_nolen_const(ST(0)); \ if (items >= 2) /* version supplied as bootstrap arg */ \ _sv = ST(1); \ else { \ /* XXX GV_ADDWARN */ \ _sv = get_sv(Perl_form(aTHX_ "%s::%s", module, \ vn = "XS_VERSION"), FALSE); \ if (!_sv || !SvOK(_sv)) \ _sv = get_sv(Perl_form(aTHX_ "%s::%s", module, \ vn = "VERSION"), FALSE); \ } \ if (_sv) { \ SV *xssv = Perl_newSVpv(aTHX_ XS_VERSION, 0); \ xssv = new_version(xssv); \ if ( !sv_derived_from(_sv, "version") ) \ _sv = new_version(_sv); \ if ( vcmp(_sv,xssv) ) \ Perl_croak(aTHX_ "%s object version %"SVf" does not match %s%s%s%s %"SVf,\ module, SVfARG(vstringify(xssv)), \ vn ? "$" : "", vn ? module : "", vn ? "::" : "", \ vn ? vn : "bootstrap parameter", SVfARG(vstringify(_sv)));\ } \ } STMT_END#else# define XS_VERSION_BOOTCHECK#endif#ifdef NO_XSLOCKS# define dXCPT dJMPENV; int rEtV = 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -