summaryrefslogtreecommitdiff
path: root/bindgen/codegen/mod.rs
diff options
context:
space:
mode:
authorChristian Poveda Ruiz <31802960+pvdrz@users.noreply.github.com>2022-11-11 11:48:39 -0500
committerGitHub <noreply@github.com>2022-11-11 11:48:39 -0500
commit67dfa7ed41303a74277bf9ad4e2e2344c8ffb505 (patch)
tree3f6994bb2d3fbf5d133270cad32dd1f1663527d9 /bindgen/codegen/mod.rs
parentdb4ea32e2d810e765a4c40479e053d0a61a875cf (diff)
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
Diffstat (limited to 'bindgen/codegen/mod.rs')
-rw-r--r--bindgen/codegen/mod.rs24
1 files changed, 15 insertions, 9 deletions
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<proc_macro2::TokenStream>,
- method_names: &mut HashMap<String, usize>,
+ method_names: &mut HashSet<String>,
result: &mut CodegenResult<'a>,
parent: &CompInfo,
);
@@ -2432,7 +2432,7 @@ impl MethodCodegen for Method {
&self,
ctx: &BindgenContext,
methods: &mut Vec<proc_macro2::TokenStream>,
- method_names: &mut HashMap<String, usize>,
+ method_names: &mut HashSet<String>,
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();