⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 typemap.xs

📁 source of perl for linux application,
💻 XS
📖 第 1 页 / 共 2 页
字号:
/*   XS code to test the typemap entries   Copyright (C) 2001 Tim Jenness.   All Rights Reserved*/#include "EXTERN.h"   /* std perl include */#include "perl.h"     /* std perl include */#include "XSUB.h"     /* XSUB include *//* Prototypes for external functions */FILE * xsfopen( const char * );int xsfclose( FILE * );int xsfprintf( FILE *, const char *);/* Type definitions required for the XS typemaps */typedef SV * SVREF; /* T_SVREF */typedef int SysRet; /* T_SYSRET */typedef int Int;    /* T_INT */typedef int intRef; /* T_PTRREF */typedef int intObj; /* T_PTROBJ */typedef int intRefIv; /* T_REF_IV_PTR */typedef int intArray; /* T_ARRAY */typedef short shortOPQ;   /* T_OPAQUE */typedef int intOpq;   /* T_OPAQUEPTR *//* A structure to test T_OPAQUEPTR */struct t_opaqueptr {  int a;  int b;  double c;};typedef struct t_opaqueptr astruct;/* Some static memory for the tests */static I32 xst_anint;static intRef xst_anintref;static intObj xst_anintobj;static intRefIv xst_anintrefiv;static intOpq xst_anintopq;/* Helper functions *//* T_ARRAY - allocate some memory */intArray * intArrayPtr( int nelem ) {    intArray * array;    Newx(array, nelem, intArray);    return array;}MODULE = XS::Typemap   PACKAGE = XS::TypemapPROTOTYPES: DISABLE=head1 TYPEMAPSEach C type is represented by an entry in the typemap file thatis responsible for converting perl variables (SV, AV, HV and CV) toand from that type.=over 4=item T_SVThis simply passes the C representation of the Perl variable (an SV*)in and out of the XS layer. This can be used if the C code wantsto deal directly with the Perl variable.=cutSV *T_SV( sv )  SV * sv CODE:  /* create a new sv for return that is a copy of the input     do not simply copy the pointer since the SV will be marked     mortal by the INPUT typemap when it is pushed back onto the stack */  RETVAL = sv_mortalcopy( sv );  /* increment the refcount since the default INPUT typemap mortalizes     by default and we don't want to decrement the ref count twice     by mistake */  SvREFCNT_inc(RETVAL); OUTPUT:  RETVAL=item T_SVREFUsed to pass in and return a reference to an SV.=cutSVREFT_SVREF( svref )  SVREF svref CODE:  RETVAL = svref; OUTPUT:  RETVAL=item T_AVREFFrom the perl level this is a reference to a perl array.From the C level this is a pointer to an AV.=cutAV *T_AVREF( av )  AV * av CODE:  RETVAL = av; OUTPUT:  RETVAL=item T_HVREFFrom the perl level this is a reference to a perl hash.From the C level this is a pointer to an HV.=cutHV *T_HVREF( hv )  HV * hv CODE:  RETVAL = hv; OUTPUT:  RETVAL=item T_CVREFFrom the perl level this is a reference to a perl subroutine(e.g. $sub = sub { 1 };). From the C level this is a pointerto a CV.=cutCV *T_CVREF( cv )  CV * cv CODE:  RETVAL = cv; OUTPUT:  RETVAL=item T_SYSRETThe T_SYSRET typemap is used to process return values from system calls.It is only meaningful when passing values from C to perl (there isno concept of passing a system return value from Perl to C).System calls return -1 on error (setting ERRNO with the reason)and (usually) 0 on success. If the return value is -1 this typemapreturns C<undef>. If the return value is not -1, this typemaptranslates a 0 (perl false) to "0 but true" (whichis perl true) or returns the value itself, to indicate that thecommand succeeded.The L<POSIX|POSIX> module makes extensive use of this type.=cut# Test a successful returnSysRetT_SYSRET_pass() CODE:  RETVAL = 0; OUTPUT:  RETVAL# Test failureSysRetT_SYSRET_fail() CODE:  RETVAL = -1; OUTPUT:  RETVAL=item T_UVAn unsigned integer.=cutunsigned intT_UV( uv )  unsigned int uv CODE:  RETVAL = uv; OUTPUT:  RETVAL=item T_IVA signed integer. This is cast to the required  integer type whenpassed to C and converted to an IV when passed back to Perl.=cutlongT_IV( iv )  long iv CODE:  RETVAL = iv; OUTPUT:  RETVAL=item T_INTA signed integer. This typemap converts the Perl value to a nativeinteger type (the C<int> type on the current platform). When returningthe value to perl it is processed in the same way as for T_IV.Its behaviour is identical to using an C<int> type in XS with T_IV.=item T_ENUMAn enum value. Used to transfer an enum componentfrom C. There is no reason to pass an enum value to C sinceit is stored as an IV inside perl.=cut# The test should return the value for SVt_PVHV.# 11 at the present time but we can't not rely on this# for testing purposes.svtypeT_ENUM() CODE:  RETVAL = SVt_PVHV; OUTPUT:  RETVAL=item T_BOOLA boolean type. This can be used to pass true and false values to andfrom C.=cutboolT_BOOL( in )  bool in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_U_INTThis is for unsigned integers. It is equivalent to using T_UVbut explicitly casts the variable to type C<unsigned int>.The default type for C<unsigned int> is T_UV.=item T_SHORTShort integers. This is equivalent to T_IV but explicitly caststhe return to type C<short>. The default typemap for C<short>is T_IV.=item T_U_SHORTUnsigned short integers. This is equivalent to T_UV but explicitlycasts the return to type C<unsigned short>. The default typemap forC<unsigned short> is T_UV.T_U_SHORT is used for type C<U16> in the standard typemap.=cutU16T_U_SHORT( in )  U16 in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_LONGLong integers. This is equivalent to T_IV but explicitly caststhe return to type C<long>. The default typemap for C<long>is T_IV.=item T_U_LONGUnsigned long integers. This is equivalent to T_UV but explicitlycasts the return to type C<unsigned long>. The default typemap forC<unsigned long> is T_UV.T_U_LONG is used for type C<U32> in the standard typemap.=cutU32T_U_LONG( in )  U32 in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_CHARSingle 8-bit characters.=cutcharT_CHAR( in );  char in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_U_CHARAn unsigned byte.=cutunsigned charT_U_CHAR( in );  unsigned char in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_FLOATA floating point number. This typemap guarantees to return a variablecast to a C<float>.=cutfloatT_FLOAT( in )  float in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_NVA Perl floating point number. Similar to T_IV and T_UV in that thereturn type is cast to the requested numeric type rather thanto a specific type.=cutNVT_NV( in )  NV in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_DOUBLEA double precision floating point number. This typemap guarantees toreturn a variable cast to a C<double>.=cutdoubleT_DOUBLE( in )  double in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_PVA string (char *).=cutchar *T_PV( in )  char * in CODE:  RETVAL = in; OUTPUT:  RETVAL=item T_PTRA memory address (pointer). Typically associated with a C<void *>type.=cut# Pass in a value. Store the value in some static memory and# then return the pointervoid *T_PTR_OUT( in )  int in; CODE:  xst_anint = in;  RETVAL = &xst_anint; OUTPUT:  RETVAL# pass in the pointer and return the value

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -