mirror of https://github.com/swig/swig
[python] Fix inheriting from multiple director classes
Fix mishandling of a Python class inheriting from multiple SWIG-wrapped director classes. Fixes #422 Fixes https://sourceforge.net/p/swig/bugs/1379/
This commit is contained in:
parent
8a03c7d555
commit
e23d912b49
|
@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
|
||||||
Version 4.1.0 (in progress)
|
Version 4.1.0 (in progress)
|
||||||
===========================
|
===========================
|
||||||
|
|
||||||
|
2022-07-20: jicks, Ingener74, olly
|
||||||
|
#422 [Python] Fix mishandling of a Python class inheriting from
|
||||||
|
multiple SWIG-wrapped director classes.
|
||||||
|
|
||||||
2022-07-19: wsfulton
|
2022-07-19: wsfulton
|
||||||
#692 [C#, Java, Perl, Python, Ruby] std::unique_ptr and std::auto_ptr typemaps
|
#692 [C#, Java, Perl, Python, Ruby] std::unique_ptr and std::auto_ptr typemaps
|
||||||
provided for inputs types in std_unique_ptr.i and std_auto_ptr.i.
|
provided for inputs types in std_unique_ptr.i and std_auto_ptr.i.
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
//%module(ruby_minherit="1") multiple_inheritance
|
||||||
|
%module(directors="1") director_multiple_inheritance
|
||||||
|
|
||||||
|
%feature("director") A;
|
||||||
|
%feature("director") B;
|
||||||
|
%feature("director") C;
|
||||||
|
%feature("director") D;
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
|
||||||
|
class A {
|
||||||
|
public:
|
||||||
|
virtual ~A() { }
|
||||||
|
virtual int testA();
|
||||||
|
};
|
||||||
|
|
||||||
|
class B: virtual public A {
|
||||||
|
public:
|
||||||
|
virtual ~B() { }
|
||||||
|
virtual int testB();
|
||||||
|
};
|
||||||
|
|
||||||
|
class C: virtual public A {
|
||||||
|
public:
|
||||||
|
virtual ~C() { }
|
||||||
|
virtual int testC();
|
||||||
|
};
|
||||||
|
|
||||||
|
class D: virtual public A {
|
||||||
|
public:
|
||||||
|
virtual ~D() { }
|
||||||
|
virtual int testD();
|
||||||
|
};
|
||||||
|
|
||||||
|
class E {
|
||||||
|
public:
|
||||||
|
virtual ~E() { }
|
||||||
|
virtual int testE(B*);
|
||||||
|
};
|
||||||
|
|
||||||
|
class F {
|
||||||
|
public:
|
||||||
|
virtual ~F() { }
|
||||||
|
virtual int testF(C*);
|
||||||
|
};
|
||||||
|
|
||||||
|
class T {
|
||||||
|
public:
|
||||||
|
virtual ~T() { }
|
||||||
|
virtual int testT(D*);
|
||||||
|
};
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
||||||
|
%{
|
||||||
|
|
||||||
|
int A::testA() { return 1; }
|
||||||
|
|
||||||
|
int B::testB() { return 2; }
|
||||||
|
|
||||||
|
int C::testC() { return 3; }
|
||||||
|
|
||||||
|
int D::testD() { return 4; }
|
||||||
|
|
||||||
|
int E::testE(B*) { return 5; }
|
||||||
|
|
||||||
|
int F::testF(C*) { return 6; }
|
||||||
|
|
||||||
|
int T::testT(D*) { return 20; }
|
||||||
|
|
||||||
|
%}
|
|
@ -0,0 +1,36 @@
|
||||||
|
import director_multiple_inheritance as st
|
||||||
|
|
||||||
|
class TestBCD(st.B, st.C, st.D):
|
||||||
|
def __init__(self):
|
||||||
|
st.B.__init__(self)
|
||||||
|
st.C.__init__(self)
|
||||||
|
st.D.__init__(self)
|
||||||
|
|
||||||
|
class TestBDC(st.B, st.C, st.D):
|
||||||
|
def __init__(self):
|
||||||
|
st.B.__init__(self)
|
||||||
|
st.D.__init__(self)
|
||||||
|
st.C.__init__(self)
|
||||||
|
|
||||||
|
class TestCBD(st.B, st.C, st.D):
|
||||||
|
def __init__(self):
|
||||||
|
st.C.__init__(self)
|
||||||
|
st.B.__init__(self)
|
||||||
|
st.D.__init__(self)
|
||||||
|
|
||||||
|
def dotest(test):
|
||||||
|
e = st.E()
|
||||||
|
if e.testE(test) != 5:
|
||||||
|
raise RuntimeError(e.testE(test))
|
||||||
|
|
||||||
|
f = st.F()
|
||||||
|
if f.testF(test) != 6:
|
||||||
|
raise RuntimeError(f.testF(test))
|
||||||
|
|
||||||
|
t = st.T()
|
||||||
|
if t.testT(test) != 20:
|
||||||
|
raise RuntimeError(t.testT(test))
|
||||||
|
|
||||||
|
dotest(TestBCD())
|
||||||
|
dotest(TestCBD())
|
||||||
|
dotest(TestBDC())
|
|
@ -792,6 +792,7 @@ SwigPyObject_append(PyObject* v, PyObject* next)
|
||||||
PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject");
|
PyErr_SetString(PyExc_TypeError, "Attempt to append a non SwigPyObject");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
((SwigPyObject *)next)->next = sobj->next;
|
||||||
sobj->next = next;
|
sobj->next = next;
|
||||||
Py_INCREF(next);
|
Py_INCREF(next);
|
||||||
return SWIG_Py_Void();
|
return SWIG_Py_Void();
|
||||||
|
|
Loading…
Reference in New Issue