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.
This textual approach seems unreliable; what if there isn't a space before the *? Possibly other cases?
There was a problem hiding this comment.
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.
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.
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
Given that C keeps a different namespace for
structs and aliases. The following patternis valid C code and produces both a
structand a pointer calledfoo. Given that Rust does not make this distinction, we add the_ptrprefix to the pointer type alias to avoid any name collisions.Fixes: #2227