diff --git a/CHANGES.current b/CHANGES.current index 5e7fbbf6e..f39960bc3 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -15,6 +15,11 @@ Version 4.0.0 (in progress) [Python] Replace pep8 with pycodestyle for checking the Python code style when running Python tests. +2017-12-30: davedissian + Fixed a symbol lookup issue when encountering a typedef of a symbol from the tag + namespace to the global namespace when the names are identical, such as 'typedef + struct Foo Foo;'. + 2017-12-13: wsfulton [Perl] add missing support for directorfree typemaps. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index d798a6853..3bcf67c8c 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -491,6 +491,7 @@ CPP_TEST_CASES += \ throw_exception \ typedef_array_member \ typedef_class \ + typedef_classforward_same_name \ typedef_funcptr \ typedef_inherit \ typedef_mptr \ @@ -677,6 +678,7 @@ C_TEST_CASES += \ string_simple \ struct_rename \ struct_initialization \ + typedef_classforward_same_name \ typedef_struct \ typemap_subst \ union_parameter \ diff --git a/Examples/test-suite/java/typedef_classforward_same_name_runme.java b/Examples/test-suite/java/typedef_classforward_same_name_runme.java new file mode 100644 index 000000000..86e713d14 --- /dev/null +++ b/Examples/test-suite/java/typedef_classforward_same_name_runme.java @@ -0,0 +1,26 @@ + +import typedef_classforward_same_name.*; + +public class typedef_classforward_same_name_runme { + + static { + try { + System.loadLibrary("typedef_classforward_same_name"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e); + System.exit(1); + } + } + + public static void main(String argv[]) { + Foo foo = new Foo(); + foo.setX(5); + if (typedef_classforward_same_name.extractFoo(foo) != 5) + throw new RuntimeException("unexpected value"); + + Boo boo = new Boo(); + boo.setX(5); + if (typedef_classforward_same_name.extractBoo(boo) != 5) + throw new RuntimeException("unexpected value"); + } +} diff --git a/Examples/test-suite/python/typedef_classforward_same_name_runme.py b/Examples/test-suite/python/typedef_classforward_same_name_runme.py new file mode 100644 index 000000000..61f45fbee --- /dev/null +++ b/Examples/test-suite/python/typedef_classforward_same_name_runme.py @@ -0,0 +1,11 @@ +from typedef_classforward_same_name import * + +foo = Foo() +foo.x = 5 +if extractFoo(foo) != 5: + raise RuntimeError("unexpected value") + +boo = Boo() +boo.x = 5 +if extractBoo(boo) != 5: + raise RuntimeError("unexpected value") diff --git a/Examples/test-suite/typedef_classforward_same_name.i b/Examples/test-suite/typedef_classforward_same_name.i new file mode 100644 index 000000000..ad2e456f8 --- /dev/null +++ b/Examples/test-suite/typedef_classforward_same_name.i @@ -0,0 +1,15 @@ +%module typedef_classforward_same_name + +%inline %{ +typedef struct Foo Foo; +struct Foo { + int x; +}; +int extractFoo(Foo* foo) { return foo->x; } + +struct Boo { + int x; +}; +typedef struct Boo Boo; +int extractBoo(Boo* boo) { return boo->x; } +%} diff --git a/Source/Modules/lang.cxx b/Source/Modules/lang.cxx index 1e4a6bdb6..3464d2327 100644 --- a/Source/Modules/lang.cxx +++ b/Source/Modules/lang.cxx @@ -3296,6 +3296,14 @@ Node *Language::classLookup(const SwigType *s) const { break; if (Strcmp(nodeType(n), "class") == 0) break; + Node *sibling = n; + while (sibling) { + sibling = Getattr(sibling, "csym:nextSibling"); + if (sibling && Strcmp(nodeType(sibling), "class") == 0) + break; + } + if (sibling) + break; n = parentNode(n); if (!n) break;