Hi,
I have some object with multiple inheritance :
class D : public B1, public B2
B1 B2
\ /
D
I made XS interface for B1,B2 and D classes,
and I set ISA to match inheritance in the perl packages
I have a function that have parameters from type B2
and I want to pass a D to this function.
int func(B2* obj1,B2* obj2){
return obj1 == obj2;
}
D* d_ptr = new D();
B2* b2_ptr = dynamic_cast<B2*>(d_ptr)
func(d_ptr,b2_ptr);
>> return true
this works fine in full C++
but in the XS mapping the following process is in action:
D* object is cast on a void* to be came a perl reference.
then this void * is cast into a B2*.
here is my perlobject.map:
# "perlobject.map" Dean Roehrich, version 19960302
#
# TYPEMAPs
#
######################################################################
OUTPUT
# The Perl object is blessed into 'CLASS', which should be a
# char* having the name of the package for the blessing.
T_X_PTR
sv_setref_pv( $arg,${ntype}_Package, (void*)$var );
######################################################################
INPUT
T_X_PTR
if(sv_derived_from($arg,${ntype}_Package)) {
IV tmp_ = SvIV((SV*)SvRV($arg));
$var = ($type)tmp_;
}
else
croak(\"$var is not of type %s\",${ntype}_Package);
if I compare the final B2* and the original D*, the address of the pointed object
has changed due to the void* cast that do not work correctly with multiple inheritance.
This is a problem for me because I compare addresses of objects. so that the function
return false!!
Do you know how to fix this?
Is there a safe way to map multiple inherited objects in perl ??
thanks
Franck