From 6b2bcfed0b1c8b0ed87d92ce492651c2325e067b Mon Sep 17 00:00:00 2001 From: David Avedissian Date: Wed, 27 Dec 2017 16:31:16 +0000 Subject: [PATCH 1/3] Added test case for a forward declaration in a typedef with the same name --- Examples/test-suite/common.mk | 2 ++ .../typedef_classforward_same_name_runme.java | 22 +++++++++++++++++++ .../typedef_classforward_same_name.i | 9 ++++++++ 3 files changed, 33 insertions(+) create mode 100644 Examples/test-suite/java/typedef_classforward_same_name_runme.java create mode 100644 Examples/test-suite/typedef_classforward_same_name.i diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index db9b13433..7a2136639 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -490,6 +490,7 @@ CPP_TEST_CASES += \ throw_exception \ typedef_array_member \ typedef_class \ + typedef_classforward_same_name \ typedef_funcptr \ typedef_inherit \ typedef_mptr \ @@ -676,6 +677,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..23a06b913 --- /dev/null +++ b/Examples/test-suite/java/typedef_classforward_same_name_runme.java @@ -0,0 +1,22 @@ + +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.extract(foo) == 5) { + // All good! + } + } +} \ No newline at end of file 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..15e29c693 --- /dev/null +++ b/Examples/test-suite/typedef_classforward_same_name.i @@ -0,0 +1,9 @@ +%module typedef_classforward_same_name + +%inline %{ +typedef struct Foo Foo; +struct Foo { + int x; +}; +int extract(Foo* foo) { return foo->x; } +%} \ No newline at end of file From 3617e22fda7b276d727c24452250e64871d4117c Mon Sep 17 00:00:00 2001 From: David Avedissian Date: Sun, 31 Dec 2017 00:23:51 +0000 Subject: [PATCH 2/3] Fixed 'typedef class Foo Foo;' edge case by iterating through linked list. Suggested fix by wsfulton --- CHANGES.current | 5 +++++ Source/Modules/lang.cxx | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index 1c361fbec..3b5bb3f85 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,11 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +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/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; From ce6960de9261f08bb653400555254f7dc01ca663 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Sun, 31 Dec 2017 16:25:55 +0000 Subject: [PATCH 3/3] Add more runtime typedef_classforward_same_name runtime testing --- .../java/typedef_classforward_same_name_runme.java | 12 ++++++++---- .../python/typedef_classforward_same_name_runme.py | 11 +++++++++++ Examples/test-suite/typedef_classforward_same_name.i | 10 ++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 Examples/test-suite/python/typedef_classforward_same_name_runme.py diff --git a/Examples/test-suite/java/typedef_classforward_same_name_runme.java b/Examples/test-suite/java/typedef_classforward_same_name_runme.java index 23a06b913..86e713d14 100644 --- a/Examples/test-suite/java/typedef_classforward_same_name_runme.java +++ b/Examples/test-suite/java/typedef_classforward_same_name_runme.java @@ -15,8 +15,12 @@ public class typedef_classforward_same_name_runme { public static void main(String argv[]) { Foo foo = new Foo(); foo.setX(5); - if (typedef_classforward_same_name.extract(foo) == 5) { - // All good! - } + 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"); } -} \ No newline at end of file +} 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 index 15e29c693..ad2e456f8 100644 --- a/Examples/test-suite/typedef_classforward_same_name.i +++ b/Examples/test-suite/typedef_classforward_same_name.i @@ -5,5 +5,11 @@ typedef struct Foo Foo; struct Foo { int x; }; -int extract(Foo* foo) { return foo->x; } -%} \ No newline at end of file +int extractFoo(Foo* foo) { return foo->x; } + +struct Boo { + int x; +}; +typedef struct Boo Boo; +int extractBoo(Boo* boo) { return boo->x; } +%}