summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2023-04-19 15:50:56 +1200
committerOlly Betts <olly@survex.com>2023-04-19 15:50:56 +1200
commit6f15b1419ae0bb3a29c529f28c315cfd0aa5cd43 (patch)
treef27a741bd324c25d0f6add96c5bab80acb4e66b9
parent043bdf567756e6a30dd1e62bef10607d28a3db91 (diff)
downloadswig-6f15b1419ae0bb3a29c529f28c315cfd0aa5cd43.tar.gz
Adjust new tests
Add a regression test based on https://sourceforge.net/p/swig/bugs/1163/ since this patch solves that case too. Replace the __attribute__ test case from #2525 with a variant of the 1163 regression test, since __attribute__ is specific to certain compilers. Adjust the self-referential test case to actually work - it wasn't valid C code before.
-rw-r--r--Examples/test-suite/preproc_defined.i25
-rw-r--r--Examples/test-suite/python/preproc_defined_runme.py12
2 files changed, 22 insertions, 15 deletions
diff --git a/Examples/test-suite/preproc_defined.i b/Examples/test-suite/preproc_defined.i
index de654df36..401666806 100644
--- a/Examples/test-suite/preproc_defined.i
+++ b/Examples/test-suite/preproc_defined.i
@@ -124,29 +124,30 @@ void another_macro_checking(void) {
# wobble wobble
#endif
-#define __attribute__(x)
-%inline %{
-/*
- * This should not compile in when this bug is present
- * https://github.com/swig/swig/issues/2525
+/* Regression test for https://sourceforge.net/p/swig/bugs/1163/
+ * ONE(1)(2) should expand to `2` but SWIG was expanding it to `TWO(2)`
+ * which results in the generated C wrapper failing to compile.
*/
-#define my_bad_attr __attribute__
-#define my_good_attr(x) __attribute__(x)
-
-int bad my_bad_attr((used));
-int good my_good_attr((used));
+#define ONE(X) TWO
+#define TWO(X) X
+%constant int a = ONE(1)(2);
+#define XXX TWO
+%constant int b = XXX(42);
+#undef ONE
+#undef TWO
/*
* The behaviour of Self-Referential Macros is defined
* https://gcc.gnu.org/onlinedocs/gcc-4.8.5/cpp/Self-Referential-Macros.html
*/
+%inline %{
int y = 0;
+%}
#define x (4 + y)
#define y (2 * x)
-int z = y;
+%constant int z = y;
#undef y
#undef x
-%}
diff --git a/Examples/test-suite/python/preproc_defined_runme.py b/Examples/test-suite/python/preproc_defined_runme.py
index 4be937b8d..37441db52 100644
--- a/Examples/test-suite/python/preproc_defined_runme.py
+++ b/Examples/test-suite/python/preproc_defined_runme.py
@@ -3,12 +3,18 @@ import preproc_defined
if preproc_defined.call_checking() != 1:
raise RuntimeError
-if preproc_defined.y != 8:
- raise RuntimeError()
-
d = preproc_defined.Defined()
d.defined = 10
preproc_defined.thing(10)
preproc_defined.stuff(10)
preproc_defined.bumpf(10)
+
+if preproc_defined.a != 2:
+ raise RuntimeError
+
+if preproc_defined.b != 42:
+ raise RuntimeError
+
+if preproc_defined.z != 8:
+ raise RuntimeError