Subject: | Missing CLASS declaration in code generated for methods that return instances of their own class |
The general use-case I'm trying to support is an instance method that
returns another instance of it's own type.
I'm using ExtUtils::XSpp ver 0.1602 with perl 5.14.2. OS is 64 bit
Ubuntu 10.04.
Consider the Animal class that is part of the XSpp-Example included with
the distro.
If I add an instance method to the class:
Animal MakeTwin() const;
with an implementation like:
Animal Animal::MakeTwin() const
{
return Animal(fName);
}
and then add it to the xsp file for the Animal class:
Animal & MakeTwin();
When the code is generated by xspp, we get (I've removed various #
declarations):
XS_EUPXS(XS_Animal_MakeTwin);
XS_EUPXS(XS_Animal_MakeTwin)
{
dVAR; dXSARGS;
if (items != 1)
croak_xs_usage(cv, "THIS");
{
Animal * THIS;
Animal * RETVAL;
if( sv_isobject(ST(0)) && (SvTYPE(SvRV(ST(0))) == SVt_PVMG) )
THIS = (Animal *)SvIV((SV*)SvRV( ST(0) ));
else{
warn( "Animal::MakeTwin() -- THIS is not a blessed SV reference" );
XSRETURN_UNDEF;
}
;
try {
RETVAL = new Animal( THIS->MakeTwin() );
}
catch (std::exception& e) {
croak("Caught C++ exception of type or derived from
'std::exception': %s", e.what());
}
catch (...) {
croak("Caught C++ exception of unknown type");
}
ST(0) = sv_newmortal();
sv_setref_pv( ST(0), CLASS, (void*)RETVAL );
}
XSRETURN(1);
}
..which looks almost correct, but the declaration of CLASS is missing,
causing the compiler error:
buildtmp/Example.c: In function ‘void
XS_Animal_MakeTwin(PerlInterpreter*, CV*)’:
buildtmp/Example.c:371: error: ‘CLASS’ was not declared in this scope
If there is a workaround for this use case, that would be fine too. Thanks.