Skip to content

codegen: Fix remaining cases of missing core prefix. #489

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

Merged
merged 1 commit into from
Feb 8, 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
4 changes: 3 additions & 1 deletion src/codegen/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ pub mod ast_ty {
let prefix = ctx.rust_ident_raw(prefix);
quote_ty!(ctx.ext_cx(), $prefix::$ident)
}
None => quote_ty!(ctx.ext_cx(), ::std::os::raw::$ident),
None => {
quote_ty!(ctx.ext_cx(), ::std::os::raw::$ident)
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1644,9 +1644,10 @@ impl MethodCodegen for Method {
// If it's a constructor, we need to insert an extra parameter with a
// variable called `__bindgen_tmp` we're going to create.
if self.is_constructor() {
let prefix = ctx.trait_prefix();
let tmp_variable_decl =
quote_stmt!(ctx.ext_cx(),
let mut __bindgen_tmp = ::std::mem::uninitialized())
let mut __bindgen_tmp = ::$prefix::mem::uninitialized())
.unwrap();
stmts.push(tmp_variable_decl);
exprs[0] = quote_expr!(ctx.ext_cx(), &mut __bindgen_tmp);
Expand Down Expand Up @@ -2601,9 +2602,9 @@ mod utils {
.unwrap();

let union_field_debug_impl = quote_item!(ctx.ext_cx(),
impl<T> ::std::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter)
-> ::std::fmt::Result {
impl<T> ::$prefix::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::$prefix::fmt::Formatter)
-> ::$prefix::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
Expand Down
55 changes: 55 additions & 0 deletions tests/expectations/tests/use-core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@

extern crate core;

#[repr(C)]
pub struct __BindgenUnionField<T>(::core::marker::PhantomData<T>);
impl <T> __BindgenUnionField<T> {
#[inline]
pub fn new() -> Self { __BindgenUnionField(::core::marker::PhantomData) }
#[inline]
pub unsafe fn as_ref(&self) -> &T { ::core::mem::transmute(self) }
#[inline]
pub unsafe fn as_mut(&mut self) -> &mut T { ::core::mem::transmute(self) }
}
impl <T> ::core::default::Default for __BindgenUnionField<T> {
#[inline]
fn default() -> Self { Self::new() }
}
impl <T> ::core::clone::Clone for __BindgenUnionField<T> {
#[inline]
fn clone(&self) -> Self { Self::new() }
}
impl <T> ::core::marker::Copy for __BindgenUnionField<T> { }
impl <T> ::core::fmt::Debug for __BindgenUnionField<T> {
fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
fmt.write_str("__BindgenUnionField")
}
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct foo {
Expand Down Expand Up @@ -40,5 +64,36 @@ impl Clone for foo {
impl Default for foo {
fn default() -> Self { unsafe { ::core::mem::zeroed() } }
}
#[repr(C)]
#[derive(Debug, Default, Copy)]
pub struct _bindgen_ty_1 {
pub bar: __BindgenUnionField<::std::os::raw::c_int>,
pub baz: __BindgenUnionField<::std::os::raw::c_long>,
pub bindgen_union_field: u64,
}
#[test]
fn bindgen_test_layout__bindgen_ty_1() {
assert_eq!(::core::mem::size_of::<_bindgen_ty_1>() , 8usize , concat ! (
"Size of: " , stringify ! ( _bindgen_ty_1 ) ));
assert_eq! (::core::mem::align_of::<_bindgen_ty_1>() , 8usize , concat ! (
"Alignment of " , stringify ! ( _bindgen_ty_1 ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const _bindgen_ty_1 ) ) . bar as * const _ as
usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
, stringify ! ( bar ) ));
assert_eq! (unsafe {
& ( * ( 0 as * const _bindgen_ty_1 ) ) . baz as * const _ as
usize } , 0usize , concat ! (
"Alignment of field: " , stringify ! ( _bindgen_ty_1 ) , "::"
, stringify ! ( baz ) ));
}
impl Clone for _bindgen_ty_1 {
fn clone(&self) -> Self { *self }
}
extern "C" {
#[link_name = "bazz"]
pub static mut bazz: _bindgen_ty_1;
}
pub type fooFunction =
::core::option::Option<unsafe extern "C" fn(bar: ::std::os::raw::c_int)>;
5 changes: 5 additions & 0 deletions tests/headers/use-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ struct foo {
void* bar;
};

union {
int bar;
long baz;
} bazz;

typedef void (*fooFunction)(int bar);