Skip to content

Commit ca279d5

Browse files
committed
codegen: Fix remaining cases of missing core prefix.
1 parent f5394b3 commit ca279d5

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

src/codegen/helpers.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ pub mod ast_ty {
8989
let prefix = ctx.rust_ident_raw(prefix);
9090
quote_ty!(ctx.ext_cx(), $prefix::$ident)
9191
}
92-
None => quote_ty!(ctx.ext_cx(), ::std::os::raw::$ident),
92+
None => {
93+
let prefix = ctx.trait_prefix();
94+
quote_ty!(ctx.ext_cx(), ::$prefix::os::raw::$ident)
95+
}
9396
}
9497
}
9598

src/codegen/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1593,9 +1593,10 @@ impl MethodCodegen for Method {
15931593
// If it's a constructor, we need to insert an extra parameter with a
15941594
// variable called `__bindgen_tmp` we're going to create.
15951595
if self.is_constructor() {
1596+
let prefix = ctx.trait_prefix();
15961597
let tmp_variable_decl =
15971598
quote_stmt!(ctx.ext_cx(),
1598-
let mut __bindgen_tmp = ::std::mem::uninitialized())
1599+
let mut __bindgen_tmp = ::$prefix::mem::uninitialized())
15991600
.unwrap();
16001601
stmts.push(tmp_variable_decl);
16011602
exprs[0] = quote_expr!(ctx.ext_cx(), &mut __bindgen_tmp);
@@ -2137,7 +2138,7 @@ impl ToRustTy for Type {
21372138
.map(|arg| arg.to_rust_ty(ctx))
21382139
.collect::<Vec<_>>();
21392140

2140-
path.segments.last_mut().unwrap().parameters = if
2141+
path.segments.last_mut().unwrap().parameters = if
21412142
template_args.is_empty() {
21422143
None
21432144
} else {
@@ -2550,9 +2551,9 @@ mod utils {
25502551
.unwrap();
25512552

25522553
let union_field_debug_impl = quote_item!(ctx.ext_cx(),
2553-
impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
2554-
fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
2555-
-> ::std::fmt::Result {
2554+
impl<T> ::$prefix::fmt::Debug for __BindgenUnionField<T> {
2555+
fn fmt(&self, fmt: &mut ::$prefix::fmt::Formatter)
2556+
-> ::$prefix::fmt::Result {
25562557
fmt.write_str("__BindgenUnionField")
25572558
}
25582559
}

tests/expectations/tests/use-core.rs

+53-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,36 @@
55

66
extern crate core;
77

8+
#[repr(C)]
9+
pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>);
10+
impl <T> __BindgenUnionField<T> {
11+
#[inline]
12+
pub fn new() -> Self { __BindgenUnionField(::core::marker::PhantomData) }
13+
#[inline]
14+
pub unsafe fn as_ref(&self) -> &T { ::core::mem::transmute(self) }
15+
#[inline]
16+
pub unsafe fn as_mut(&mut self) -> &mut T { ::core::mem::transmute(self) }
17+
}
18+
impl <T> ::core::default::Default for __BindgenUnionField<T> {
19+
#[inline]
20+
fn default() -> Self { Self::new() }
21+
}
22+
impl <T> ::core::clone::Clone for __BindgenUnionField<T> {
23+
#[inline]
24+
fn clone(&self) -> Self { Self::new() }
25+
}
26+
impl <T> ::core::marker::Copy for __BindgenUnionField<T> { }
27+
impl <T> ::core::fmt::Debug for __BindgenUnionField<T> {
28+
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
29+
fmt.write_str("__BindgenUnionField")
30+
}
31+
}
832
#[repr(C)]
933
#[derive(Debug, Copy)]
1034
pub struct foo {
11-
pub a: ::std::os::raw::c_int,
12-
pub b: ::std::os::raw::c_int,
13-
pub bar: *mut ::std::os::raw::c_void,
35+
pub a: ::core::os::raw::c_int,
36+
pub b: ::core::os::raw::c_int,
37+
pub bar: *mut ::core::os::raw::c_void,
1438
}
1539
#[test]
1640
fn bindgen_test_layout_foo() {
@@ -29,5 +53,30 @@ fn bindgen_test_layout_foo() {
2953
impl Clone for foo {
3054
fn clone(&self) -> Self { *self }
3155
}
56+
#[repr(C)]
57+
#[derive(Debug, Copy)]
58+
pub struct _bindgen_ty_1 {
59+
pub bar: __BindgenUnionField<::core::os::raw::c_int>,
60+
pub baz: __BindgenUnionField<::core::os::raw::c_long>,
61+
pub bindgen_union_field: u64,
62+
}
63+
#[test]
64+
fn bindgen_test_layout__bindgen_ty_1() {
65+
assert_eq!(::core::mem::size_of::<_bindgen_ty_1>() , 8usize);
66+
assert_eq! (::core::mem::align_of::<_bindgen_ty_1>() , 8usize);
67+
assert_eq! (unsafe {
68+
& ( * ( 0 as * const _bindgen_ty_1 ) ) . bar as * const _ as
69+
usize } , 0usize);
70+
assert_eq! (unsafe {
71+
& ( * ( 0 as * const _bindgen_ty_1 ) ) . baz as * const _ as
72+
usize } , 0usize);
73+
}
74+
impl Clone for _bindgen_ty_1 {
75+
fn clone(&self) -> Self { *self }
76+
}
77+
extern "C" {
78+
#[link_name = "bazz"]
79+
pub static mut bazz: _bindgen_ty_1;
80+
}
3281
pub type fooFunction =
33-
::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>;
82+
::core::option::Option<unsafe extern "C" fn(bar: ::core::os::raw::c_int)>;

tests/headers/use-core.h

+5
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ struct foo {
55
void* bar;
66
};
77

8+
union {
9+
int bar;
10+
long baz;
11+
} bazz;
12+
813
typedef void (*fooFunction)(int bar);

0 commit comments

Comments
 (0)