Skip to content

Commit 58876b9

Browse files
committed
Update tests
1 parent 2627937 commit 58876b9

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎tests/unit/out/refcount/05_new.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ use std::io::prelude::*;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::AsFd;
88
use std::rc::{Rc, Weak};
9+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
10+
#[byte_size(1)]
11+
pub struct A {}
12+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
13+
#[byte_size(1)]
14+
pub struct D {}
915
pub fn main() {
1016
__cpp2rust_init_globals();
1117
std::process::exit(main_0());
@@ -14,6 +20,22 @@ fn main_0() -> i32 {
1420
let mut d: Ptr<i32> = Ptr::alloc(0);
1521
d.write(5);
1622
d.delete();
23+
let mut c: Ptr<i32> = Ptr::alloc(3);
24+
c.delete();
25+
({
26+
DImpl::operator_call(
27+
&Rc::new(RefCell::new(<D>::default())).as_pointer(),
28+
Ptr::alloc(<A>::default()),
29+
)
30+
});
1731
return 0;
1832
}
33+
pub trait DImpl {
34+
fn operator_call(&self, ptr: Ptr<A>);
35+
}
36+
impl DImpl for Ptr<D> {
37+
fn operator_call(&self, mut ptr: Ptr<A>) {
38+
ptr.delete();
39+
}
40+
}
1941
pub fn __cpp2rust_init_globals() {}

‎tests/unit/out/unsafe/05_new.rs‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ use std::collections::BTreeMap;
66
use std::io::{Read, Seek, Write};
77
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
88
use std::rc::Rc;
9+
#[repr(C)]
10+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
11+
pub struct A {}
12+
#[repr(C)]
13+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
14+
pub struct D {}
15+
impl D {
16+
pub unsafe fn operator_call(&self, mut ptr: *const A) {
17+
{
18+
let __p = ptr;
19+
if !__p.is_null() {
20+
::std::mem::drop(Box::from_raw(__p.cast_mut()))
21+
}
22+
};
23+
}
24+
}
925
pub fn main() {
1026
unsafe {
1127
__cpp2rust_init_globals();
@@ -21,6 +37,19 @@ unsafe fn main_0() -> i32 {
2137
::std::mem::drop(Box::from_raw(__p))
2238
}
2339
};
40+
let mut c: *const i32 = (Box::leak(Box::new(3)) as *mut i32).cast_const();
41+
{
42+
let __p = c;
43+
if !__p.is_null() {
44+
::std::mem::drop(Box::from_raw(__p.cast_mut()))
45+
}
46+
};
47+
(unsafe {
48+
D::operator_call(
49+
&<D>::default(),
50+
(Box::leak(Box::new(<A>::default())) as *mut A).cast_const(),
51+
)
52+
});
2453
return 0;
2554
}
2655
pub unsafe fn __cpp2rust_init_globals() {}

0 commit comments

Comments
 (0)