Skip to content
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

Auto-generated test failure for cpp array of wchar_t #1345

Closed
ehsanul opened this issue Jul 5, 2018 · 1 comment
Closed

Auto-generated test failure for cpp array of wchar_t #1345

ehsanul opened this issue Jul 5, 2018 · 1 comment

Comments

@ehsanul
Copy link

ehsanul commented Jul 5, 2018

Input C/C++ Header

struct Foo {
	wchar_t	Bar[32];
};

Bindgen Invocation

$ bindgen test.hpp -o test.rs
$ rustc --test test.rs
$ ./test

Actual Results

Generated code:

/* automatically generated by rust-bindgen */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Foo {
    pub Bar: [u16; 32usize],
}
#[test]
fn bindgen_test_layout_Foo() {
    assert_eq!(
        ::std::mem::size_of::<Foo>(),
        128usize,
        concat!("Size of: ", stringify!(Foo))
    );
    assert_eq!(
        ::std::mem::align_of::<Foo>(),
        4usize,
        concat!("Alignment of ", stringify!(Foo))
    );
    assert_eq!(
        unsafe { &(*(::std::ptr::null::<Foo>())).Bar as *const _ as usize },
        0usize,
        concat!("Offset of field: ", stringify!(Foo), "::", stringify!(Bar))
    );
}

Test result:

---- bindgen_test_layout_Foo stdout ----
	thread 'bindgen_test_layout_Foo' panicked at 'assertion failed: `(left == right)`
  left: `64`,
 right: `128`: Size of: Foo', test.rs:10:5

Expected Results

I'm not really familiar with wchar_t, but seems it can be either 2 or 4 bytes depending on the platform/implementation. In this case it seems like it chose the wrong expected value in tests for my current platform.

System

Toolchain: x86_64-apple-darwin
rustc: 1.28.0-nightly
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0

emilio added a commit to emilio/rust-bindgen that referenced this issue Jul 5, 2018
@emilio
Copy link
Contributor

emilio commented Jul 5, 2018

Yup, for some reason we assume it's u16. #1346 should fix.

bors-servo pushed a commit that referenced this issue Jul 6, 2018
ir: Don't assume wchar is 2 bytes.

Fixes #1345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants