Fix #1940536, overactive preprocessor which was expanding defined(...) outside of #if and #elif preprocessor directives.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12441 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
65f377c422
commit
63af0a2d72
5 changed files with 54 additions and 4 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
|||
Version 2.0.2 (in progress)
|
||||
===========================
|
||||
|
||||
2011-02-07: wsfulton
|
||||
Fix #1940536, overactive preprocessor which was expanding defined(...) outside of #if and #elif
|
||||
preprocessor directives.
|
||||
|
||||
2011-02-05: wsfulton
|
||||
[MzScheme] SF #2942899 Add user supplied documentation to help getting started with MzScheme.
|
||||
|
|
|
|||
|
|
@ -493,6 +493,7 @@ C_TEST_CASES += \
|
|||
overload_extendc \
|
||||
preproc \
|
||||
preproc_constants_c \
|
||||
preproc_defined \
|
||||
preproc_line_file \
|
||||
ret_by_value \
|
||||
simple_array \
|
||||
|
|
|
|||
36
Examples/test-suite/preproc_defined.i
Normal file
36
Examples/test-suite/preproc_defined.i
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
%module preproc_defined
|
||||
|
||||
// Check 'defined' passes through the preprocessor without being processed like '#if defined(ABC)' would be (SF bug #1940536)
|
||||
|
||||
%define DEFINED_MACRO
|
||||
%{
|
||||
int defined(int b) {
|
||||
return b > 10;
|
||||
}
|
||||
int vvv = -1;
|
||||
void fn(int val) {
|
||||
if (defined(val))
|
||||
vvv = 1;
|
||||
else
|
||||
vvv = 0;
|
||||
}
|
||||
%}
|
||||
%enddef
|
||||
|
||||
DEFINED_MACRO
|
||||
|
||||
%{
|
||||
int checking(void) {
|
||||
fn(11);
|
||||
int okay = (vvv == 1);
|
||||
fn(9);
|
||||
okay = okay && (vvv == 0);
|
||||
return okay; /* should be 1 */
|
||||
}
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
int call_checking(void) {
|
||||
return checking();
|
||||
}
|
||||
%}
|
||||
4
Examples/test-suite/python/preproc_defined_runme.py
Normal file
4
Examples/test-suite/python/preproc_defined_runme.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import preproc_defined
|
||||
|
||||
if preproc_defined.call_checking() != 1:
|
||||
raise RuntimeError
|
||||
|
|
@ -33,6 +33,7 @@ static Hash *included_files = 0;
|
|||
static List *dependencies = 0;
|
||||
static Scanner *id_scan = 0;
|
||||
static int error_as_warning = 0; /* Understand the cpp #error directive as a special #warning */
|
||||
static int defined_operator_accepted = 0;
|
||||
static int macro_level = 0;
|
||||
static int macro_start_line = 0;
|
||||
static const String * macro_start_file = 0;
|
||||
|
|
@ -1013,8 +1014,8 @@ static DOH *Preprocessor_replace(DOH *s) {
|
|||
} else {
|
||||
/* We found the end of a valid identifier */
|
||||
Ungetc(c, s);
|
||||
/* See if this is the special "defined" macro */
|
||||
if (Equal(kpp_defined, id)) {
|
||||
/* See if this is the special "defined" operator */
|
||||
if (Equal(kpp_defined, id) && defined_operator_accepted) {
|
||||
int lenargs = 0;
|
||||
DOH *args = 0;
|
||||
/* See whether or not a parenthesis has been used */
|
||||
|
|
@ -1042,7 +1043,7 @@ static DOH *Preprocessor_replace(DOH *s) {
|
|||
}
|
||||
lenargs = Len(args);
|
||||
if ((!args) || (!lenargs)) {
|
||||
/* This is not a defined() macro. */
|
||||
/* This is not a defined() operator. */
|
||||
Append(ns, id);
|
||||
state = 0;
|
||||
break;
|
||||
|
|
@ -1554,7 +1555,9 @@ String *Preprocessor_parse(String *s) {
|
|||
level++;
|
||||
if (allow) {
|
||||
int val;
|
||||
String *sval = Preprocessor_replace(value);
|
||||
String *sval;
|
||||
defined_operator_accepted = 1;
|
||||
sval = Preprocessor_replace(value);
|
||||
start_level = level;
|
||||
Seek(sval, 0, SEEK_SET);
|
||||
/* Printf(stdout,"Evaluating '%s'\n", sval); */
|
||||
|
|
@ -1570,6 +1573,7 @@ String *Preprocessor_parse(String *s) {
|
|||
if (val == 0)
|
||||
allow = 0;
|
||||
}
|
||||
defined_operator_accepted = 0;
|
||||
mask = 1;
|
||||
}
|
||||
} else if (Equal(id, kpp_elif)) {
|
||||
|
|
@ -1577,6 +1581,7 @@ String *Preprocessor_parse(String *s) {
|
|||
Swig_error(Getfile(s), Getline(id), "Misplaced #elif.\n");
|
||||
} else {
|
||||
cond_lines[level - 1] = Getline(id);
|
||||
defined_operator_accepted = 1;
|
||||
if (allow) {
|
||||
allow = 0;
|
||||
mask = 0;
|
||||
|
|
@ -1599,6 +1604,7 @@ String *Preprocessor_parse(String *s) {
|
|||
allow = 0;
|
||||
}
|
||||
}
|
||||
defined_operator_accepted = 0;
|
||||
}
|
||||
} else if (Equal(id, kpp_warning)) {
|
||||
if (allow) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue