From c39a3799423a095df98d7bd44d1ce4ecec6d8eb1 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Mon, 20 Aug 2018 19:21:14 +0100 Subject: [PATCH] Add testcase for nested C struct name conflict Issue #1305 --- CHANGES.current | 4 ++ Examples/test-suite/nested.i | 46 ++++++++++++++++++++++ Examples/test-suite/python/nested_runme.py | 20 ++++++++++ 3 files changed, 70 insertions(+) create mode 100644 Examples/test-suite/python/nested_runme.py diff --git a/CHANGES.current b/CHANGES.current index 1ced20389..a26205560 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/ Version 4.0.0 (in progress) =========================== +2018-08-20: wkalinin + #1305 Fix nested structure symbol tables in C mode to fix member name conflicts + in different structs with the same nested struct member name. + 2018-08-12: gmazzamuto [Python] #1283 Update pybuffer.i library to use new-style Python buffer C API. diff --git a/Examples/test-suite/nested.i b/Examples/test-suite/nested.i index 216ee4224..2e6d2786f 100644 --- a/Examples/test-suite/nested.i +++ b/Examples/test-suite/nested.i @@ -114,4 +114,50 @@ typedef struct OutSt { #endif +%inline %{ + typedef struct { + union x_union { + int x; + } duplicate_p; + } x_t; + + typedef struct { + union y_union { + int y; + } duplicate_p; + } y_t; + + typedef struct A { + union a_union { + int a; + } duplicate_p; + } a_t; + + typedef struct B { + union b_union { + int b; + } duplicate_p; + } b_t; + + typedef struct { + union { + int c; + } duplicate_p; + } c_t; + + typedef struct { + union { + int d; + } duplicate_p; + } d_t; + + void set_union_values(int startval, x_t *x, y_t *y, a_t *a, b_t *b, c_t *c, d_t *d) { + x->duplicate_p.x = startval++; + y->duplicate_p.y = startval++; + a->duplicate_p.a = startval++; + b->duplicate_p.b = startval++; + c->duplicate_p.c = startval++; + d->duplicate_p.d = startval++; + } +%} diff --git a/Examples/test-suite/python/nested_runme.py b/Examples/test-suite/python/nested_runme.py new file mode 100644 index 000000000..0e839e64b --- /dev/null +++ b/Examples/test-suite/python/nested_runme.py @@ -0,0 +1,20 @@ +from nested import * + +def check(a, b): + if a != b: + raise RuntimeError("Problem: {} != {}".format(a, b)) +xx = x_t() +yy = y_t() +aa = a_t() +bb = b_t() +cc = c_t() +dd = d_t() + +set_union_values(100, xx, yy, aa, bb, cc, dd) + +check(xx.duplicate_p.x, 100) +check(yy.duplicate_p.y, 101) +check(aa.duplicate_p.a, 102) +check(bb.duplicate_p.b, 103) +check(cc.duplicate_p.c, 104) +check(dd.duplicate_p.d, 105)