-
Notifications
You must be signed in to change notification settings - Fork 304
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
Add support for transparent typedefs #966
base: master
Are you sure you want to change the base?
Conversation
7ce3ac0
to
8a76012
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.
Need to take a closer look but over all looks reasonable.
for example. | ||
``` | ||
#define MY_ATTRIBUTES [[nodiscard]] | ||
``` |
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.
These changes seem unrelated? Seems ok, but maybe worth splitting into its own commit / PR? Or is it some sort of autoformatting i'm not aware of?
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.
src/bindgen/ir/ty.rs
Outdated
} => { | ||
// Predict that ret+args will all be erased, but decrement the count whenever we're | ||
// wrong. If the count drops to 0, then type erasure was a no-op after all. | ||
let mut num_erased = 1 + args.len(); |
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 think it'd be a bit clearer to do it the other way around. In fact, wouldn't it be a bit nicer to just:
let mut erased_any = false;
macro_rules! try_erase {
($item:tt) => {
if let Some(erased) = eraser.erase_transparent_types(library, $item, mappings) {
erased
} else {
$item.clone()
}
}
Then:
let ret = try_erase!(ret);
...
if erased_any {
return Some(..);
}
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.
Ah, nice suggestion. I implemented it with a lambda instead of a macro tho.
c4d5245
to
42ae2fe
Compare
Following #967, introduce
/// cbindgen:transparent-typedef
annotation that causes cbindgen to replace transparent structs and typedefs with their underlying type.This allows the following:
to export as
instead of today's output: