Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1069455]
Approved by boftx
[marto]: https://www. v=WZnsHvEYEZI
[Discipulus]: marto apotropaic gestures in Eataly..
[Discipulus]: LanX nick does not downvote peoples, just content he dislike (I think)
[Discipulus]: anyway I have my Tk toys running at 50%!! someone want to see it?
[LanX]: disc+ true every node authored by me or mentioning Perl 6 ;)
[Discipulus]: naahh..
[LanX]: oh a tunnel ...
LanX ducks!

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2018-04-26 10:27 GMT
Find Nodes?
    Voting Booth?