summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/function.rs9
-rw-r--r--tests/expectations/tests/mangling-linux32.rs28
-rw-r--r--tests/expectations/tests/mangling-linux64.rs28
-rw-r--r--tests/expectations/tests/mangling-macos.rs19
-rw-r--r--tests/expectations/tests/mangling-win32.rs19
-rw-r--r--tests/expectations/tests/mangling-win64.rs28
-rw-r--r--tests/headers/mangling-linux32.hpp7
-rw-r--r--tests/headers/mangling-linux64.hpp7
-rw-r--r--tests/headers/mangling-macos.h3
-rw-r--r--tests/headers/mangling-macos.hpp7
-rw-r--r--tests/headers/mangling-win32.h3
-rw-r--r--tests/headers/mangling-win32.hpp7
-rw-r--r--tests/headers/mangling-win64.hpp7
13 files changed, 165 insertions, 7 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 9865997d..5fa95203 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 00000000..5aa7bd55
--- /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::<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 }
+}
diff --git a/tests/expectations/tests/mangling-linux64.rs b/tests/expectations/tests/mangling-linux64.rs
new file mode 100644
index 00000000..5aa7bd55
--- /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::<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 }
+}
diff --git a/tests/expectations/tests/mangling-macos.rs b/tests/expectations/tests/mangling-macos.rs
index 87df5e4a..5aa7bd55 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::<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 }
+}
diff --git a/tests/expectations/tests/mangling-win32.rs b/tests/expectations/tests/mangling-win32.rs
index 87df5e4a..ffaf52cf 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::<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 }
+}
diff --git a/tests/expectations/tests/mangling-win64.rs b/tests/expectations/tests/mangling-win64.rs
new file mode 100644
index 00000000..ae5cc9cc
--- /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::<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 }
+}
diff --git a/tests/headers/mangling-linux32.hpp b/tests/headers/mangling-linux32.hpp
new file mode 100644
index 00000000..450c91d7
--- /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 00000000..36dda913
--- /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 230f938b..00000000
--- 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 00000000..94b16202
--- /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 897aeb42..00000000
--- 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 00000000..50beea5a
--- /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 00000000..8882d7dd
--- /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;
+};