diff options
author | William S Fulton <wsf@fultondesigns.co.uk> | 2011-02-13 13:53:14 +0000 |
---|---|---|
committer | William S Fulton <wsf@fultondesigns.co.uk> | 2011-02-13 13:53:14 +0000 |
commit | e0ee14c3ba28a2ca4a053f7cd4e2d5e2827fb504 (patch) | |
tree | 229f66628f1d7e35d35c16def1d0d2e240e5e002 | |
parent | ac42dd8153d723f78cd7ccfdace16a1b02214eeb (diff) | |
download | swig-e0ee14c3ba28a2ca4a053f7cd4e2d5e2827fb504.tar.gz |
Fix Fix #1927852 - #include directives don't preprocess the file passed to it
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12457 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r-- | CHANGES.current | 6 | ||||
-rw-r--r-- | Examples/test-suite/common.mk | 2 | ||||
-rw-r--r-- | Examples/test-suite/preproc_include.i | 18 | ||||
-rw-r--r-- | Examples/test-suite/preproc_include_a.h | 3 | ||||
-rw-r--r-- | Examples/test-suite/preproc_include_b.h | 7 | ||||
-rw-r--r-- | Examples/test-suite/preproc_include_c.h | 3 | ||||
-rw-r--r-- | Examples/test-suite/python/preproc_include_runme.py | 11 | ||||
-rw-r--r-- | Source/Preprocessor/cpp.c | 29 |
8 files changed, 72 insertions, 7 deletions
diff --git a/CHANGES.current b/CHANGES.current index 23805145e..726033532 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,12 @@ See the RELEASENOTES file for a summary of changes in each release. Version 2.0.2 (in progress) =========================== +2011-02-13: wsfulton + Fix #1927852 #include directives don't preprocess the file passed to it. The fix is for + #include with -importall or -includeall, %include and %import, for example: + #define FILENAME "abc.h" + %include FILENAME + 2011-02-12: wsfulton Fix #1940536, overactive preprocessor which was expanding defined(...) outside of #if and #elif preprocessor directives. diff --git a/Examples/test-suite/common.mk b/Examples/test-suite/common.mk index ad2a91c7c..5f3012091 100644 --- a/Examples/test-suite/common.mk +++ b/Examples/test-suite/common.mk @@ -494,6 +494,7 @@ C_TEST_CASES += \ preproc \ preproc_constants_c \ preproc_defined \ + preproc_include \ preproc_line_file \ ret_by_value \ simple_array \ @@ -518,6 +519,7 @@ MULTI_CPP_TEST_CASES += \ # Custom tests - tests with additional commandline options wallkw.cpptest: SWIGOPT += -Wallkw +preproc_include.ctest: SWIGOPT += -includeall NOT_BROKEN_TEST_CASES = $(CPP_TEST_CASES:=.cpptest) \ diff --git a/Examples/test-suite/preproc_include.i b/Examples/test-suite/preproc_include.i new file mode 100644 index 000000000..c6b08b5fd --- /dev/null +++ b/Examples/test-suite/preproc_include.i @@ -0,0 +1,18 @@ +%module preproc_include + +%{ +#include "preproc_include_a.h" +#include "preproc_include_b.h" +int multiply10(int a) { return a*10; } +int multiply20(int a) { return a*20; } +int multiply30(int a) { return a*30; } +%} + +#define INCLUDE_B preproc_include_b.h +#define FILE_INCLUDE(FNAME) #FNAME + +%include FILE_INCLUDE(preproc_include_a.h) + +// Note that this test uses -includeall, so including preproc_include_b.h also includes preproc_include_c.h +%include INCLUDE_B + diff --git a/Examples/test-suite/preproc_include_a.h b/Examples/test-suite/preproc_include_a.h new file mode 100644 index 000000000..b6b55d90d --- /dev/null +++ b/Examples/test-suite/preproc_include_a.h @@ -0,0 +1,3 @@ + +int multiply10(int a); + diff --git a/Examples/test-suite/preproc_include_b.h b/Examples/test-suite/preproc_include_b.h new file mode 100644 index 000000000..b7cfd530e --- /dev/null +++ b/Examples/test-suite/preproc_include_b.h @@ -0,0 +1,7 @@ + +int multiply20(int a); + +#define PREPROC_INCLUDE_C "preproc_include_c.h" + +#include PREPROC_INCLUDE_C + diff --git a/Examples/test-suite/preproc_include_c.h b/Examples/test-suite/preproc_include_c.h new file mode 100644 index 000000000..18f9084a4 --- /dev/null +++ b/Examples/test-suite/preproc_include_c.h @@ -0,0 +1,3 @@ + +int multiply30(int a); + diff --git a/Examples/test-suite/python/preproc_include_runme.py b/Examples/test-suite/python/preproc_include_runme.py new file mode 100644 index 000000000..e15606581 --- /dev/null +++ b/Examples/test-suite/python/preproc_include_runme.py @@ -0,0 +1,11 @@ +import preproc_include + +if preproc_include.multiply10(10) != 100: + raise RuntimeError + +if preproc_include.multiply20(10) != 200: + raise RuntimeError + +if preproc_include.multiply30(10) != 300: + raise RuntimeError + diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c index 1e7548058..2da4944c9 100644 --- a/Source/Preprocessor/cpp.c +++ b/Source/Preprocessor/cpp.c @@ -643,7 +643,7 @@ unterm: } /* ----------------------------------------------------------------------------- - * DOH *get_filename(DOH *str) + * DOH *get_filename() * * Read a filename from str. A filename can be enclosed in quotes, angle brackets, * or bare. @@ -1656,12 +1656,14 @@ String *Preprocessor_parse(String *s) { String *s1, *s2, *fn; char *dirname; int sysfile = 0; + String *filename_processed; if (include_all && import_all) { Swig_warning(WARN_PP_INCLUDEALL_IMPORTALL, Getfile(s), Getline(id), "Both includeall and importall are defined: using includeall\n"); import_all = 0; } - Seek(value, 0, SEEK_SET); - fn = get_filename(value, &sysfile); + filename_processed = Preprocessor_replace(value); + Seek(filename_processed, 0, SEEK_SET); + fn = get_filename(filename_processed, &sysfile); s1 = cpp_include(fn, sysfile); if (s1) { if (include_all) @@ -1787,11 +1789,13 @@ String *Preprocessor_parse(String *s) { Ungetc(c, s); /* Look for common SWIG directives */ if (Equal(decl, kpp_dinclude) || Equal(decl, kpp_dimport) || Equal(decl, kpp_dextern)) { - /* Got some kind of file inclusion directive */ + /* Got some kind of file inclusion directive, eg: %import(option1="value1") "filename" */ if (allow) { DOH *s1, *s2, *fn, *opt; - String *options_whitespace = NewString(""); - String *filename_whitespace = NewString(""); + String *options_whitespace = NewStringEmpty(); + String *filename_whitespace = NewStringEmpty(); + String *filename_unprocessed = NewStringEmpty(); + String *filename_processed; int sysfile = 0; if (Equal(decl, kpp_dextern)) { @@ -1801,8 +1805,17 @@ String *Preprocessor_parse(String *s) { } skip_whitespace(s, options_whitespace); opt = get_options(s); + skip_whitespace(s, filename_whitespace); - fn = get_filename(s, &sysfile); + copy_location(s, filename_unprocessed); + while (((c = Getc(s)) != EOF) && (!isspace(c))) + Putc(c, filename_unprocessed); + if (isspace(c)) + Ungetc(c, s); + filename_processed = Preprocessor_replace(filename_unprocessed); + Seek(filename_processed, 0, SEEK_SET); + + fn = get_filename(filename_processed, &sysfile); s1 = cpp_include(fn, sysfile); if (s1) { char *dirname; @@ -1832,6 +1845,8 @@ String *Preprocessor_parse(String *s) { Delete(s1); } Delete(fn); + Delete(filename_processed); + Delete(filename_unprocessed); Delete(filename_whitespace); Delete(options_whitespace); } |