diff --git a/src/ir/function.rs b/src/ir/function.rs index 9865997ded..5fa95203a7 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -130,7 +130,14 @@ fn get_abi(cc: CXCallingConv) -> Abi { fn mangling_hack_if_needed(ctx: &BindgenContext, symbol: &mut String) { if ctx.needs_mangling_hack() { - symbol.remove(0); + match symbol.chars().next().unwrap() { + // Stripping leading underscore for all names on Darwin and + // C linkage functions on Win32. + '_' => { symbol.remove(0); } + // Stop Rust from prepending underscore for variables on Win32. + '?' => { symbol.insert(0, '\x01'); } + _ => {} + } } } diff --git a/tests/expectations/tests/mangling-linux32.rs b/tests/expectations/tests/mangling-linux32.rs new file mode 100644 index 0000000000..5aa7bd551a --- /dev/null +++ b/tests/expectations/tests/mangling-linux32.rs @@ -0,0 +1,28 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +extern "C" { + pub fn foo(); +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "_ZN3Foo4sBarE"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); +} +impl Clone for Foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/mangling-linux64.rs b/tests/expectations/tests/mangling-linux64.rs new file mode 100644 index 0000000000..5aa7bd551a --- /dev/null +++ b/tests/expectations/tests/mangling-linux64.rs @@ -0,0 +1,28 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +extern "C" { + pub fn foo(); +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "_ZN3Foo4sBarE"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); +} +impl Clone for Foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/mangling-macos.rs b/tests/expectations/tests/mangling-macos.rs index 87df5e4ad7..5aa7bd551a 100644 --- a/tests/expectations/tests/mangling-macos.rs +++ b/tests/expectations/tests/mangling-macos.rs @@ -7,3 +7,22 @@ extern "C" { pub fn foo(); } +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "_ZN3Foo4sBarE"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); +} +impl Clone for Foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/mangling-win32.rs b/tests/expectations/tests/mangling-win32.rs index 87df5e4ad7..ffaf52cf2a 100644 --- a/tests/expectations/tests/mangling-win32.rs +++ b/tests/expectations/tests/mangling-win32.rs @@ -7,3 +7,22 @@ extern "C" { pub fn foo(); } +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "\u{1}?sBar@Foo@@2_NA"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); +} +impl Clone for Foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/expectations/tests/mangling-win64.rs b/tests/expectations/tests/mangling-win64.rs new file mode 100644 index 0000000000..ae5cc9cc12 --- /dev/null +++ b/tests/expectations/tests/mangling-win64.rs @@ -0,0 +1,28 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +extern "C" { + pub fn foo(); +} +#[repr(C)] +#[derive(Debug, Default, Copy)] +pub struct Foo { + pub _address: u8, +} +extern "C" { + #[link_name = "?sBar@Foo@@2_NA"] + pub static mut Foo_sBar: bool; +} +#[test] +fn bindgen_test_layout_Foo() { + assert_eq!(::std::mem::size_of::() , 1usize , concat ! ( + "Size of: " , stringify ! ( Foo ) )); + assert_eq! (::std::mem::align_of::() , 1usize , concat ! ( + "Alignment of " , stringify ! ( Foo ) )); +} +impl Clone for Foo { + fn clone(&self) -> Self { *self } +} diff --git a/tests/headers/mangling-linux32.hpp b/tests/headers/mangling-linux32.hpp new file mode 100644 index 0000000000..450c91d74a --- /dev/null +++ b/tests/headers/mangling-linux32.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: -- --target=i586-unknown-linux + +extern "C" void foo(); + +struct Foo { + static bool sBar; +}; diff --git a/tests/headers/mangling-linux64.hpp b/tests/headers/mangling-linux64.hpp new file mode 100644 index 0000000000..36dda913e0 --- /dev/null +++ b/tests/headers/mangling-linux64.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: -- --target=x86_64-unknown-linux + +extern "C" void foo(); + +struct Foo { + static bool sBar; +}; diff --git a/tests/headers/mangling-macos.h b/tests/headers/mangling-macos.h deleted file mode 100644 index 230f938ba8..0000000000 --- a/tests/headers/mangling-macos.h +++ /dev/null @@ -1,3 +0,0 @@ -// bindgen-flags: -- --target=x86_64-apple-darwin - -void foo(); diff --git a/tests/headers/mangling-macos.hpp b/tests/headers/mangling-macos.hpp new file mode 100644 index 0000000000..94b16202e5 --- /dev/null +++ b/tests/headers/mangling-macos.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: -- --target=x86_64-apple-darwin + +extern "C" void foo(); + +struct Foo { + static bool sBar; +}; diff --git a/tests/headers/mangling-win32.h b/tests/headers/mangling-win32.h deleted file mode 100644 index 897aeb42be..0000000000 --- a/tests/headers/mangling-win32.h +++ /dev/null @@ -1,3 +0,0 @@ -// bindgen-flags: -- --target=i686-pc-win32 - -void foo(); diff --git a/tests/headers/mangling-win32.hpp b/tests/headers/mangling-win32.hpp new file mode 100644 index 0000000000..50beea5aec --- /dev/null +++ b/tests/headers/mangling-win32.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: -- --target=i686-pc-win32 + +extern "C" void foo(); + +struct Foo { + static bool sBar; +}; diff --git a/tests/headers/mangling-win64.hpp b/tests/headers/mangling-win64.hpp new file mode 100644 index 0000000000..8882d7ddd0 --- /dev/null +++ b/tests/headers/mangling-win64.hpp @@ -0,0 +1,7 @@ +// bindgen-flags: -- --target=x86_64-pc-win32 + +extern "C" void foo(); + +struct Foo { + static bool sBar; +};