Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicated function names #2341

Merged
merged 1 commit into from Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions bindgen-tests/tests/headers/duplicated-definition-count.hpp
@@ -0,0 +1,6 @@
class BitStream {
public:
void Write(const char *inputByteArray, unsigned int numberOfBytes);
void Write(BitStream *bitStream, unsigned numberOfBits);
void Write1();
};
24 changes: 15 additions & 9 deletions bindgen/codegen/mod.rs
Expand Up @@ -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,
);
Expand All @@ -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,
) {
Expand Down Expand Up @@ -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();
Expand Down