Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

xspp did not handle "const string&" typemap

by llancet (Friar)
on Jan 06, 2014 at 05:08 UTC ( #1069455=perlquestion: print w/ replies, xml ) Need Help??
llancet has asked for the wisdom of the Perl Monks concerning the following question:

I found the problem by myself. If one uses XSPP, one must also use Module::Build::WithXSpp to generate XS tyepmap from XSPP typemaps. Otherwise the typemaps are actually not generated.

I'm trying to write a Perl wrapper for my C++ library using XSpp. The typemap looks like this:
%loadplugin{feature::default_xs_typemap}; %typemap{const std::string&}{parsed} { %precall_code {% std::string tmp(SvPV($PerlVar)); $Cvar = tmp; %}; }; %typemap{const std::string}{parsed} { %precall_code {% std::string $Cvar(SvPV($PerlVar)); %}; }; %typemap{GenoEye::PosType}{simple} { %xs_type{T_IV}; }; %typemap{GenoEye::Page*}{parsed} { %precall_code {% IV tmp = SvIV(SvRV($PerlVar)); $CVar = INT2PTR(GenoEye::Page, tmp); %}; %output_code {% $CVar->ref(); sv_setref_pv($PerlVar, "GenoEye::Page", $CVar) %}; };
When I do the compile, XS said the "const std::string" is not type mapped:
Could not find a typemap for C type 'const std::string'. The following C types are mapped by the current typemap: 'AV *', 'Boolean', 'CV *', 'FILE *', 'FileHandle', 'GenoEye::Page *', +'GenoEye::PosType', 'HV *', 'I16', 'I32', 'I8', 'IV', 'InOutStream', +'InputStream', 'NV', 'OutputStream', 'PerlIO *', 'Result', 'STRLEN', +'SV *', 'SVREF', 'SysRet', 'SysRetLong', 'Time_t *', 'U16', 'U32', 'U +8', 'UV', 'bool', 'bool_t', 'caddr_t', 'char', 'char *', 'char **', ' +const char *', 'double', 'float', 'int', 'long', 'short', 'size_t', ' +ssize_t', 'time_t', 'unsigned', 'unsigned char', 'unsigned char *', ' +unsigned int', 'unsigned long', 'unsigned long *', 'unsigned short', +'void *', 'wchar_t', 'wchar_t *' in /usr/bin/perl -MExtUtils::XSpp::Cmd -e xspp -- --typemap=typemap.x +sp GenoEye_Page.xsp, line 53
Then I tried to run xspp directly to see the generated XS code. In the TYPEMAP section, it seems most of the typemaps I written is not converted to XS. Why?
TYPEMAP: <<END TYPEMAP GenoEye::Page* O_OBJECT GenoEye::PosType T_IV INPUT O_OBJECT if( sv_isobject($arg) && (SvTYPE(SvRV($arg)) == SVt_PVMG) ) $var = ($type)SvIV((SV*)SvRV( $arg )); else{ warn( \"${Package}::$func_name() -- $var is not a blessed SV r +eference\" ); XSRETURN_UNDEF; } OUTPUT O_OBJECT sv_setref_pv( $arg, xsp_constructor_class("${my $ntt = $type; $ntt + =~ s{^const\s+|[ \t*]+$}{}g; \$ntt}"), (void*)$var ); END

Comment on xspp did not handle "const string&" typemap
Select or Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1069455]
Approved by boftx
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2014-09-30 16:39 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (378 votes), past polls