-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix handling of macro with empty argument list #1111
Conversation
CI tests are all green, so it looks like fixing this isn't going to break the world. There's clearly potential for breaking existing user interface files which rely on the current behaviour, but I think we just have to accept that risk (and for 4.0 it seems reasonable) - SWIG really ought to behave like a C/C++ compiler's preprocessor in cases like this (I hit this in a real world example, and I'm struggling to see how to work around it). Please don't merge yet - I want to rework the approach a bit regarding how the empty argument list is represented, and it needs a |
This will be a nice addition. Note that we work around this in places. Will it fix this the closely related empty argument bug too, eg in Lib/shared_ptr.i: // Workaround empty first macro argument bug
#define SWIGEMPTYHACK
// Main user macro for defining shared_ptr typemaps for both const and non-const pointer types
%define %shared_ptr(TYPE...)
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
SWIG_SHARED_PTR_TYPEMAPS(SWIGEMPTYHACK, TYPE)
SWIG_SHARED_PTR_TYPEMAPS(const, TYPE)
%enddef |
It didn't fix that case, but it's related to the bug here and I've pushed an adjustment to the fix which I think should cover this too. Thanks for pointing this out. |
Do you know where we work around the original bug here, or how to locate such places? |
Mmm, probably the only workaround is the first argument bug and not the original no arguments bug in this issue. I have seen the no arguments bug brought up before, but not sure where, possibly in the SF bug tracker. Sorry, that isn't particularly helpful! |
The no arguments bug did seem very vaguely familiar, but I didn't see an open issue here. It seems the sourceforge ticket search is broken currently, and I didn't find anything via google with a suitable |
8f2466a
to
f72dde1
Compare
The first argument was being dropped in this case.
f72dde1
to
55ca36a
Compare
I found https://sourceforge.net/p/swig/bugs/826/ which is about a varargs macro not accepting an empty argument list, and which this change also fixed, so I've added that to the regression test and closed it. |
In the preproc.i testcase: #define FOO2(X) int foo_func2(X);
...
FOO2() gcc, clang and visual c++ preprocessor output is: int foo_func2(); gcc and clang are silent and Visual c++ emits a warning:
SWIG outputs: FOO2() So I think this is another similar case where SWIG ought to follow the compilers, possibly with an 'extra' warning which is suppressed by default unless using |
I'm inclined to think "C4003" is just another pointless MSVC warning and not something we should emulate (unless the C or C++ standard says it's not valid, which I don't have time to check right now). But the testcase isn't working properly and there are some actual bugs: SWIG git master:
GCC and clang:
I guess this is a C testcase and so SWIG is assume Thanks for spotting - I'll work on a fix, though it may be a few days before I have time. Meanwhile I think we can leave the current patch on git master - SWIG 3.0.12 gives this, and git master is either the same or better:
|
SWIG aims to support ANSI/ISO C and I don't recall SWIG attempting to support K&R C where the return type defaults to int if left off. ff(int a); results in a syntax error in SWIG. Agreed the patch should be left as it is provides much better preproc support. |
I thought implicit
But as you say it SWIG doesn't seem to support it (and nobody's complained that I can recall). I wonder why |
The output I quoted above for SWIG is bogus - it's what you get from If I use just the content of that
SWIG 3.0.12 fails with:
Which is good, as that means that part is working as a regression test. SWIG git master gives:
Which matches GCC and clang preprocessed output (if you run them with So it actually looks like the |
Oh good, it all works as it should. Yes, I looked at the preprocessed output and fell into the same trap. A runtime test calling these functions would be a useful enhancement to make sure that it all expands as expected. |
On 13 October 2017 at 19:10, William S Fulton ***@***.***> wrote:
A runtime test calling these functions would be a useful enhancement to make sure that it all expands as expected.
I actually constructed the testcases such that SWIG should fail at the
preprocessor or parser stage if any of the fixes regresses.
Cheers,
Olly
|
SWIG's preprocessor doesn't work quite like the preprocessors in C/C++ compilers (I compared it to GCC and clang) on this example:
Without this patch, SWIG gives:
while GCC and clang give:
Work-in-progress patch currently - I wanted to check it didn't break anything, but locally the testsuite fails due to me having a newer pep8, and I also don't have all the languages installed.