-
Notifications
You must be signed in to change notification settings - Fork 672
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
__darwin_size_t is included even when it's not whitelisted #1215
Comments
By default a type generates all types that depend on it. In this case I guess in your platform is something like: typedef unsigned long long __darwing_size_t;
typedef __darwin_size_t size_t; The special casing of size_t -> usize happens later in the pipeline (on code generation), and by then we think This one is fixable, not sure how easily in a clean way though, guess I'll need to give it a shot. Easy workaround would be to |
I'm hitting a similar issue on Linux. The Input C header// Emulate: #include <inttypes.h>
typedef unsigned char __uint8_t;
typedef __uint8_t uint8_t;
typedef uint8_t (*my_callback)(const uint8_t *code); Bindgen Invocation
Actual Resultspub type __uint8_t = ::std::os::raw::c_uchar;
pub type my_callback = ::std::option::Option<unsafe extern "C" fn(code: *const u8) -> u8>; Expected Resultspub type my_callback = ::std::option::Option<unsafe extern "C" fn(code: *const u8) -> u8>; Since |
I think this is basically the same issue as #1188 -- an intermediate typedef is produced in both cases, because that is what the C headers say to do. In my opinion, there should not be explicit edge cases in The best description of rule to implement might be @tmfink's :
but I still am not sure why "a typedef is not used" should really mean that the typedef is suppressed and other typedefs are stitched together in its absence. Since the C headers have this, why should not |
@kulp I see what you are saying about not wanting to special case this (assuming I'm understanding correctly). One way to solve this would be to do an extra pass to see what items are "reachable" from the whitelisted set. Unreachable types (such as My crate It would be nice if the bindgen output was consistent for each platform (Windows, Mac, Linux, FreeBSD, etc.) and did not rely details of the system headers. The blacklist approach depends on details of system's headers. |
I think actually the At the risk of overgeneralizing the problem, maybe @tmfink's request could be expressed like this : Prune type aliases ( However, this still does not really address what @kornelski wants, because the emitted bindings in that original case do reference the "internals" : pub type __darwin_size_t = ::std::os::raw::c_ulong;
pub type size_t = __darwin_size_t;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Foo {
pub s: size_t,
} So, on my Mac at least, I do not see any "special casing of
|
Yeah, this is related to |
The right way to fix this is doing those replacements sooner, IMO, but that may or may not be a lot of work for this edge case. |
There are more options:
|
Fair enough :) Here some trade-offs with those that come to mind:
Yeah, the problem is that this requires yet another pass on top of all the existing passes we do just to detect this special case, which is not great. You get this for free if you do the replacement earlier...
That's true, but it seems like the resulting bindings could be less idiomatic unnecessarily. So much stuff would end up being
This is the simplest, but but if that typedef is used in a "public" struct, like (pseudo-code): struct something {
// Public members, then...
__uint32_t __reserved[10];
}; Then bindgen would generate bindings that don't compile, which is not great. Maybe we could auto-treat them as opaque and it'd "just work", not sure... |
To clarify, by eagerly resolve I've meant the intermediate types, so that you'd still get And if a name is used outside of a typedef chain, then of course it should not be pruned. AFAIK "requires yet another pass" is purely bindgen's problem, not something user would be concerned about. C headers and libclang have messy issues, so needing multiple passes to clean that data up seems normal. |
Input C/C++ Header
Bindgen Invocation
on macOS High Sierra.
Actual Results
(other darwin types are filtered out correctly)
Expected Results
No darwin internals at all.
The text was updated successfully, but these errors were encountered: