-
Notifications
You must be signed in to change notification settings - Fork 806
fix: resolve bitfield accessor name conflicts #3354
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| /// Bitfield accessor name conflicts: | ||
| /// - `set_x` getter collides with `x` setter | ||
| /// - `set_x_bindgen_bitfield` tests the collision chain (the suffix | ||
| /// used for deduplication itself collides with a real field name) | ||
| struct test { | ||
| char set_x: 1; | ||
| char x: 1; | ||
| char set_x_bindgen_bitfield: 1; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2783,7 +2783,26 @@ impl CodeGenerator for CompInfo { | |
| } | ||
| } | ||
|
|
||
| let mut method_names = Default::default(); | ||
| // Seed method_names with bitfield accessor names so C++ | ||
| // methods, constructors, and destructors that collide with | ||
| // them get renamed instead of producing duplicates. | ||
| let mut method_names: HashSet<String> = self | ||
| .fields() | ||
| .iter() | ||
| .filter_map(|f| match f { | ||
| Field::Bitfields(ref bu) => Some(bu.bitfields().iter()), | ||
| Field::DataMember(_) => None, | ||
| }) | ||
| .flatten() | ||
| .filter(|bf| bf.name().is_some()) | ||
| .flat_map(|bf| { | ||
| let g = bf.getter_name().to_owned(); | ||
| let s = bf.setter_name().to_owned(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need |
||
| let gr = format!("{g}_raw"); | ||
| let sr = format!("{s}_raw"); | ||
| [g, s, gr, sr] | ||
| }) | ||
| .collect(); | ||
| let discovered_id = DiscoveredItemId::new(item.id().as_usize()); | ||
| if ctx.options().codegen_config.methods() { | ||
| for method in self.methods() { | ||
|
|
@@ -3126,6 +3145,12 @@ impl Method { | |
| return; | ||
| } | ||
|
|
||
| // Mangle the name before dedup so we compare the actual Rust | ||
| // identifier (e.g. C++ `type` → Rust `type_`) against | ||
| // method_names, which contains bitfield accessor names that | ||
| // are already in their Rust-mangled form. | ||
| name = ctx.rust_mangle(&name).to_string(); | ||
|
|
||
| if method_names.contains(&name) { | ||
| let mut count = 1; | ||
| let mut new_name; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use our regular tests for this? If not, why not?