Skip to content

Commit a978cc7

Browse files
committed
Support macros and functions with the same name.
1 parent b6a242e commit a978cc7

File tree

7 files changed

+46
-29
lines changed

7 files changed

+46
-29
lines changed

Cargo.lock

+21-23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@ default-members = [
1313
"bindgen-cli",
1414
"bindgen-tests",
1515
]
16+
17+
# [patch.crates-io]
18+
# cmacro = { path = "../cmacro-rs" }

bindgen-tests/tests/expectations/tests/macro_func_wrapper.rs

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-tests/tests/headers/macro_func_wrapper.h

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ void func(int, int);
22

33
#define Y 7
44
#define wrapper_func(x) func(x, Y)
5+
#define func(x) func(x, Y)

bindgen/Cargo.toml

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ path = "lib.rs"
2626

2727
[dependencies]
2828
bitflags = "1.0.3"
29-
cmacro = "0.1.2"
29+
cmacro = "0.1.3"
3030
clang-sys = { version = "1", features = ["clang_6_0"] }
3131
lazycell = "1"
3232
lazy_static = "1"
@@ -55,6 +55,3 @@ experimental = []
5555
testing_only_extra_assertions = []
5656
testing_only_libclang_9 = []
5757
testing_only_libclang_5 = []
58-
59-
# [patch."https://github.com/reitermarkus/cmacro-rs"]
60-
# cmacro = { path = "../cmacro-rs" }

bindgen/codegen/macro_def.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ impl CodeGenerator for MacroDef {
6262

6363
match self {
6464
Self::Fn(name) => {
65-
if result.seen_function(&canonical_name) {
65+
if result.seen_fn_macro(&canonical_name) {
6666
return;
6767
}
68-
result.saw_function(&canonical_name);
68+
result.saw_fn_macro(&canonical_name);
6969

7070
let mut fn_macro = ctx.fn_macro(name).unwrap().clone();
7171
let generated_value = match fn_macro.generate(ctx) {

bindgen/codegen/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ struct CodegenResult<'a> {
262262
/// Being these two different declarations.
263263
functions_seen: HashSet<String>,
264264
vars_seen: HashSet<String>,
265+
fn_macros_seen: HashSet<String>,
265266

266267
/// Used for making bindings to overloaded functions. Maps from a canonical
267268
/// function name to the number of overloads we have already codegen'd for
@@ -285,6 +286,7 @@ impl<'a> CodegenResult<'a> {
285286
items_seen: Default::default(),
286287
functions_seen: Default::default(),
287288
vars_seen: Default::default(),
289+
fn_macros_seen: Default::default(),
288290
overload_counters: Default::default(),
289291
items_to_serialize: Default::default(),
290292
}
@@ -330,6 +332,14 @@ impl<'a> CodegenResult<'a> {
330332
self.functions_seen.insert(name.into());
331333
}
332334

335+
fn seen_fn_macro(&self, name: &str) -> bool {
336+
self.fn_macros_seen.contains(name)
337+
}
338+
339+
fn saw_fn_macro(&mut self, name: &str) {
340+
self.fn_macros_seen.insert(name.into());
341+
}
342+
333343
/// Get the overload number for the given function name. Increments the
334344
/// counter internally so the next time we ask for the overload for this
335345
/// name, we get the incremented value, and so on.

0 commit comments

Comments
 (0)