Make sure warning and error messages are not split up

They could be split up by other processes writing to stdout
at the same time.
This commit is contained in:
William S Fulton 2017-06-16 19:20:50 +01:00
commit 11aa71b939
2 changed files with 17 additions and 6 deletions

View file

@ -7,6 +7,10 @@ the issue number to the end of the URL: https://github.com/swig/swig/issues/
Version 4.0.0 (in progress)
===========================
2017-06-16: wsfulton
Make sure warning and error messages are not split up by other processes writing to
stdout at the same time.
2017-06-16: wsfulton
[R] Fix wrapping function pointers containing rvalue and lvalue reference parameters.

View file

@ -106,13 +106,16 @@ void Swig_warning(int wnum, const_String_or_char_ptr filename, int line, const c
}
if (warnall || wrn) {
String *formatted_filename = format_filename(filename);
String *full_message = NewString("");
if (wnum) {
Printf(stderr, wrn_wnum_fmt, formatted_filename, line, wnum);
Printf(full_message, wrn_wnum_fmt, formatted_filename, line, wnum);
} else {
Printf(stderr, wrn_nnum_fmt, formatted_filename, line);
Printf(full_message, wrn_nnum_fmt, formatted_filename, line);
}
Printf(stderr, "%s", msg);
Printf(full_message, "%s", msg);
Printv(stderr, full_message, NIL);
nwarning++;
Delete(full_message);
Delete(formatted_filename);
}
Delete(out);
@ -128,6 +131,7 @@ void Swig_warning(int wnum, const_String_or_char_ptr filename, int line, const c
void Swig_error(const_String_or_char_ptr filename, int line, const char *fmt, ...) {
va_list ap;
String *formatted_filename = NULL;
String *full_message = NULL;
if (silence)
return;
@ -136,14 +140,17 @@ void Swig_error(const_String_or_char_ptr filename, int line, const char *fmt, ..
va_start(ap, fmt);
formatted_filename = format_filename(filename);
full_message = NewString("");
if (line > 0) {
Printf(stderr, err_line_fmt, formatted_filename, line);
Printf(full_message, err_line_fmt, formatted_filename, line);
} else {
Printf(stderr, err_eof_fmt, formatted_filename);
Printf(full_message, err_eof_fmt, formatted_filename);
}
vPrintf(stderr, fmt, ap);
vPrintf(full_message, fmt, ap);
Printv(stderr, full_message, NIL);
va_end(ap);
nerrors++;
Delete(full_message);
Delete(formatted_filename);
}