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.
This commit is contained in:
Olly Betts 2023-04-19 15:50:56 +12:00
parent 043bdf5677
commit 6f15b1419a
2 changed files with 22 additions and 15 deletions

View File

@ -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
%}

View File

@ -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