Skip to content

Commit f0654e2

Browse files
committed
Update tests
1 parent 19eff97 commit f0654e2

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎tests/unit/out/refcount/fn_ptr.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ impl HashHolder_unsigned_long__ptr__bool__ {
4040
Self { h: (h.read()) }
4141
}
4242
}
43+
thread_local!(
44+
pub static total_7: Value<i32> = Rc::new(RefCell::new(0));
45+
);
46+
pub fn add_to_total_8(mut x: i32) {
47+
total_7.with(|rc| *rc.borrow_mut() += x);
48+
}
4349
pub fn main() {
4450
__cpp2rust_init_globals();
4551
std::process::exit(main_0());
@@ -71,6 +77,12 @@ fn main_0() -> i32 {
7177
HashHolder_unsigned_long__ptr__bool__::new({ __tmp_0.as_pointer() })
7278
};
7379
assert!((({ hh.h.call(true,) }) == 1_u64));
80+
let mut handler: FnPtr<fn(i32)> = FnPtr::<fn(i32)>::new(add_to_total_8);
81+
({ handler.call(2) });
82+
({ handler.call(3) });
83+
assert!((total_7.with(|rc| *rc.borrow()) == 5));
7484
return 0;
7585
}
76-
pub fn __cpp2rust_init_globals() {}
86+
pub fn __cpp2rust_init_globals() {
87+
let _ = total_7.with(|_| ());
88+
}

‎tests/unit/out/unsafe/fn_ptr.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ impl HashHolder_unsigned_long__ptr__bool__ {
4242
this
4343
}
4444
}
45+
pub static mut total_7: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
46+
pub unsafe fn add_to_total_8(mut x: i32) {
47+
(*std::cell::LazyCell::force_mut(&mut *&raw mut total_7)) += x;
48+
}
4549
pub fn main() {
4650
unsafe {
4751
__cpp2rust_init_globals();
@@ -76,6 +80,12 @@ unsafe fn main_0() -> i32 {
7680
HashHolder_unsigned_long__ptr__bool__::new({ &mut __tmp_0 })
7781
};
7882
assert!(((unsafe { (hh.h).unwrap()(true,) }) == (1_u64)));
83+
let mut handler: Option<unsafe fn(i32)> = Some(add_to_total_8);
84+
(unsafe { (handler).unwrap()(2) });
85+
(unsafe { (handler).unwrap()(3) });
86+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_7)) == (5)));
7987
return 0;
8088
}
81-
pub unsafe fn __cpp2rust_init_globals() {}
89+
pub unsafe fn __cpp2rust_init_globals() {
90+
std::cell::LazyCell::force(&*&raw const total_7);
91+
}

0 commit comments

Comments
 (0)