From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../run-make-fulldeps/foreign-exceptions/foo.cpp | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/test/run-make-fulldeps/foreign-exceptions/foo.cpp (limited to 'src/test/run-make-fulldeps/foreign-exceptions/foo.cpp') diff --git a/src/test/run-make-fulldeps/foreign-exceptions/foo.cpp b/src/test/run-make-fulldeps/foreign-exceptions/foo.cpp new file mode 100644 index 000000000..8182021a2 --- /dev/null +++ b/src/test/run-make-fulldeps/foreign-exceptions/foo.cpp @@ -0,0 +1,60 @@ +#include +#include +#include + +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; + } + } +} -- cgit v1.2.3