Skip to content

Commit

Permalink
Add test that opaque C++ types are unwind-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Aug 30, 2024
1 parent 86f1f71 commit 5f08017
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
clippy::unseparated_literal_suffix
)]

use cxx::SharedPtr;
use cxx::{SharedPtr, UniquePtr};
use cxx_test_suite::module::ffi2;
use cxx_test_suite::{cast, ffi, R};
use std::cell::Cell;
use std::ffi::CStr;
use std::panic;

thread_local! {
static CORRECT: Cell<bool> = const { Cell::new(false) };
Expand Down Expand Up @@ -380,3 +381,10 @@ fn test_raw_ptr() {
assert_eq!(2025, unsafe { ffi::c_take_const_ptr(c3) });
assert_eq!(2025, unsafe { ffi::c_take_mut_ptr(c3 as *mut ffi::C) }); // deletes c3
}

#[test]
fn test_unwind_safe() {
fn inspect(_c: &ffi::C) {}
let _unwind_safe = |c: UniquePtr<ffi::C>| panic::catch_unwind(|| drop(c));
let _ref_unwind_safe = |c: &ffi::C| panic::catch_unwind(|| inspect(c));
}

0 comments on commit 5f08017

Please sign in to comment.