-
Notifications
You must be signed in to change notification settings - Fork 707
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
Handle the const struct *
and struct *
patterns
#2304
Conversation
bindgen/ir/ty.rs
Outdated
if !ctx.options().c_naming { | ||
if let Some(inner_name) = dbg!(inner_spelling | ||
.strip_prefix("const struct ") | ||
.and_then(|s| s.strip_suffix(" *"))) |
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.
This textual approach seems unreliable; what if there isn't a space before the *
? Possibly other cases?
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.
This textual representation is generated by clang
and it doesn't seem to be affected by adding/removing spaces from the source code. For example:
typedef const struct foo {
char bar;
}*foo;
works just fine.
05ef029
to
2db8777
Compare
const struct *
pattern.const struct *
and struct *
patterns
2db8777
to
e0fdc7f
Compare
@goffrie thanks for your review! I updated the PR with some changes if you want to give it a second look |
bindgen/ir/ty.rs
Outdated
// collisions. | ||
if !ctx.options().c_naming { | ||
if let Some(inner_name) = inner_spelling | ||
.strip_prefix("const struct ") |
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.
This feels a bit hackish, relying on libclang's serialization... Can we use pointee_type()
and cursor equality instead? If not I guess this is ok...
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.
I did a commit using pointee_type
but I don't get the cursor equality part, wdym?
f7716a5
to
e4ba626
Compare
Given that C keeps a different namespace for `struct`s and aliases. The following patterns ```c typedef const struct foo { void *inner; } *foo; typedef struct bar { void *inner; } *bar; ``` are valid C code and produces both a `struct` and a pointer called `foo` and `bar` in different namespaces. Given that Rust does not make this distinction, we add the `_ptr` prefix to the pointer type aliases to avoid any name collisions.
e4ba626
to
9dedf00
Compare
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.
Thanks!
Given that C keeps a different namespace for
struct
s and aliases. The following patternis valid C code and produces both a
struct
and a pointer calledfoo
. Given that Rust does not make this distinction, we add the_ptr
prefix to the pointer type alias to avoid any name collisions.Fixes: #2227