summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam S Fulton <wsf@fultondesigns.co.uk>2010-09-10 06:08:45 +0000
committerWilliam S Fulton <wsf@fultondesigns.co.uk>2010-09-10 06:08:45 +0000
commit122bc852f98500360c9d7d920bf3bee220085770 (patch)
treed52d2337dbc92cb57bc692e39d7215a33d9af9c9
parentf6cd7912e324cdf2633a3e4e0c626a26f627be96 (diff)
downloadswig-122bc852f98500360c9d7d920bf3bee220085770.tar.gz
Fix #2149523 - Incorrect line number reporting in errors after parsing macros. Remove extraneous extra line in preprocessed output which would sometimes lead to error/warning messages two lines after the end of the file
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12211 626c5289-ae23-0410-ae9c-e8d60b6d4f22
-rw-r--r--CHANGES.current9
-rwxr-xr-xExamples/test-suite/errors/make.sh6
-rw-r--r--Examples/test-suite/errors/pp_constant.i43
-rw-r--r--Examples/test-suite/errors/pp_macro_inline_unterminated.i11
-rw-r--r--Source/Preprocessor/cpp.c11
-rw-r--r--Source/Swig/include.c2
6 files changed, 73 insertions, 9 deletions
diff --git a/CHANGES.current b/CHANGES.current
index 660e73eeb..227f5218c 100644
--- a/CHANGES.current
+++ b/CHANGES.current
@@ -5,6 +5,15 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 2.0.1 (in progress)
===========================
+2010-09-10: wsfulton
+ Remove extraneous extra line in preprocessed output after including files
+ which would sometimes lead to error/warning messages two lines after the
+ end of the file.
+
+2010-09-10: wsfulton
+ Fix #2149523 - Incorrect line number reporting in errors after parsing macros
+ containing C++ comments.
+
2010-09-08: olly
[PHP] Fix handling of OUTPUT typemaps (Patch from Ryan in SF#3058394).
diff --git a/Examples/test-suite/errors/make.sh b/Examples/test-suite/errors/make.sh
index 3b58d6ab0..45c5c1733 100755
--- a/Examples/test-suite/errors/make.sh
+++ b/Examples/test-suite/errors/make.sh
@@ -26,13 +26,15 @@ c_varargs
c_varargs_neg
nomodule
pp_badeval
-pp_deprecated
+pp_constant
pp_defined
-pp_macro_defined_unterminated
+pp_deprecated
pp_illegal_argument
pp_macro_args
pp_macro_badchar
+pp_macro_defined_unterminated
pp_macro_expansion
+pp_macro_inline_unterminated
pp_macro_nargs
pp_macro_redef
pp_macro_rparen
diff --git a/Examples/test-suite/errors/pp_constant.i b/Examples/test-suite/errors/pp_constant.i
new file mode 100644
index 000000000..84846f1c5
--- /dev/null
+++ b/Examples/test-suite/errors/pp_constant.i
@@ -0,0 +1,43 @@
+%module xxx
+
+/* Test preprocessor comments and their effect on line number reporting on later errors */
+
+#define A1 1234
+#define A2 1234 /*C comment*/
+#define A3 1234
+
+%constant int aaa=;
+
+#define B1 1234
+#define B2 1234 //C++ comment
+#define B3 1234
+
+%constant int bbb=;
+
+#define C1 1234
+#define C2 1234 /*multiline
+C
+comment */
+#define C3 1234
+
+%constant int ccc=;
+
+#define D1 1234
+#define /*C Comment*/ D2 1234
+#define D3 1234
+
+%constant int ddd=;
+
+#define E1 1234
+#/*C comment*/define E2 1234
+#define E3 1234
+
+%constant int eee=;
+
+#define F1 1234
+#define F2 1234 \
+// C comment
+#define F3 1234
+
+%constant int fff=;
+
diff --git a/Examples/test-suite/errors/pp_macro_inline_unterminated.i b/Examples/test-suite/errors/pp_macro_inline_unterminated.i
new file mode 100644
index 000000000..67de0942c
--- /dev/null
+++ b/Examples/test-suite/errors/pp_macro_inline_unterminated.i
@@ -0,0 +1,11 @@
+%module xxx
+
+%define foo(a,x)
+int ii;
+%enddef
+
+%inline %{
+struct Struct {
+foo(2,
+};
+%}
diff --git a/Source/Preprocessor/cpp.c b/Source/Preprocessor/cpp.c
index b4866ee9c..bb56c21d2 100644
--- a/Source/Preprocessor/cpp.c
+++ b/Source/Preprocessor/cpp.c
@@ -1445,15 +1445,14 @@ String *Preprocessor_parse(String *s) {
state = 43;
}
break;
- case 46:
+ case 46: /* in C++ comment */
if (c == '\n') {
Ungetc(c, s);
- cpp_lines++;
state = 50;
} else
Putc(c, comment);
break;
- case 47:
+ case 47: /* in C comment */
if (c == '*')
state = 48;
else
@@ -1638,7 +1637,7 @@ String *Preprocessor_parse(String *s) {
}
s2 = Preprocessor_parse(s1);
addline(ns, s2, allow);
- Append(ns, "\n]");
+ Append(ns, "]");
if (dirname) {
Swig_pop_directory();
}
@@ -1784,7 +1783,7 @@ String *Preprocessor_parse(String *s) {
pop_imported();
}
addline(ns, s2, allow);
- Append(ns, "\n]");
+ Append(ns, "]");
Delete(s2);
Delete(s1);
}
@@ -1845,7 +1844,6 @@ String *Preprocessor_parse(String *s) {
Seek(value, 0, SEEK_SET);
Preprocessor_define(value, 1);
}
- /* Putc('\n',ns); */
addline(ns, value, 0);
state = 0;
}
@@ -1884,6 +1882,5 @@ String *Preprocessor_parse(String *s) {
Delete(comment);
Delete(chunk);
- /* fprintf(stderr,"cpp: %d\n", Len(Getattr(cpp,"symbols"))); */
return ns;
}
diff --git a/Source/Swig/include.c b/Source/Swig/include.c
index baae44bb8..e3f256901 100644
--- a/Source/Swig/include.c
+++ b/Source/Swig/include.c
@@ -221,6 +221,8 @@ String *Swig_read_file(FILE *f) {
Append(str, buffer);
}
len = Len(str);
+ /* Add a newline if not present on last line -- the preprocessor seems to
+ * rely on \n and not EOF terminating lines */
if (len) {
char *cstr = Char(str);
if (cstr[len - 1] != '\n') {