diff --git a/SWIG/Examples/test-suite/common.mk b/SWIG/Examples/test-suite/common.mk index 6599d9ef3..ab7b58ac1 100644 --- a/SWIG/Examples/test-suite/common.mk +++ b/SWIG/Examples/test-suite/common.mk @@ -382,7 +382,8 @@ C_TEST_CASES += \ MULTI_CPP_TEST_CASES += \ clientdata_prop \ imports \ - template_typedef_import + template_typedef_import \ + mod NOT_BROKEN_TEST_CASES = $(CPP_TEST_CASES:=.cpptest) \ $(C_TEST_CASES:=.ctest) \ diff --git a/SWIG/Examples/test-suite/mod.h b/SWIG/Examples/test-suite/mod.h new file mode 100644 index 000000000..aae629850 --- /dev/null +++ b/SWIG/Examples/test-suite/mod.h @@ -0,0 +1,34 @@ + + +class C; + +class A +{ +public: + A() {} + C* GetC() { return NULL; } + + void DoSomething(A* a) {} +}; + + +class B : public A +{ +public: + B() {} + +}; + + +class C : public B +{ +public: + C() {} +}; + + +class D : public C +{ +public: + D() {} +}; diff --git a/SWIG/Examples/test-suite/mod.list b/SWIG/Examples/test-suite/mod.list new file mode 100644 index 000000000..41350aefa --- /dev/null +++ b/SWIG/Examples/test-suite/mod.list @@ -0,0 +1,2 @@ +mod_a +mod_b diff --git a/SWIG/Examples/test-suite/mod_a.i b/SWIG/Examples/test-suite/mod_a.i new file mode 100644 index 000000000..bc8c163f4 --- /dev/null +++ b/SWIG/Examples/test-suite/mod_a.i @@ -0,0 +1,24 @@ +%module mod_a + +%{ +#include "mod.h" +%} + + +class C; + +class A +{ +public: + A() {} + C* GetC() { return NULL; } + + void DoSomething(A* a) {} +}; + + +class B : public A +{ +public: + B(); +}; diff --git a/SWIG/Examples/test-suite/mod_b.i b/SWIG/Examples/test-suite/mod_b.i new file mode 100644 index 000000000..3bb8c8bf3 --- /dev/null +++ b/SWIG/Examples/test-suite/mod_b.i @@ -0,0 +1,22 @@ +%module mod_b + +%{ +#include "mod.h" +%} + + +%import mod_a.i + + +class C : public B +{ +public: + C() {} +}; + + +class D : public C +{ +public: + D() {} +}; diff --git a/SWIG/Examples/test-suite/python/mod_runme.py b/SWIG/Examples/test-suite/python/mod_runme.py new file mode 100644 index 000000000..d92611991 --- /dev/null +++ b/SWIG/Examples/test-suite/python/mod_runme.py @@ -0,0 +1,6 @@ +import mod_a +import mod_b + +c = mod_b.C() +d = mod_b.D() +d.DoSomething(c) diff --git a/SWIG/Lib/swiginit.swg b/SWIG/Lib/swiginit.swg index d109d2a26..a9cb7d117 100644 --- a/SWIG/Lib/swiginit.swg +++ b/SWIG/Lib/swiginit.swg @@ -123,17 +123,23 @@ SWIG_InitializeModule(void *clientdata) { if (ret) printf("SWIG_InitializeModule: found cast %s\n", ret->name); #endif } - if (ret && type == swig_module.type_initial[i]) { + if (ret) { + if (type == swig_module.type_initial[i]) { #ifdef SWIGRUNTIME_DEBUG - if (ret) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); + printf("SWIG_InitializeModule: skip old type %s\n", ret->name); #endif - cast->type = ret; - ret = 0; - } else { - /* Fix PyICU and many others */ - ret = 0; + cast->type = ret; + ret = 0; + } else { + /* Check for casting already in the list */ + swig_cast_info *ocast = SWIG_TypeCheck(ret->name, type); +#ifdef SWIGRUNTIME_DEBUG + if (ocast) printf("SWIG_InitializeModule: skip old cast %s\n", ret->name); +#endif + if (!ocast) ret = 0; + } } - + if (!ret) { #ifdef SWIGRUNTIME_DEBUG printf("SWIG_InitializeModule: adding cast %s\n", cast->type->name); @@ -146,11 +152,26 @@ SWIG_InitializeModule(void *clientdata) { } cast++; } - /* Set entry in modules->types array equal to the type */ swig_module.types[i] = type; } swig_module.types[i] = 0; + +#ifdef SWIGRUNTIME_DEBUG + printf("**** SWIG_InitializeModule: Cast List ******\n"); + for (i = 0; i < swig_module.size; ++i) { + int j = 0; + swig_cast_info *cast = swig_module.cast_initial[i]; + printf("SWIG_InitializeModule: type %d %s\n", i, swig_module.type_initial[i]->name); + while (cast->type) { + printf("SWIG_InitializeModule: cast type %s\n", cast->type->name); + cast++; + ++j; + } + printf("---- Total casts: %d\n",j); + } + printf("**** SWIG_InitializeModule: Cast List ******\n"); +#endif } /* This function will propagate the clientdata field of type to