From 624ec3e1b7dd8908b37ee86bce6f60423c915bc5 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 25 Apr 2017 07:09:18 +0100 Subject: [PATCH 1/2] Fix bug with comments inline in macros - commit fixes #974 --- Source/Preprocessor/cpp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 12d27c316..491eb8a96 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -607,6 +607,23 @@ static List *find_args(String *s, int ismacro, String *macro_name) { skip_tochar(s, '\'', str); c = Getc(s); continue; + } else if (c == '/') { + /* Ensure comments are ignored by eating up the characters */ + c = Getc(s); + if (c == '*') { + while ((c = Getc(s)) != EOF) { + if (c == '*') { + c = Getc(s); + if (c == '/' || c == EOF) + break; + } + } + c = Getc(s); + continue; + } + /* ensure char is available in the stream as this was not a comment*/ + Ungetc(c, s); + c = '/'; } if ((c == ',') && (level == 0)) break; From 956495dd47d3f1eec5da67befbf76b3ec79b5489 Mon Sep 17 00:00:00 2001 From: William S Fulton Date: Thu, 27 Apr 2017 19:45:19 +0100 Subject: [PATCH 2/2] Add testcase for macros with commas in comment --- CHANGES.current | 3 +++ Examples/test-suite/preproc.i | 17 +++++++++++++++++ Examples/test-suite/python/preproc_runme.py | 3 +++ 3 files changed, 23 insertions(+) diff --git a/CHANGES.current b/CHANGES.current index f01a29b96..1513eb33a 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.0.0 (in progress) =========================== +2017-04-27: redbrain + Issue #974, Patch #976 - Fix preprocessor handling of macros with commas in a comment. + 2017-04-21: tamuratak [Ruby] #964 - Add shared_ptr director typemaps. diff --git a/Examples/test-suite/preproc.i b/Examples/test-suite/preproc.i index f236bfdff..8ed8c1a09 100644 --- a/Examples/test-suite/preproc.i +++ b/Examples/test-suite/preproc.i @@ -370,3 +370,20 @@ int methodX(int x); int methodX(int x) { return x+100; } %} +// Comma in macro - Github issue #974 +%inline %{ +#define __attribute__(x) +#define TCX_PACKED(d) d __attribute__ ((__packed__)) + +TCX_PACKED (typedef struct tcxMessageTestImpl +{ + int mHeader; /**< comment */ +}) tcxMessageTest; + + +TCX_PACKED (typedef struct tcxMessageBugImpl +{ + int mBid; /**< Bid price and size, check PresentMap if available in message */ +}) tcxMessageBug; +%} + diff --git a/Examples/test-suite/python/preproc_runme.py b/Examples/test-suite/python/preproc_runme.py index 99a6d0307..071362bc3 100644 --- a/Examples/test-suite/python/preproc_runme.py +++ b/Examples/test-suite/python/preproc_runme.py @@ -14,3 +14,6 @@ if 2 * preproc.one != preproc.two: if preproc.methodX(99) != 199: raise RuntimeError + +t1 = preproc.tcxMessageTest() +t2 = preproc.tcxMessageBug()