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

📄 extutils::xsbuilder.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
\&    perl \-MMyClass::WrapXS \-e \*(AqMyClass::WrapXS\->run\*(Aq.Ve.PPXSBuilder will create the \s-1XS\s0, pm and Makefile.PL files for every module that is mentioned in the maps. The result is placed as a directory hierarchy underWrapXS. To control the content of the \f(CW\*(C`Makefile.PL\*(C'\fR and the \f(CW\*(C`pm\*(C'\fR file, youcan override the \f(CW\*(C`makefilepl_text\*(C'\fR and \f(CW\*(C`pm_text\*(C'\fR methods. You can includeadditional code in the \s-1XS\s0 files by writing an include file which is includedat the top of the \s-1XS\s0 file. This file can contain helper functions that can'tbe automatically generated. The files must be placed under the \f(CW\*(C`xs\*(C'\fRdirectory, with the correct path and name. For example, to have a header fileincluded for the module Apache::DAV, create a file named\&\f(CW\*(C`xs/Apache/DAV/Apache_\|_DAV.h\*(C'\fR. The same can be done for inclusion in the pmfile. Following the example above, the file name would be \&\f(CW\*(C`xs/Apache/DAV/DAV_pm\*(C'\fR..SH "Format of the map files".IX Header "Format of the map files"For all map files blank lines are ignored and lines starting with a \f(CW\*(C`#\*(C'\fR aretreated as comments and are also ignored..Sh "Types map file".IX Subsection "Types map file"Contains the mapping from C type to Perl classes..PPFormat is the name of the C type followed by the name of the Perl classor the \s-1XS\s0 type specifier, separated by a \f(CW\*(C`|\*(C'\fR. Example:.PP.Vb 2\&    int                 | IV\&    struct request_rec  | Apache::RequestRec.Ve.PPIf you have a Perl class with a single-level namespace (e.g. Apache) you needto postfix it with two colons (e.g. \*(L"Apache::\*(R"). When both a typedef and astructure share the same name, structures must be written as with a \*(L"struct \*(R"prefix (e.g. \*(L"struct foo\*(R".) Addionally, you can give the id for the typemap ifyou need a special conversion and one or more other names for the struct:.PP.Vb 1\&    struct request_rec  | Apache::RequestRec | T_APACHEOBJ | r.Ve.PPAn optional fifth parameter specifies that the data needs to be copiedwhen assigned to a struct member and selects the way how memory is allocated:.PP.Vb 1\&    char *   | PV | | | strdup.Ve.PPThe actual code for memory allocation is provided inside the structure map,for example:.PP.Vb 2\&    MALLOC=strdup:$dest = ($type)ap_pstrdup(obj \-> pool, $src)\&    MALLOC=malloc:ap_palloc(obj \-> pool, $src, sizeof($type)) ; memcpy($dest,$src,sizeof($type)).Ve.PPThis gives two ways to allocate memory and copy the data into it. The fifthparameter in the type map selects which of these two should be used. \f(CW$src\fR,\&\f(CW$dest\fR and \f(CW$type\fR are replaced by the source, the destination and the type.\&\f(CW\*(C`obj\*(C'\fR is a pointer to the C\-structure..PP\fISpecial Types\fR.IX Subsection "Special Types".IP "String, \s-1PV\s0 and PVnull" 4.IX Item "String, PV and PVnull"A string is represented in C as a pointer to an null terminated range ofcharacters. In Perl the it is called \f(CW\*(C`PV\*(C'\fR (pointer value). When convertinga Perl \f(CW\*(C`undef\*(C'\fR to a C string Perl by default converts it to an empty string.While this is save, this is not always what is required, because manyC interfaces treat \s-1NULL\s0 as a special case. For this reason the \f(CW\*(C`PVnull\*(C'\fR typeis introduced, which converts \f(CW\*(C`undef\*(C'\fR to \f(CW\*(C`NULL\*(C'\fR and \f(CW\*(C`NULL\*(C'\fR to \f(CW\*(C`undef\*(C'\fR..SpTo make it work you need the following line in your type map file:.Sp.Vb 1\&        PVnull          | PVnull | | | strdup.Ve.SpNow you can defines any type, structure memeber or function argumentas type \f(CW\*(C`PVnull\*(C'\fR..Sh "Functions map file".IX Subsection "Functions map file"Contains the mapping from C functions to Perl functions. This can be used to reorder arguments, tell XSBuilder which arguments are return values, and inwhich Perl package the function will be created..PPThere are some directives which affect the function mappings that follow it.Each directive may appear in the file more than once..IP "\s-1MODULE\s0" 4.IX Item "MODULE"the module name (file name) where the function should be defined, e.g..Sp.Vb 1\&    MODULE=Apache::Connection.Ve.Spwill define the functions that follow in files named Apache/Connection.{pm,xs}.IP "\s-1PACKAGE\s0" 4.IX Item "PACKAGE"The name of the package that functions are defined in. If undefined, \s-1PACKAGE\s0defaults to the value of \s-1MODULE\s0. A value of 'guess' indicates that packagename should be guessed based on first argument found that maps to a Perlclass. Falls back on the prefix (ap_ \-> Apache, apr_ \-> \s-1APR\s0)..IP "\s-1PREFIX\s0" 4.IX Item "PREFIX"The prefix to be stripped from C functions when creating the \s-1XS\s0 stubs.Defaults to the value of \s-1PACKAGE\s0, converted to C naming convention. Forexample,.Sp.Vb 1\&    PREFIX=APR::Base64.Ve.Spwill strip \f(CW\*(C`apr_base64_\*(C'\fR from the C functions. If the prefix does not match,it defaults to \f(CW\*(C`ap_\*(C'\fR or \f(CW\*(C`apr_\*(C'\fR..PP\&\fB\s-1NOTE:\s0\fR You must have at least one \f(CW\*(C`MODULE\*(C'\fR definitionotherwise all functions will be ignored..PPThe format of entries is:.PP.Vb 1\&    C function name | dispatch function name (dispatch argspec) | argspec | Perl alias.Ve.PPThe \f(CW\*(C`dispatch function name\*(C'\fR (the C function that is actually called)defaults to C function name. If the dispatch function name is just a prefix(mpxs_, \s-1MPXS_\s0), the \f(CW\*(C`C function name\*(C'\fR is appended to it. The return type maybe specified before the \f(CW\*(C`C function name\*(C'\fR, and defaults to the \f(CW\*(C`return_type\*(C'\fRin the \f(CW\*(C`{foo}::FunctionTable\*(C'\fR module generated by the \f(CW\*(C`ParseSource\*(C'\fR module..PPThe \f(CW\*(C`dispatch argspec\*(C'\fR is optional. If supplied, it can be used to passdifferent parameters to the dispatch function then to the \s-1XS\s0 function. If thefunction name begins with \f(CW\*(C`DEFINE_\*(C'\fR, a new function is defined (for definingfunctions that are not parsed from the source). \f(CW\*(C`argspec\*(C'\fR must be supplied.\&\f(CW\*(C`DEFINE_\*(C'\fR is not included in the generated function name..PPThe \f(CW\*(C`argspec\*(C'\fR defaults to arguments in \f(CW\*(C`{foo}::FunctionTable\*(C'\fR, as generatedby the \f(CW\*(C`ParseSource\*(C'\fR module. Argument types can be specified to overridethose in the \f(CW\*(C`{foo}::FunctionTable\*(C'\fR. Default values can also be specified,e.g. arg=default_value.PPFor example:  ap_get_client_block   | mpxs_ | r, \s-1SV\s0 *:buffer, bufsiz  ap_setup_client_block |       | r, read_policy=REQUEST_CHUNKED_ERROR  ap_make_array      | ap_make_array(r\->pool, nelts, elt_size) | request_rec *:r, nelts, elt_size.PPargspec of '...' indicates passthru, calling the function with.PP.Vb 1\&    (aTHX_ I32 items, SP **sp, SV **MARK).Ve.PPTo mark an argument as return only you can prefix it with < e.g..PP.Vb 1\&    dav_open_lockdb | | r, ro, <lockdb.Ve.PPwill be called as ($error get the return value of the C function).PP.Vb 1\&    ($error, $lockdb) = $r \-> open_lockdb (0) ;.Ve.PPThe return argument (e.g. lockdb) will always be passed by address to the function..PPThe function alias, if defined, will be created in the current \f(CW\*(C`PACKAGE\*(C'\fR..PPFunction names on lines that do not begin with a word character or a singlespace are skipped. Function names can be prefixed with the following symbols:.PP.Vb 5\&    \*(Aq!\*(Aq => \*(Aqdisabled or not yet implemented\*(Aq,\&    \*(Aq~\*(Aq => \*(Aqimplemented but not auto\-generated\*(Aq,\&    \*(Aq\-\*(Aq => \*(Aqlikely never be available to Perl\*(Aq,\&    \*(Aq>\*(Aq => \*(Aq"private" to your C library\*(Aq,\&    \*(Aq?\*(Aq => \*(Aqunclassified\*(Aq,.Ve.Sh "Structures map file".IX Subsection "Structures map file"Contains the mapping from C structures to Perl classes and defines the membersfor which access methods should be created. A \f(CW\*(C`new\*(C'\fR method may be specified,if desired. The format looks like the following:.PP.Vb 5\&    <struct_name>\&      member1\&      member2\&      new\&    </struct_name>.Ve.PPAn optional module name can be given, to specify in which module the codeshould be placed. To place the structure in My::Module, for example, specify:.PP.Vb 1\&    <struct_name MODULE=My::Module>.Ve.PPFor all members that are listed here, XSBuilder will generate an access methodto read and write it's content. If you want to name the perl access methoddifferently than the C member, you can write.PP.Vb 1\&   cMemberValue | member_value | type.Ve.PPthis will map the \f(CW\*(C`cMemberValue\*(C'\fR structure member to the access function \&\f(CW\*(C`member_value\*(C'\fR. The default is to use the same name in Perl as in C.As third argument you can give a typename. This defaults to the type of the variable. It can be used to specify a different type, for special conversion needs.(e.g. \s-1PV\s0 versus PVnull)If you give the \f(CW\*(C`new\*(C'\fR member, XSBuilder will create a new method for thatclass, which can be used to create a new instance and initialize it with data..Sh "Callbacks map file".IX Subsection "Callbacks map file"The format of entries is:.PP.Vb 1\&    C function name | argspec.Ve.PPThe content is the same as function map, it but contains the callbacks..SH "Additional generated methods".IX Header "Additional generated methods"For structures, XSBuilder will generate two additional methods: \f(CW\*(C`new\*(C'\fR, and\&\f(CW\*(C`init_callbacks\*(C'\fR..Sh "new ($initialvalue)".IX Subsection "new ($initialvalue)"With \f(CW\*(C`new\*(C'\fR you can create a new Perl object for an C structure. Optionally,you can pass either a hashref with initial data, or another object, who'sdata will be copied into the new object..Sh "init_callbacks".IX Subsection "init_callbacks"\&\f(CW\*(C`init_callbacks\*(C'\fR should be called during object initialization. It will fillin all callback members of a structure with pointers that cause a method callinto the object, when the callback is called from C..PPYou can call it either with.PP.Vb 1\&    $obj \-> init_callbacks.Ve.PPor.PP.Vb 1\&    MyModule \-> init_callbacks ($obj) ;.Ve.SH "Callbacks".IX Header "Callbacks"A callback which is part of a structure will cause a call to the method withthe same name as the structure member, prefixed with \f(CW\*(C`cb_\*(C'\fR. For example, ifyou have a structure member named \f(CW\*(C`open\*(C'\fR, then the Perl method \f(CW\*(C`cb_open\*(C'\fRwill be called whenever the C code calls the callback..PPIf you want to call the callback on your own you need to call the method whichis called like the structure member, e.g. \f(CW\*(C`open\*(C'\fR..PP\&\s-1NOTE:\s0 You need to call \f(CW\*(C`init_callbacks\*(C'\fR during your method initialzation tobe able to call callbacks.

⌨️ 快捷键说明

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