-
Notifications
You must be signed in to change notification settings - Fork 729
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
Wrong layout for empty struct in C mode #551
Comments
Oh, interesting, so this is one of these C vs. C++ semantics I guess: The same: // test.h
struct Foo {}; $ ./target/debug/bindgen test.h -- -x c++
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
"Size of: " , stringify ! ( Foo ) ));
assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
"Alignment of " , stringify ! ( Foo ) ));
}
impl Clone for Foo {
fn clone(&self) -> Self { *self }
}
$ ./target/debug/bindgen test.h
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy)]
pub struct Foo {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_Foo() {
assert_eq!(::std::mem::size_of::<Foo>() , 0usize , concat ! (
"Size of: " , stringify ! ( Foo ) ));
assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
"Alignment of " , stringify ! ( Foo ) ));
}
impl Clone for Foo {
fn clone(&self) -> Self { *self }
} That different So it seems in C++ all structs are addressable, but not in C. // test.c
#include <stdio.h>
struct Foo {};
struct Bar {
struct Foo f;
};
int main() {
struct Bar b;
struct Foo f;
printf("%lu, %lu %p, %p\n", sizeof(struct Bar), sizeof(struct Foo), &b, &f);
return 0;
} $ cc test.c
$ ./a.out
0, 0 0x7ffe8ffb10b0, 0x7ffe8ffb10b0
$ c++ test.c -x c++
$ ./a.out
1, 1 0x7ffefd7a8faf, 0x7ffefd7a8fae Bindgen is usually agnostic to the header and just trusts clang. perhaps we should do the same check here to avoid generating the |
Edited the description to be more meaningful. Patch at #552. |
see rust-lang/rust-bindgen#551 for more details
This should be fixed now. |
Input C/C++ Header
Actual Results
cargo test
report failure:Expected Results
generated tests should all be green
Note
In the real example (not reduced one as above)
cargo test
failed in another place,here real example (with resolved
typedef
s) from windows variant of java sdk:The text was updated successfully, but these errors were encountered: