Skip to content

Commit

Permalink
Update and add tests for MaybeUninit
Browse files Browse the repository at this point in the history
  • Loading branch information
elichai authored and emilio committed Nov 8, 2019
1 parent 99aff6e commit 3609bd6
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 27 deletions.
6 changes: 3 additions & 3 deletions tests/expectations/tests/constructor-tp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ extern "C" {
impl Bar {
#[inline]
pub unsafe fn new() -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
Bar_Bar(&mut __bindgen_tmp);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
Bar_Bar(__bindgen_tmp.as_mut_ptr());
__bindgen_tmp.assume_init()
}
}
18 changes: 9 additions & 9 deletions tests/expectations/tests/constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ extern "C" {
impl TestOverload {
#[inline]
pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
TestOverload_TestOverload(&mut __bindgen_tmp, arg1);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
TestOverload_TestOverload(__bindgen_tmp.as_mut_ptr(), arg1);
__bindgen_tmp.assume_init()
}
#[inline]
pub unsafe fn new1(arg1: f64) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
TestOverload_TestOverload1(&mut __bindgen_tmp, arg1);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
TestOverload_TestOverload1(__bindgen_tmp.as_mut_ptr(), arg1);
__bindgen_tmp.assume_init()
}
}
#[repr(C)]
Expand Down Expand Up @@ -75,8 +75,8 @@ extern "C" {
impl TestPublicNoArgs {
#[inline]
pub unsafe fn new() -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
TestPublicNoArgs_TestPublicNoArgs(__bindgen_tmp.as_mut_ptr());
__bindgen_tmp.assume_init()
}
}
84 changes: 84 additions & 0 deletions tests/expectations/tests/constructors_1_33.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/* automatically generated by rust-bindgen */

#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct TestOverload {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_TestOverload() {
assert_eq!(
::std::mem::size_of::<TestOverload>(),
1usize,
concat!("Size of: ", stringify!(TestOverload))
);
assert_eq!(
::std::mem::align_of::<TestOverload>(),
1usize,
concat!("Alignment of ", stringify!(TestOverload))
);
}
extern "C" {
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
#[link_name = "\u{1}_ZN12TestOverloadC1Ei"]
pub fn TestOverload_TestOverload(
this: *mut TestOverload,
arg1: ::std::os::raw::c_int,
);
}
extern "C" {
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
#[link_name = "\u{1}_ZN12TestOverloadC1Ed"]
pub fn TestOverload_TestOverload1(this: *mut TestOverload, arg1: f64);
}
impl TestOverload {
#[inline]
pub unsafe fn new(arg1: ::std::os::raw::c_int) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
TestOverload_TestOverload(&mut __bindgen_tmp, arg1);
__bindgen_tmp
}
#[inline]
pub unsafe fn new1(arg1: f64) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
TestOverload_TestOverload1(&mut __bindgen_tmp, arg1);
__bindgen_tmp
}
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct TestPublicNoArgs {
pub _address: u8,
}
#[test]
fn bindgen_test_layout_TestPublicNoArgs() {
assert_eq!(
::std::mem::size_of::<TestPublicNoArgs>(),
1usize,
concat!("Size of: ", stringify!(TestPublicNoArgs))
);
assert_eq!(
::std::mem::align_of::<TestPublicNoArgs>(),
1usize,
concat!("Alignment of ", stringify!(TestPublicNoArgs))
);
}
extern "C" {
#[link_name = "\u{1}_ZN16TestPublicNoArgsC1Ev"]
pub fn TestPublicNoArgs_TestPublicNoArgs(this: *mut TestPublicNoArgs);
}
impl TestPublicNoArgs {
#[inline]
pub unsafe fn new() -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
TestPublicNoArgs_TestPublicNoArgs(&mut __bindgen_tmp);
__bindgen_tmp
}
}
6 changes: 3 additions & 3 deletions tests/expectations/tests/gen-constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extern "C" {
impl Foo {
#[inline]
pub unsafe fn new(a: ::std::os::raw::c_int) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
Foo_Foo(&mut __bindgen_tmp, a);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
Foo_Foo(__bindgen_tmp.as_mut_ptr(), a);
__bindgen_tmp.assume_init()
}
}
9 changes: 6 additions & 3 deletions tests/expectations/tests/issue-447.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ pub mod root {
pub unsafe fn new(
arg1: root::mozilla::detail::GuardObjectNotifier,
) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
JSAutoCompartment_JSAutoCompartment(&mut __bindgen_tmp, arg1);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
JSAutoCompartment_JSAutoCompartment(
__bindgen_tmp.as_mut_ptr(),
arg1,
);
__bindgen_tmp.assume_init()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ impl Opaque {
}
#[inline]
pub unsafe fn new(pup: Pupper) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
Opaque_Opaque(&mut __bindgen_tmp, pup);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
Opaque_Opaque(__bindgen_tmp.as_mut_ptr(), pup);
__bindgen_tmp.assume_init()
}
}
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ extern "C" {
impl Usage {
#[inline]
pub unsafe fn new() -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
Usage_Usage(&mut __bindgen_tmp);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
Usage_Usage(__bindgen_tmp.as_mut_ptr());
__bindgen_tmp.assume_init()
}
}
6 changes: 3 additions & 3 deletions tests/expectations/tests/var-tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ extern "C" {
impl Bar {
#[inline]
pub unsafe fn new(baz: ::std::os::raw::c_int) -> Self {
let mut __bindgen_tmp = ::std::mem::uninitialized();
Bar_Bar(&mut __bindgen_tmp, baz);
__bindgen_tmp
let mut __bindgen_tmp = ::std::mem::MaybeUninit::uninit();
Bar_Bar(__bindgen_tmp.as_mut_ptr(), baz);
__bindgen_tmp.assume_init()
}
}
#[repr(C)]
Expand Down
16 changes: 16 additions & 0 deletions tests/headers/constructors_1_33.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// bindgen-flags: --rust-target 1.33

class TestOverload {
// This one shouldnt' be generated.
TestOverload();
public:
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
TestOverload(int);
/// Calling this should use `mem::unintialized()` and not `MaybeUninit()` as only rust 1.36 includes that.
TestOverload(double);
};

class TestPublicNoArgs {
public:
TestPublicNoArgs();
};

0 comments on commit 3609bd6

Please sign in to comment.