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

📄 typemap.xs

📁 source of perl for linux application,
💻 XS
📖 第 1 页 / 共 2 页
字号:
intT_PTR_IN( ptr )  void * ptr CODE:  RETVAL = *(int *)ptr; OUTPUT:  RETVAL=item T_PTRREFSimilar to T_PTR except that the pointer is stored in a scalar and thereference to that scalar is returned to the caller. This can be usedto hide the actual pointer value from the programmer since it is usuallynot required directly from within perl.The typemap checks that a scalar reference is passed from perl to XS.=cut# Similar test to T_PTR# Pass in a value. Store the value in some static memory and# then return the pointerintRef *T_PTRREF_OUT( in )  intRef in; CODE:  xst_anintref = in;  RETVAL = &xst_anintref; OUTPUT:  RETVAL# pass in the pointer and return the valueintRefT_PTRREF_IN( ptr )  intRef * ptr CODE:  RETVAL = *ptr; OUTPUT:  RETVAL=item T_PTROBJSimilar to T_PTRREF except that the reference is blessed into a class.This allows the pointer to be used as an object. Most commonly used todeal with C structs. The typemap checks that the perl object passedinto the XS routine is of the correct class (or part of a subclass).The pointer is blessed into a class that is derived from the nameof type of the pointer but with all '*' in the name replaced with'Ptr'.=cut# Similar test to T_PTRREF# Pass in a value. Store the value in some static memory and# then return the pointerintObj *T_PTROBJ_OUT( in )  intObj in; CODE:  xst_anintobj = in;  RETVAL = &xst_anintobj; OUTPUT:  RETVAL# pass in the pointer and return the valueMODULE = XS::Typemap  PACKAGE = intObjPtrintObjT_PTROBJ_IN( ptr )  intObj * ptr CODE:  RETVAL = *ptr; OUTPUT:  RETVALMODULE = XS::Typemap PACKAGE = XS::Typemap=item T_REF_IV_REFNOT YET=item T_REF_IV_PTRSimilar to T_PTROBJ in that the pointer is blessed into a scalar object.The difference is that when the object is passed back into XS it must beof the correct type (inheritance is not supported).The pointer is blessed into a class that is derived from the nameof type of the pointer but with all '*' in the name replaced with'Ptr'.=cut# Similar test to T_PTROBJ# Pass in a value. Store the value in some static memory and# then return the pointerintRefIv *T_REF_IV_PTR_OUT( in )  intRefIv in; CODE:  xst_anintrefiv = in;  RETVAL = &xst_anintrefiv; OUTPUT:  RETVAL# pass in the pointer and return the valueMODULE = XS::Typemap  PACKAGE = intRefIvPtrintRefIvT_REF_IV_PTR_IN( ptr )  intRefIv * ptr CODE:  RETVAL = *ptr; OUTPUT:  RETVALMODULE = XS::Typemap PACKAGE = XS::Typemap=item T_PTRDESCNOT YET=item T_REFREFNOT YET=item T_REFOBJNOT YET=item T_OPAQUEPTRThis can be used to store bytes in the string component of theSV. Here the representation of the data is irrelevant to perl and thebytes themselves are just stored in the SV. It is assumed that the Cvariable is a pointer (the bytes are copied from that memorylocation).  If the pointer is pointing to something that isrepresented by 8 bytes then those 8 bytes are stored in the SV (andlength() will report a value of 8). This entry is similar to T_OPAQUE.In principal the unpack() command can be used to convert the bytesback to a number (if the underlying type is known to be a number).This entry can be used to store a C structure (the numberof bytes to be copied is calculated using the C C<sizeof> function)and can be used as an alternative to T_PTRREF without having to worryabout a memory leak (since Perl will clean up the SV).=cutintOpq *T_OPAQUEPTR_IN( val )  intOpq val CODE:  xst_anintopq = val;  RETVAL = &xst_anintopq; OUTPUT:  RETVALintOpqT_OPAQUEPTR_OUT( ptr )  intOpq * ptr CODE:  RETVAL = *ptr; OUTPUT:  RETVALshortT_OPAQUEPTR_OUT_short( ptr )  shortOPQ * ptr CODE:  RETVAL = *ptr; OUTPUT:  RETVAL# Test it with a structureastruct *T_OPAQUEPTR_IN_struct( a,b,c )  int a  int b  double c PREINIT:  struct t_opaqueptr test; CODE:  test.a = a;  test.b = b;  test.c = c;  RETVAL = &test; OUTPUT:  RETVALvoidT_OPAQUEPTR_OUT_struct( test )  astruct * test PPCODE:  XPUSHs(sv_2mortal(newSViv(test->a)));  XPUSHs(sv_2mortal(newSViv(test->b)));  XPUSHs(sv_2mortal(newSVnv(test->c)));=item T_OPAQUEThis can be used to store data from non-pointer types in the stringpart of an SV. It is similar to T_OPAQUEPTR except that thetypemap retrieves the pointer directly rather than assuming itis being supplied. For example if an integer is imported intoPerl using T_OPAQUE rather than T_IV the underlying bytes representingthe integer will be stored in the SV but the actual integer value will notbe available. i.e. The data is opaque to perl.The data may be retrieved using the C<unpack> function if theunderlying type of the byte stream is known.T_OPAQUE supports input and output of simple types.T_OPAQUEPTR can be used to pass these bytes back into C if a pointeris acceptable.=cutshortOPQT_OPAQUE_IN( val )  int val CODE:  RETVAL = (shortOPQ)val; OUTPUT:  RETVALIVT_OPAQUE_OUT( val )  shortOPQ val CODE:  RETVAL = (IV)val; OUTPUT:  RETVAL=item Implicit arrayxsubpp supports a special syntax for returningpacked C arrays to perl. If the XS return type is given as  array(type, nelem)xsubpp will copy the contents of C<nelem * sizeof(type)> bytes fromRETVAL to an SV and push it onto the stack. This is only really usefulif the number of items to be returned is known at compile time and youdon't mind having a string of bytes in your SV.  Use T_ARRAY to push avariable number of arguments onto the return stack (they won't bepacked as a single string though).This is similar to using T_OPAQUEPTR but can be used to process more thanone element.=cutarray(int,3)T_OPAQUE_array( a,b,c)  int a  int b  int c PREINIT:  int array[3]; CODE:  array[0] = a;  array[1] = b;  array[2] = c;  RETVAL = array; OUTPUT:  RETVAL=item T_PACKEDNOT YET=item T_PACKEDARRAYNOT YET=item T_DATAUNITNOT YET=item T_CALLBACKNOT YET=item T_ARRAYThis is used to convert the perl argument list to a C arrayand for pushing the contents of a C array onto the perlargument stack.The usual calling signature is  @out = array_func( @in );Any number of arguments can occur in the list before the array butthe input and output arrays must be the last elements in the list.When used to pass a perl list to C the XS writer must provide afunction (named after the array type but with 'Ptr' substituted for'*') to allocate the memory required to hold the list. A pointershould be returned. It is up to the XS writer to free the memory onexit from the function. The variable C<ix_$var> is set to the numberof elements in the new array.When returning a C array to Perl the XS writer must provide an integervariable called C<size_$var> containing the number of elements in thearray. This is used to determine how many elements should be pushedonto the return argument stack. This is not required on input sincePerl knows how many arguments are on the stack when the routine iscalled. Ordinarily this variable would be called C<size_RETVAL>.Additionally, the type of each element is determined from the type ofthe array. If the array uses type C<intArray *> xsubpp willautomatically work out that it contains variables of type C<int> anduse that typemap entry to perform the copy of each element. Allpointer '*' and 'Array' tags are removed from the name to determinethe subtype.=cut# Test passes in an integer array and returns it along with# the number of elements# Pass in a dummy value to test offsetting# Problem is that xsubpp does XSRETURN(1) because we arent# using PPCODE. This means that only the first element# is returned. KLUGE this by using CLEANUP to return before the# end.intArray *T_ARRAY( dummy, array, ... )  int dummy = 0;  intArray * array PREINIT:  U32 size_RETVAL; CODE:  dummy += 0; /* Fix -Wall */  size_RETVAL = ix_array;  RETVAL = array; OUTPUT:  RETVAL CLEANUP:  Safefree(array);  XSRETURN(size_RETVAL);=item T_STDIOThis is used for passing perl filehandles to and from C usingC<FILE *> structures.=cutFILE *T_STDIO_open( file )  const char * file CODE:  RETVAL = xsfopen( file ); OUTPUT:  RETVALSysRetT_STDIO_close( f )  PerlIO * f PREINIT:  FILE * stream; CODE:  /* Get the FILE* */  stream = PerlIO_findFILE( f );    /* Release the FILE* from the PerlIO system so that we do     not close the file twice */  PerlIO_releaseFILE(f,stream);  /* Must release the file before closing it */  RETVAL = xsfclose( stream ); OUTPUT:  RETVALintT_STDIO_print( stream, string )  FILE * stream  const char * string CODE:  RETVAL = xsfprintf( stream, string ); OUTPUT:  RETVAL=item T_INNOT YET=item T_INOUTThis is used for passing perl filehandles to and from C usingC<PerlIO *> structures. The file handle can used for reading andwriting.See L<perliol> for more information on the Perl IO abstractionlayer. Perl must have been built with C<-Duseperlio>.=item T_OUTNOT YET=back=cut

⌨️ 快捷键说明

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