diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
commit | 631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch) | |
tree | a1b87c8f8cad01cf18f7c5f57a08f102771ed303 /tests/run-make-fulldeps/foreign-exceptions | |
parent | Adding debian version 1.69.0+dfsg1-1. (diff) | |
download | rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/run-make-fulldeps/foreign-exceptions')
-rw-r--r-- | tests/run-make-fulldeps/foreign-exceptions/Makefile | 10 | ||||
-rw-r--r-- | tests/run-make-fulldeps/foreign-exceptions/foo.cpp | 60 | ||||
-rw-r--r-- | tests/run-make-fulldeps/foreign-exceptions/foo.rs | 59 |
3 files changed, 0 insertions, 129 deletions
diff --git a/tests/run-make-fulldeps/foreign-exceptions/Makefile b/tests/run-make-fulldeps/foreign-exceptions/Makefile deleted file mode 100644 index 38fe2773d..000000000 --- a/tests/run-make-fulldeps/foreign-exceptions/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -include ../tools.mk - -all: foo - $(call RUN,foo) - -foo: foo.rs $(call NATIVE_STATICLIB,foo) - $(RUSTC) $< -lfoo $(EXTRARSCXXFLAGS) - -$(TMPDIR)/libfoo.o: foo.cpp - $(call COMPILE_OBJ_CXX,$@,$<) diff --git a/tests/run-make-fulldeps/foreign-exceptions/foo.cpp b/tests/run-make-fulldeps/foreign-exceptions/foo.cpp deleted file mode 100644 index 8182021a2..000000000 --- a/tests/run-make-fulldeps/foreign-exceptions/foo.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include <assert.h> -#include <stddef.h> -#include <stdio.h> - -void println(const char* s) { - puts(s); - fflush(stdout); -} - -struct exception {}; -struct rust_panic {}; - -struct drop_check { - bool* ok; - ~drop_check() { - println("~drop_check"); - - if (ok) - *ok = true; - } -}; - -extern "C" { - void rust_catch_callback(void (*cb)(), bool* rust_ok); - - void throw_cxx_exception() { - println("throwing C++ exception"); - throw exception(); - } - - void test_cxx_exception() { - bool rust_ok = false; - try { - rust_catch_callback(throw_cxx_exception, &rust_ok); - assert(false && "unreachable"); - } catch (exception e) { - println("caught C++ exception"); - assert(rust_ok); - return; - } - assert(false && "did not catch thrown C++ exception"); - } - - void cxx_catch_callback(void (*cb)(), bool* cxx_ok) { - drop_check x; - x.ok = NULL; - try { - cb(); - } catch (rust_panic e) { - assert(false && "shouldn't be able to catch a rust panic"); - } catch (...) { - println("caught foreign exception in catch (...)"); - // Foreign exceptions are caught by catch (...). We only set the ok - // flag if we successfully caught the panic. The destructor of - // drop_check will then set the flag to true if it is executed. - x.ok = cxx_ok; - throw; - } - } -} diff --git a/tests/run-make-fulldeps/foreign-exceptions/foo.rs b/tests/run-make-fulldeps/foreign-exceptions/foo.rs deleted file mode 100644 index dd3b7c76f..000000000 --- a/tests/run-make-fulldeps/foreign-exceptions/foo.rs +++ /dev/null @@ -1,59 +0,0 @@ -// Tests that C++ exceptions can unwind through Rust code run destructors and -// are caught by catch_unwind. Also tests that Rust panics can unwind through -// C++ code. - -#![feature(c_unwind)] - -use std::panic::{catch_unwind, AssertUnwindSafe}; - -struct DropCheck<'a>(&'a mut bool); -impl<'a> Drop for DropCheck<'a> { - fn drop(&mut self) { - println!("DropCheck::drop"); - *self.0 = true; - } -} - -extern "C" { - fn test_cxx_exception(); -} - -extern "C-unwind" { - fn cxx_catch_callback(cb: extern "C-unwind" fn(), ok: *mut bool); -} - -#[no_mangle] -extern "C-unwind" fn rust_catch_callback(cb: extern "C-unwind" fn(), rust_ok: &mut bool) { - let _drop = DropCheck(rust_ok); - cb(); - unreachable!("should have unwound instead of returned"); -} - -fn test_rust_panic() { - extern "C-unwind" fn callback() { - println!("throwing rust panic"); - panic!(1234i32); - } - - let mut dropped = false; - let mut cxx_ok = false; - let caught_unwind = catch_unwind(AssertUnwindSafe(|| { - let _drop = DropCheck(&mut dropped); - unsafe { - cxx_catch_callback(callback, &mut cxx_ok); - } - unreachable!("should have unwound instead of returned"); - })); - println!("caught rust panic"); - assert!(dropped); - assert!(caught_unwind.is_err()); - let panic_obj = caught_unwind.unwrap_err(); - let panic_int = *panic_obj.downcast_ref::<i32>().unwrap(); - assert_eq!(panic_int, 1234); - assert!(cxx_ok); -} - -fn main() { - unsafe { test_cxx_exception() }; - test_rust_panic(); -} |