From 65be8812959aa0d2e9805e31549bbeac0cc89691 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Fri, 5 May 2023 23:23:42 +0100 Subject: Partial revert of previous commit for typedefs Setting current symbol table for a typedef seems wrong. No difference to test-suite though. Testcase rename for C++11 testing and minor adjustments. Issue #2550 Closes #2551 --- CHANGES.current | 3 +++ Examples/test-suite/common.mk | 1 + Examples/test-suite/cpp11_using_typedef_struct.i | 21 +++++++++++++++++++++ .../javascript/cpp11_using_typedef_struct_runme.js | 13 +++++++++++++ .../javascript/struct_typedef_namespace_runme.js | 7 ------- Examples/test-suite/struct_typedef_namespace.i | 21 --------------------- Source/Swig/symbol.c | 8 +++----- 7 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 Examples/test-suite/cpp11_using_typedef_struct.i create mode 100644 Examples/test-suite/javascript/cpp11_using_typedef_struct_runme.js delete mode 100644 Examples/test-suite/javascript/struct_typedef_namespace_runme.js delete mode 100644 Examples/test-suite/struct_typedef_namespace.i diff --git a/CHANGES.current b/CHANGES.current index 15398ef7c..f7840a92b 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,9 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.2.0 (in progress) =========================== +2023-04-06: mmomtchev, wsfulton + #2550 Fix typedef/using declarations to a typedef struct/class. + 2023-04-23: olly [Javascript] #2453 The testsuite and examples now select which Javascript engine to test based on what was detected by configure. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index eb80977f7..c781bd930 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -636,6 +636,7 @@ CPP11_TEST_CASES += \ cpp11_uniform_initialization \ cpp11_unrestricted_unions \ cpp11_userdefined_literals \ + cpp11_using_typedef_struct \ cpp11_variadic_function_templates \ cpp11_variadic_templates \ diff --git a/Examples/test-suite/cpp11_using_typedef_struct.i b/Examples/test-suite/cpp11_using_typedef_struct.i new file mode 100644 index 000000000..81efdc310 --- /dev/null +++ b/Examples/test-suite/cpp11_using_typedef_struct.i @@ -0,0 +1,21 @@ +%module cpp11_using_typedef_struct + +%inline +%{ +namespace nspace1 { + typedef struct _xAffineMatrix { + int x, y, z; + } AffineMatrix; + + struct _xCacheView { + int x; + }; + typedef struct _xCacheView CacheView; +} + +using nspace1::AffineMatrix; +using nspace1::CacheView; + +int fn1(AffineMatrix a) { return a.x; }; +int fn2(CacheView a) { return a.x; }; +%} diff --git a/Examples/test-suite/javascript/cpp11_using_typedef_struct_runme.js b/Examples/test-suite/javascript/cpp11_using_typedef_struct_runme.js new file mode 100644 index 000000000..43a26ddcd --- /dev/null +++ b/Examples/test-suite/javascript/cpp11_using_typedef_struct_runme.js @@ -0,0 +1,13 @@ +var cpp11_using_typedef_struct = require("cpp11_using_typedef_struct"); + +var b = new cpp11_using_typedef_struct.AffineMatrix(); +b.x = b.y = b.z = 1; + +if (cpp11_using_typedef_struct.fn1(b) != b.x) + throw new Error('failed'); + +var bb = new cpp11_using_typedef_struct._xCacheView(); +bb.x = 123; + +if (cpp11_using_typedef_struct.fn2(bb) != 123) + throw new Error('failed'); diff --git a/Examples/test-suite/javascript/struct_typedef_namespace_runme.js b/Examples/test-suite/javascript/struct_typedef_namespace_runme.js deleted file mode 100644 index 4f142121b..000000000 --- a/Examples/test-suite/javascript/struct_typedef_namespace_runme.js +++ /dev/null @@ -1,7 +0,0 @@ -var struct_typedef_namespace = require("struct_typedef_namespace"); - -var b = new struct_typedef_namespace.AffineMatrix(); -b.x = b.y = b.z = 1; - -if (struct_typedef_namespace.fn1(b) != b.x) - throw new Error('failed'); diff --git a/Examples/test-suite/struct_typedef_namespace.i b/Examples/test-suite/struct_typedef_namespace.i deleted file mode 100644 index 921d50236..000000000 --- a/Examples/test-suite/struct_typedef_namespace.i +++ /dev/null @@ -1,21 +0,0 @@ -%module typedefs - -%inline -%{ -namespace nspace1 { - typedef struct _AffineMatrix { - int x, y, z; - } AffineMatrix; - - struct _CacheView { - int x; - }; - typedef struct _CacheView CacheView; -} - -using nspace1::AffineMatrix; -using nspace1::CacheView; - -int fn1(AffineMatrix a) { return a.x; }; -int fn2(CacheView a) { return a.x; }; -%} \ No newline at end of file diff --git a/Source/Swig/symbol.c b/Source/Swig/symbol.c index 934e1ed9e..8e24c9ec7 100644 --- a/Source/Swig/symbol.c +++ b/Source/Swig/symbol.c @@ -839,13 +839,11 @@ Node *Swig_symbol_add(const_String_or_char_ptr symname, Node *n) { /* Hmmm. This appears to be okay. Make sure the symbol table refers to the allow_type node */ - Setattr(current, symname, td); - if (td != c) { - Setattr(td, "sym:symtab", current_symtab); - Setattr(td, "sym:name", symname); - } Setattr(n, "sym:symtab", current_symtab); Setattr(n, "sym:name", symname); + if (td == n) { + Setattr(current, symname, td); + } return n; } -- cgit v1.2.1