SWIGUpcast problem / assigning to .. from incompatible type

Kustaa Nyholm <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
Hi,

I've been posting a few post about this problem already so sorry about the noise.

But I think I've tracked the root cause.

Background: I'm trying to upgrade existing occjava from OCE to OCC 7.3.0.

The main problem I'm experiencing stems from the fact that OCC 7.0.0
gave gave up a hierarchy of classes Handle_XXX and replaced that with
opencascade::handle<XXX> (hidden behind macro DEFINE_STANDARD_HANDLE).

In the OCC context Handle is basically a pointer to a pointer to the
actual instance of a class and originally the Handle_XXXX hierarchy
mirrored the actual class hierarchy.

And this made the upcasting work with the occjava SWIG defs.

But now it fails cause every Handle_XXX (aka opencascade::handle<XXX>)
is a distinct type.

So I'm looking for ideas how to fix this. Preferably with a typemap
or few cause there are a lot of classes and handles in OCC (over
8000 files in /usr/local/include/opencascade).

I've made a minimal (if not totally self contained experiment project
to illustrate the problem).

You can download a zip file of the experiment here:

http://eazycnc.com/temp/experiments.zip

and I will also collect the gist of it below.

wbr Kusti


/// Standard_Handle.hxx (FRAGMENT) ---------------------------
template <class T>
  class handle
  {
  public:
    //! STL-compliant typedef of contained type
    typedef T element_type;
    ...
   handle () : entity(0) {}

    //! Constructor from pointer to new object
    handle (const T *thePtr) : entity(const_cast<T*>(thePtr))
    {
      ...
    }
 ...
  private:
    Standard_Transient* entity;
  };
...
#define DEFINE_STANDARD_HANDLECLASS(C1,C2,BC) class C1; typedef Handle(C1) Handle_##C1;
#define DEFINE_STANDARD_HANDLE(C1,C2) DEFINE_STANDARD_HANDLECLASS(C1,C2,Standard_Transient)
#define DEFINE_STANDARD_PHANDLE(C1,C2) DEFINE_STANDARD_HANDLECLASS(C1,C2,Standard_Persistent)


/// experiment.hxx --------------------------------------------
#include "/usr/local/include/opencascade/Standard_Handle.hxx"

DEFINE_STANDARD_HANDLE(Geom_Geometry,Standard_Transient);
DEFINE_STANDARD_HANDLE(Geom_Curve,Standard_Transient);


/// experiment.cxx --------------------------------------------
#include "experiment.hxx"


/// experiment.i ----------------------------------------------
%module experiment
%{
#include "experiment.hxx"
%}

%include "experiment.hxx"

%rename(Geom_Curve) Handle_Geom_Curve;
%rename(Geom_Geometry) Handle_Geom_Geometry;

class Handle_Geom_Geometry
{
	Handle_Geom_Geometry()=0;
};

class Handle_Geom_Curve : public Handle_Geom_Geometry
{
	Handle_Geom_Curve()=0;
};


/// Makefile ---------------------------------------------------
all:
	c++ -std=c++11 -c -I/usr/local/include/opencascade -o experiment.so experiment.cxx
	swig -c++ -java experiment.i
	c++ -std=c++11 -c -I/usr/local/include/opencascade -I/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/include -I/Library/Java/JavaVirtualMachines/jdk-11.0.6.jdk/Contents/Home/include/darwin -o experiment_wrap.so experiment_wrap.cxx


/// experiment_wrap.cxx (FRAGMENT) -----------------------------

SWIGEXPORT jlong JNICALL Java_experimentJNI_Geom_1Curve_1SWIGUpcast(JNIEnv *jenv, jclass jcls, jlong jarg1) {
    jlong baseptr = 0;
    (void)jenv;
    (void)jcls;
    *(Handle_Geom_Geometry **)&baseptr = *(Handle_Geom_Curve **)&jarg1;
    return baseptr;
}


which fails to compile like this



// Error ========================================================

experiment_wrap.cxx:266:42: error: assigning to 'Handle_Geom_Geometry *' (aka 'handle<Geom_Geometry> *') from incompatible type 'Handle_Geom_Curve *' (aka 'handle<Geom_Curve> *')
    *(Handle_Geom_Geometry **)&baseptr = *(Handle_Geom_Curve **)&jarg1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.