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

Stop Rust from prepending underscore before '?' for win32 #822

Merged
merged 1 commit into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: No need for braces, here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it needs. String::remove returns char and String::insert returns nothing.

// Stop Rust from prepending underscore for variables on Win32.
'?' => { symbol.insert(0, '\x01'); }
_ => {}
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions tests/expectations/tests/mangling-linux32.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
28 changes: 28 additions & 0 deletions tests/expectations/tests/mangling-linux64.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
19 changes: 19 additions & 0 deletions tests/expectations/tests/mangling-macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
19 changes: 19 additions & 0 deletions tests/expectations/tests/mangling-win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
28 changes: 28 additions & 0 deletions tests/expectations/tests/mangling-win64.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
7 changes: 7 additions & 0 deletions tests/headers/mangling-linux32.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=i586-unknown-linux

extern "C" void foo();

struct Foo {
static bool sBar;
};
7 changes: 7 additions & 0 deletions tests/headers/mangling-linux64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=x86_64-unknown-linux

extern "C" void foo();

struct Foo {
static bool sBar;
};
3 changes: 0 additions & 3 deletions tests/headers/mangling-macos.h

This file was deleted.

7 changes: 7 additions & 0 deletions tests/headers/mangling-macos.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=x86_64-apple-darwin

extern "C" void foo();

struct Foo {
static bool sBar;
};
3 changes: 0 additions & 3 deletions tests/headers/mangling-win32.h

This file was deleted.

7 changes: 7 additions & 0 deletions tests/headers/mangling-win32.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=i686-pc-win32

extern "C" void foo();

struct Foo {
static bool sBar;
};
7 changes: 7 additions & 0 deletions tests/headers/mangling-win64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=x86_64-pc-win32

extern "C" void foo();

struct Foo {
static bool sBar;
};