From 67dfa7ed41303a74277bf9ad4e2e2344c8ffb505 Mon Sep 17 00:00:00 2001 From: Christian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com> Date: Fri, 11 Nov 2022 11:48:39 -0500 Subject: Fix duplicated function names (#2341) Even though this change does name deduplication in a slower way, it avoids name collisions without any breaking changes in the test suite. Fixes #2202 --- bindgen/codegen/mod.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'bindgen/codegen/mod.rs') diff --git a/bindgen/codegen/mod.rs b/bindgen/codegen/mod.rs index e0d96cd1..c7ac59db 100644 --- a/bindgen/codegen/mod.rs +++ b/bindgen/codegen/mod.rs @@ -2421,7 +2421,7 @@ trait MethodCodegen { &self, ctx: &BindgenContext, methods: &mut Vec, - method_names: &mut HashMap, + method_names: &mut HashSet, result: &mut CodegenResult<'a>, parent: &CompInfo, ); @@ -2432,7 +2432,7 @@ impl MethodCodegen for Method { &self, ctx: &BindgenContext, methods: &mut Vec, - method_names: &mut HashMap, + method_names: &mut HashSet, result: &mut CodegenResult<'a>, _parent: &CompInfo, ) { @@ -2499,16 +2499,22 @@ impl MethodCodegen for Method { return; } - let count = { - let count = method_names.entry(name.clone()).or_insert(0); - *count += 1; - *count - 1 - }; + if method_names.contains(&name) { + let mut count = 1; + let mut new_name; + + while { + new_name = format!("{}{}", name, count); + method_names.contains(&new_name) + } { + count += 1; + } - if count != 0 { - name.push_str(&count.to_string()); + name = new_name; } + method_names.insert(name.clone()); + let mut function_name = function_item.canonical_name(ctx); if times_seen > 0 { write!(&mut function_name, "{}", times_seen).unwrap(); -- cgit v1.2.3