diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-18 12:35:22 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-18 12:35:22 -0600 |
commit | c48f835f9e03fdd30d35c7cae63f04cdaa2d9549 (patch) | |
tree | 46c948439ec4d1e97ae7a4370369c734f550db41 /libbindgen/tests | |
parent | 0674f6002e71e11ef398d90ed0e4b63ca5bbfce9 (diff) | |
parent | 2a9341146ff2ae3deef7a39b385360122f406c52 (diff) |
Auto merge of #281 - fitzgen:namespace-mangle-rust-symbols, r=emilio
Include namespaces in mangled symbols
When we aren't using `--enable-cxx-namespaces`, we can end up with
conflicting struct symbol names that we need to disambiguate. The
solution is to mangle the namespaced C++ symbol "foo::bar::Baz" into the
Rust "foo_bar_Baz" symbol.
This did change the way anonymous types and modules get named a little,
but I think our approach is much more sane now than it was before.
Fixes #267.
r? @emilio
Diffstat (limited to 'libbindgen/tests')
13 files changed, 125 insertions, 73 deletions
diff --git a/libbindgen/tests/expectations/tests/class_with_inner_struct.rs b/libbindgen/tests/expectations/tests/class_with_inner_struct.rs index ab51396d..a1bacbdb 100644 --- a/libbindgen/tests/expectations/tests/class_with_inner_struct.rs +++ b/libbindgen/tests/expectations/tests/class_with_inner_struct.rs @@ -129,38 +129,42 @@ pub struct C { #[repr(C)] #[derive(Debug, Copy)] pub struct C__bindgen_ty_1 { - pub mFunc: __BindgenUnionField<C__bindgen_ty_1_1>, - pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_1_2>, + pub mFunc: __BindgenUnionField<C__bindgen_ty_1__bindgen_ty_1>, + pub __bindgen_anon_1: __BindgenUnionField<C__bindgen_ty_1__bindgen_ty_2>, pub bindgen_union_field: [u32; 4usize], } #[repr(C)] #[derive(Debug, Copy)] -pub struct C__bindgen_ty_1_1 { +pub struct C__bindgen_ty_1__bindgen_ty_1 { pub mX1: f32, pub mY1: f32, pub mX2: f32, pub mY2: f32, } #[test] -fn bindgen_test_layout_C__bindgen_ty_1_1() { - assert_eq!(::std::mem::size_of::<C__bindgen_ty_1_1>() , 16usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_1_1>() , 4usize); +fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_1>() , + 16usize); + assert_eq!(::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_1>() , + 4usize); } -impl Clone for C__bindgen_ty_1_1 { +impl Clone for C__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct C__bindgen_ty_1_2 { +pub struct C__bindgen_ty_1__bindgen_ty_2 { pub mStepSyntax: StepSyntax, pub mSteps: ::std::os::raw::c_uint, } #[test] -fn bindgen_test_layout_C__bindgen_ty_1_2() { - assert_eq!(::std::mem::size_of::<C__bindgen_ty_1_2>() , 8usize); - assert_eq!(::std::mem::align_of::<C__bindgen_ty_1_2>() , 4usize); +fn bindgen_test_layout_C__bindgen_ty_1__bindgen_ty_2() { + assert_eq!(::std::mem::size_of::<C__bindgen_ty_1__bindgen_ty_2>() , + 8usize); + assert_eq!(::std::mem::align_of::<C__bindgen_ty_1__bindgen_ty_2>() , + 4usize); } -impl Clone for C__bindgen_ty_1_2 { +impl Clone for C__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] diff --git a/libbindgen/tests/expectations/tests/elaborated.rs b/libbindgen/tests/expectations/tests/elaborated.rs index db373d41..0e8f4ee5 100644 --- a/libbindgen/tests/expectations/tests/elaborated.rs +++ b/libbindgen/tests/expectations/tests/elaborated.rs @@ -4,8 +4,8 @@ #![allow(non_snake_case)] -pub type whatever_t = ::std::os::raw::c_int; +pub type whatever_whatever_t = ::std::os::raw::c_int; extern "C" { #[link_name = "_Z9somethingPKi"] - pub fn something(wat: *const whatever_t); + pub fn something(wat: *const whatever_whatever_t); } diff --git a/libbindgen/tests/expectations/tests/inherit-namespaced.rs b/libbindgen/tests/expectations/tests/inherit-namespaced.rs index a58058b0..c0d2e5a6 100644 --- a/libbindgen/tests/expectations/tests/inherit-namespaced.rs +++ b/libbindgen/tests/expectations/tests/inherit-namespaced.rs @@ -6,7 +6,7 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct RootedBase<T> { +pub struct js_RootedBase<T> { pub _address: u8, pub _phantom_0: ::std::marker::PhantomData<T>, } diff --git a/libbindgen/tests/expectations/tests/jsval_layout_opaque.rs b/libbindgen/tests/expectations/tests/jsval_layout_opaque.rs index 91f898af..530fdb22 100644 --- a/libbindgen/tests/expectations/tests/jsval_layout_opaque.rs +++ b/libbindgen/tests/expectations/tests/jsval_layout_opaque.rs @@ -154,24 +154,24 @@ impl jsval_layout__bindgen_ty_1 { #[repr(C)] #[derive(Debug, Copy)] pub struct jsval_layout__bindgen_ty_2 { - pub payload: jsval_layout__bindgen_ty_2_1, + pub payload: jsval_layout__bindgen_ty_2__bindgen_ty_1, } #[repr(C)] #[derive(Debug, Copy)] -pub struct jsval_layout__bindgen_ty_2_1 { +pub struct jsval_layout__bindgen_ty_2__bindgen_ty_1 { pub i32: __BindgenUnionField<i32>, pub u32: __BindgenUnionField<u32>, pub why: __BindgenUnionField<JSWhyMagic>, pub bindgen_union_field: u32, } #[test] -fn bindgen_test_layout_jsval_layout__bindgen_ty_2_1() { - assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_2_1>() , - 4usize); - assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_2_1>() , - 4usize); +fn bindgen_test_layout_jsval_layout__bindgen_ty_2__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<jsval_layout__bindgen_ty_2__bindgen_ty_1>() + , 4usize); + assert_eq!(::std::mem::align_of::<jsval_layout__bindgen_ty_2__bindgen_ty_1>() + , 4usize); } -impl Clone for jsval_layout__bindgen_ty_2_1 { +impl Clone for jsval_layout__bindgen_ty_2__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[test] diff --git a/libbindgen/tests/expectations/tests/overloading.rs b/libbindgen/tests/expectations/tests/overloading.rs index 4e138e7d..71002e23 100644 --- a/libbindgen/tests/expectations/tests/overloading.rs +++ b/libbindgen/tests/expectations/tests/overloading.rs @@ -15,9 +15,9 @@ extern "C" { } extern "C" { #[link_name = "_ZN3foo10MyFunctionEv"] - pub fn MyFunction(); + pub fn foo_MyFunction(); } extern "C" { #[link_name = "_ZN3bar10MyFunctionEv"] - pub fn MyFunction1(); + pub fn bar_MyFunction(); } diff --git a/libbindgen/tests/expectations/tests/replace_template_alias.rs b/libbindgen/tests/expectations/tests/replace_template_alias.rs index 61a2fbcc..b9a0d0c9 100644 --- a/libbindgen/tests/expectations/tests/replace_template_alias.rs +++ b/libbindgen/tests/expectations/tests/replace_template_alias.rs @@ -6,10 +6,10 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Rooted<T> { - pub ptr: MaybeWrapped<T>, +pub struct JS_Rooted<T> { + pub ptr: JS_detail_MaybeWrapped<T>, } /// But the replacement type does use T! /// -/// <div rustbindgen replaces="MaybeWrapped" /> -pub type MaybeWrapped<T> = T; +/// <div rustbindgen replaces="JS_detail_MaybeWrapped" /> +pub type JS_detail_MaybeWrapped<T> = T; diff --git a/libbindgen/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/libbindgen/tests/expectations/tests/same_struct_name_in_different_namespaces.rs new file mode 100644 index 00000000..8e7c177b --- /dev/null +++ b/libbindgen/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -0,0 +1,28 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy)] +pub struct JS_Zone { + pub _address: u8, +} +impl Clone for JS_Zone { + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct JS_shadow_Zone { + pub x: ::std::os::raw::c_int, + pub y: ::std::os::raw::c_int, +} +#[test] +fn bindgen_test_layout_JS_shadow_Zone() { + assert_eq!(::std::mem::size_of::<JS_shadow_Zone>() , 8usize); + assert_eq!(::std::mem::align_of::<JS_shadow_Zone>() , 4usize); +} +impl Clone for JS_shadow_Zone { + fn clone(&self) -> Self { *self } +} diff --git a/libbindgen/tests/expectations/tests/struct_with_nesting.rs b/libbindgen/tests/expectations/tests/struct_with_nesting.rs index 97a0949e..b3e0a5ca 100644 --- a/libbindgen/tests/expectations/tests/struct_with_nesting.rs +++ b/libbindgen/tests/expectations/tests/struct_with_nesting.rs @@ -38,38 +38,42 @@ pub struct foo { #[derive(Debug, Copy)] pub struct foo__bindgen_ty_1 { pub b: __BindgenUnionField<::std::os::raw::c_uint>, - pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_1_1>, - pub __bindgen_anon_2: __BindgenUnionField<foo__bindgen_ty_1_2>, + pub __bindgen_anon_1: __BindgenUnionField<foo__bindgen_ty_1__bindgen_ty_1>, + pub __bindgen_anon_2: __BindgenUnionField<foo__bindgen_ty_1__bindgen_ty_2>, pub bindgen_union_field: u32, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_1_1 { +pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub c1: ::std::os::raw::c_ushort, pub c2: ::std::os::raw::c_ushort, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_1_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1_1>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1_1>() , 2usize); +fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() , + 4usize); + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() , + 2usize); } -impl Clone for foo__bindgen_ty_1_1 { +impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_1_2 { +pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub d1: ::std::os::raw::c_uchar, pub d2: ::std::os::raw::c_uchar, pub d3: ::std::os::raw::c_uchar, pub d4: ::std::os::raw::c_uchar, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_1_2() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1_2>() , 4usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1_2>() , 1usize); +fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() , + 4usize); + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() , + 1usize); } -impl Clone for foo__bindgen_ty_1_2 { +impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] diff --git a/libbindgen/tests/expectations/tests/template_alias.rs b/libbindgen/tests/expectations/tests/template_alias.rs index 6457381f..d301a11c 100644 --- a/libbindgen/tests/expectations/tests/template_alias.rs +++ b/libbindgen/tests/expectations/tests/template_alias.rs @@ -4,9 +4,9 @@ #![allow(non_snake_case)] -pub type Wrapped<T> = T; +pub type JS_detail_Wrapped<T> = T; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Rooted<T> { - pub ptr: Wrapped<T>, +pub struct JS_Rooted<T> { + pub ptr: JS_detail_Wrapped<T>, } diff --git a/libbindgen/tests/expectations/tests/typeref.rs b/libbindgen/tests/expectations/tests/typeref.rs index da944146..21217ced 100644 --- a/libbindgen/tests/expectations/tests/typeref.rs +++ b/libbindgen/tests/expectations/tests/typeref.rs @@ -31,7 +31,7 @@ impl <T> ::std::fmt::Debug for __BindgenUnionField<T> { #[repr(C)] #[derive(Debug, Copy)] pub struct nsFoo { - pub mBar: StyleShapeSource<::std::os::raw::c_int>, + pub mBar: mozilla_StyleShapeSource<::std::os::raw::c_int>, } #[test] fn bindgen_test_layout_nsFoo() { @@ -43,28 +43,28 @@ impl Clone for nsFoo { } #[repr(C)] #[derive(Debug, Copy)] -pub struct FragmentOrURL { +pub struct mozilla_FragmentOrURL { pub mIsLocalRef: bool, } #[test] -fn bindgen_test_layout_FragmentOrURL() { - assert_eq!(::std::mem::size_of::<FragmentOrURL>() , 1usize); - assert_eq!(::std::mem::align_of::<FragmentOrURL>() , 1usize); +fn bindgen_test_layout_mozilla_FragmentOrURL() { + assert_eq!(::std::mem::size_of::<mozilla_FragmentOrURL>() , 1usize); + assert_eq!(::std::mem::align_of::<mozilla_FragmentOrURL>() , 1usize); } -impl Clone for FragmentOrURL { +impl Clone for mozilla_FragmentOrURL { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct Position { +pub struct mozilla_Position { pub _address: u8, } #[test] -fn bindgen_test_layout_Position() { - assert_eq!(::std::mem::size_of::<Position>() , 1usize); - assert_eq!(::std::mem::align_of::<Position>() , 1usize); +fn bindgen_test_layout_mozilla_Position() { + assert_eq!(::std::mem::size_of::<mozilla_Position>() , 1usize); + assert_eq!(::std::mem::align_of::<mozilla_Position>() , 1usize); } -impl Clone for Position { +impl Clone for mozilla_Position { fn clone(&self) -> Self { *self } } #[repr(C)] @@ -82,15 +82,15 @@ impl Clone for Bar { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct StyleShapeSource<ReferenceBox> { - pub __bindgen_anon_1: StyleShapeSource__bindgen_ty_1<ReferenceBox>, +pub struct mozilla_StyleShapeSource<ReferenceBox> { + pub __bindgen_anon_1: mozilla_StyleShapeSource__bindgen_ty_1<ReferenceBox>, pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct StyleShapeSource__bindgen_ty_1<ReferenceBox> { - pub mPosition: __BindgenUnionField<*mut Position>, - pub mFragmentOrURL: __BindgenUnionField<*mut FragmentOrURL>, +pub struct mozilla_StyleShapeSource__bindgen_ty_1<ReferenceBox> { + pub mPosition: __BindgenUnionField<*mut mozilla_Position>, + pub mFragmentOrURL: __BindgenUnionField<*mut mozilla_FragmentOrURL>, pub bindgen_union_field: u64, pub _phantom_0: ::std::marker::PhantomData<ReferenceBox>, } diff --git a/libbindgen/tests/expectations/tests/union_with_nesting.rs b/libbindgen/tests/expectations/tests/union_with_nesting.rs index 61c08a2a..af9e442d 100644 --- a/libbindgen/tests/expectations/tests/union_with_nesting.rs +++ b/libbindgen/tests/expectations/tests/union_with_nesting.rs @@ -38,37 +38,41 @@ pub struct foo { #[repr(C)] #[derive(Debug, Copy)] pub struct foo__bindgen_ty_1 { - pub __bindgen_anon_1: foo__bindgen_ty_1_1, - pub __bindgen_anon_2: foo__bindgen_ty_1_2, + pub __bindgen_anon_1: foo__bindgen_ty_1__bindgen_ty_1, + pub __bindgen_anon_2: foo__bindgen_ty_1__bindgen_ty_2, } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_1_1 { +pub struct foo__bindgen_ty_1__bindgen_ty_1 { pub b1: __BindgenUnionField<::std::os::raw::c_ushort>, pub b2: __BindgenUnionField<::std::os::raw::c_ushort>, pub bindgen_union_field: u16, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_1_1() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1_1>() , 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1_1>() , 2usize); +fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_1() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_1>() , + 2usize); + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_1>() , + 2usize); } -impl Clone for foo__bindgen_ty_1_1 { +impl Clone for foo__bindgen_ty_1__bindgen_ty_1 { fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] -pub struct foo__bindgen_ty_1_2 { +pub struct foo__bindgen_ty_1__bindgen_ty_2 { pub c1: __BindgenUnionField<::std::os::raw::c_ushort>, pub c2: __BindgenUnionField<::std::os::raw::c_ushort>, pub bindgen_union_field: u16, } #[test] -fn bindgen_test_layout_foo__bindgen_ty_1_2() { - assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1_2>() , 2usize); - assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1_2>() , 2usize); +fn bindgen_test_layout_foo__bindgen_ty_1__bindgen_ty_2() { + assert_eq!(::std::mem::size_of::<foo__bindgen_ty_1__bindgen_ty_2>() , + 2usize); + assert_eq!(::std::mem::align_of::<foo__bindgen_ty_1__bindgen_ty_2>() , + 2usize); } -impl Clone for foo__bindgen_ty_1_2 { +impl Clone for foo__bindgen_ty_1__bindgen_ty_2 { fn clone(&self) -> Self { *self } } #[test] diff --git a/libbindgen/tests/headers/replace_template_alias.hpp b/libbindgen/tests/headers/replace_template_alias.hpp index 6ceae4e5..b0648994 100644 --- a/libbindgen/tests/headers/replace_template_alias.hpp +++ b/libbindgen/tests/headers/replace_template_alias.hpp @@ -18,6 +18,6 @@ class Rooted { /// But the replacement type does use T! /// -/// <div rustbindgen replaces="MaybeWrapped" /> +/// <div rustbindgen replaces="JS_detail_MaybeWrapped" /> template <typename T> using replaces_MaybeWrapped = T; diff --git a/libbindgen/tests/headers/same_struct_name_in_different_namespaces.hpp b/libbindgen/tests/headers/same_struct_name_in_different_namespaces.hpp new file mode 100644 index 00000000..fe685845 --- /dev/null +++ b/libbindgen/tests/headers/same_struct_name_in_different_namespaces.hpp @@ -0,0 +1,12 @@ +namespace JS { + + struct Zone; + + namespace shadow { + + struct Zone { + int x; + int y; + }; + } +} |