Skip to content

Commit 004a195

Browse files
author
bors-servo
authored
Auto merge of #247 - emilio:macro-redef, r=fitzgen
Handle macro redefinition a bit more graciously. r? @fitzgen
2 parents b7259de + 1001e3b commit 004a195

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/ir/var.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,19 @@ impl ClangSubItemParser for Var {
8787

8888
assert!(!id.is_empty(), "Empty macro name?");
8989

90-
if ctx.parsed_macro(&id) {
91-
let name = String::from_utf8(id).unwrap();
92-
warn!("Duplicated macro definition: {}", name);
93-
return Err(ParseError::Continue);
94-
}
90+
let previously_defined = ctx.parsed_macro(&id);
9591

9692
// NB: It's important to "note" the macro even if the result is
9793
// not an integer, otherwise we might loose other kind of
9894
// derived macros.
9995
ctx.note_parsed_macro(id.clone(), value.clone());
10096

97+
if previously_defined {
98+
let name = String::from_utf8(id).unwrap();
99+
warn!("Duplicated macro definition: {}", name);
100+
return Err(ParseError::Continue);
101+
}
102+
101103
// NOTE: Unwrapping, here and above, is safe, because the
102104
// identifier of a token comes straight from clang, and we
103105
// enforce utf8 there, so we should have already panicked at
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
pub const FOO: ::std::os::raw::c_uint = 4;
8+
pub const BAR: ::std::os::raw::c_uint = 5;
9+
pub const BAZ: ::std::os::raw::c_uint = 6;

tests/headers/macro-redef.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define FOO 4
2+
#define BAR (1 + FOO)
3+
#undef FOO
4+
#define FOO 5
5+
#define BAZ (1 + FOO)

0 commit comments

Comments
 (0)