mirror of https://github.com/swig/swig
Fix handling of corner cases by previous change
Don't collapse runs of whitespace to a single space, instead replace each whitespace with one space. Leave the expression as-is if it contains one or more double quotes as we don't want to change the value of string literals, and any expression containing double quotes won't currently work in the context where we need to replace newlines anyway. Fixes #3127 better
This commit is contained in:
parent
4a0372aacc
commit
6dbf867d23
|
@ -67,3 +67,5 @@ public:
|
|||
|
||||
%constant int WSTRING_LIT_LEN1 = (sizeof(L"1234")/sizeof(wchar_t) - 1);
|
||||
%constant int WSTRING_LIT_LEN2 = (sizeof(L"12" L"34")/sizeof(wchar_t) - 1);
|
||||
%constant int WSTRING_LIT_LEN3 = (sizeof(L"12\
|
||||
" "34")/sizeof(wchar_t) - 1);
|
||||
|
|
|
@ -59,12 +59,12 @@ int yy() { return YY; }
|
|||
*/
|
||||
const int s1a = sizeof(X); /* worked before 4.1.0 */
|
||||
//const int s1b = sizeof X; /* not currently supported */
|
||||
const int s2a = sizeof("a string" );
|
||||
const int s2b = sizeof "a string";
|
||||
const int s2a = sizeof("a string" );
|
||||
const int s2b = sizeof "a string";
|
||||
const int s3a = sizeof('c');
|
||||
const int s3b = sizeof('c');
|
||||
const int s4a = sizeof(L"a wstring");
|
||||
const int s4b = sizeof L"a wstring";
|
||||
const int s4a = sizeof(L"a wstring");
|
||||
const int s4b = sizeof L"a wstring";
|
||||
const int s5a = sizeof(L'C');
|
||||
const int s5b = sizeof L'C';
|
||||
const int s6a = sizeof(sizeof(X));
|
||||
|
|
|
@ -12,4 +12,9 @@ check::globals(array('X','d_array','s1a','s2a','s2b','s3a','s3b','s4a','s4b','s5
|
|||
check::equal(XX, xx());
|
||||
check::equal(YY, yy());
|
||||
|
||||
check::equal(s2a_get(), 10);
|
||||
check::equal(s2b_get(), 10);
|
||||
check::equal(s4a_get(), 11 * s5a_get());
|
||||
check::equal(s4b_get(), 11 * s5b_get());
|
||||
|
||||
check::done();
|
||||
|
|
|
@ -17,5 +17,6 @@ check::equal(constant_expr::YY, constant_expr::yy());
|
|||
|
||||
check::equal(WSTRING_LIT_LEN1, 4);
|
||||
check::equal(WSTRING_LIT_LEN2, 4);
|
||||
check::equal(WSTRING_LIT_LEN3, 4);
|
||||
|
||||
check::done();
|
||||
|
|
|
@ -1913,21 +1913,25 @@ static SwigType *deduce_type(const struct Define *dtype) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
// Append scanner_ccode to expr, normalising runs of whitespace to a single
|
||||
// space (in particular newlines are problematic in the generated
|
||||
// swig_type_info).
|
||||
// Append scanner_ccode to expr. Some cleaning up of the code may be done.
|
||||
static void append_expr_from_scanner(String *expr) {
|
||||
int len = Len(scanner_ccode);
|
||||
int in_space = 0;
|
||||
for (int i = 0; i < len; ++i) {
|
||||
char ch = Char(scanner_ccode)[i];
|
||||
if (isspace((unsigned char)ch)) {
|
||||
if (!in_space) Putc(' ', expr);
|
||||
in_space = 1;
|
||||
} else {
|
||||
if (Strchr(scanner_ccode, '"') == NULL) {
|
||||
// Append scanner_ccode, changing any whitespace character to a space.
|
||||
int len = Len(scanner_ccode);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
char ch = Char(scanner_ccode)[i];
|
||||
if (isspace((unsigned char)ch)) ch = ' ';
|
||||
Putc(ch, expr);
|
||||
in_space = 0;
|
||||
}
|
||||
} else {
|
||||
// The code contains a double quote so leave it be as changing a
|
||||
// backslash-escaped linefeed character (i.e. `\` followed by byte 0x0a)
|
||||
// in a string literal into a space will insert a space into the string
|
||||
// literal's value. An expression containing a double quote won't work if
|
||||
// used in a context where a swig_type_info is generated as the typename
|
||||
// gets substituted into a string literal without any escaping which will
|
||||
// result in invalid code due to the double quotes.
|
||||
Append(expr, scanner_ccode);
|
||||
}
|
||||
Clear(scanner_ccode);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue