FrenchZ has asked for the wisdom of the Perl Monks concerning the following question:
I have some object with multiple inheritance :
class D : public B1, public B2
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();<BR> B2* b2_ptr = dynamic_cast<B2*>(d_ptr);<BR> 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<BR> #<BR> # TYPEMAPs<BR> #<BR> ############################################################<BR> OUTPUT<BR> # The Perl object is blessed into 'CLASS', which should be a<BR> # char* having the name of the package for the blessing.<BR> T_X_PTR<BR> sv_setref_pv( $arg,${ntype}_Package, (void*)$var );<BR> <p> ############################################################<BR> INPUT<BR> T_X_PTR<BR> if(sv_derived_from($arg,${ntype}_Package)) { <BR> IV tmp_ = SvIV((SV*)SvRV($arg));<BR> $var = ($type)tmp_;<BR> }<BR> else<BR> croak(\"$var is not of type %s\",${ntype}_Package);<BR>
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 in advance
Edit kudra, 2001-08-08 Added code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XS typemap and C++ multiple inheritance
by John M. Dlugosz (Monsignor) on Aug 03, 2001 at 02:54 UTC | |
by FrenchZ (Initiate) on Aug 06, 2001 at 15:55 UTC | |
by John M. Dlugosz (Monsignor) on Aug 06, 2001 at 18:02 UTC | |
by FrenchZ (Initiate) on Aug 06, 2001 at 18:19 UTC | |
by John M. Dlugosz (Monsignor) on Aug 06, 2001 at 22:44 UTC | |
| |
|
Re: XS typemap and C++ multiple inheritance
by rsteinke (Scribe) on Jun 15, 2002 at 15:59 UTC |