-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update exception handling to use std::exception_ptr
#1180
base: master
Are you sure you want to change the base?
Commits on Feb 24, 2023
-
Add
CxxException
to wrap a C++ exceptionThe exception object can be passed as a pointer via `CxxException` error through Rust frames. A method to create the default message-based `rust::Error` and to drop and clone the exception are provided.
Configuration menu - View commit details
-
Copy full SHA for ffd3e4c - Browse repository at this point
Copy the full SHA ffd3e4cView commit details -
This represents C++ `std::exception_ptr` on the Rust side via `CxxException` object, which can be mentioned as a return type for functions creating custom exceptions or evaluating exceptions caught from C++ (added in further commits).
Configuration menu - View commit details
-
Copy full SHA for 73eeef3 - Browse repository at this point
Copy the full SHA 73eeef3View commit details -
Update exception handling to use
std::exception_ptr
This makes the interface between C++ exception handling and Rust `Result` cleaner and allows passing C++ exception from the inner C++ call to the outer C++ call via Rust's `CxxException` unmodified, i.e., without losing information. To allow custom exception types, trait `ToCxxException` was introduced. With this trait, it's possible to convert a Rust error to the wrapper `CxxExeception` via a C++ function, thus allowing throwing other exceptions as well. This required changing `r#try` function into macros, so we can properly default to `rust::Error` for errors not having `ToCxxException` defined. Background: The `throw` statement in C++ (__cxa_throw) effectively first allocates space on the heap and creates the exception within, then starts unwinding. This can be also done via standard C++11 API in two steps. First, `std::make_exception_ptr()` creates a new `std::exception_ptr`, which points into this allocated space and internally is just a pointer (it's a smart pointer much like `std::shared_ptr`). Then, `std::rethrow_exception()` can be used to actually throw and/or rethrow this exception. Basically, the new implementation now uses `std::make_exception_ptr()` called from Rust to construct an exception for the `Result<_, E>` and then after returning it back to C++ via `CxxResult` (which is now BTW smaller, just 8B) the C++ part throws it using `std::rethrow_exception()`.
Configuration menu - View commit details
-
Copy full SHA for b11a622 - Browse repository at this point
Copy the full SHA b11a622View commit details
Commits on Feb 25, 2023
-
Fix a warning on no_std and the expected output for Result
Since invalid `Result<T>` output changed, the expected file had to be updated. The output actually got better, since now the location of the actual declaration of the offending struct is also shown, not only the usage.
Configuration menu - View commit details
-
Copy full SHA for e7b7116 - Browse repository at this point
Copy the full SHA e7b7116View commit details -
Fix handling of MSVC
std::exception_ptr
Contrary to the most platforms, which just store a single pointer in `std::exception_ptr`, MSVC stores two. Add necessary code to handle this.
Configuration menu - View commit details
-
Copy full SHA for b7bb463 - Browse repository at this point
Copy the full SHA b7bb463View commit details -
Fix: pick up changed tests.h/cc to rebuild bridge
Previously, modifying tests.h/cc would not trigger rebuild of the bridge, effectively preventing test development.
Configuration menu - View commit details
-
Copy full SHA for c45ce05 - Browse repository at this point
Copy the full SHA c45ce05View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7528dde - Browse repository at this point
Copy the full SHA 7528ddeView commit details -
Add NUL character at the end of copied error message
C++ error message returned by `what` must be NUL-terminated. However, the current copy function only copied the characters, but didn't add the NUL. Allocate one more byte and set it to NUL.
Configuration menu - View commit details
-
Copy full SHA for 2805a91 - Browse repository at this point
Copy the full SHA 2805a91View commit details -
Disable the ui test
result_no_display
due to a bug intrybuild
cr……ate. The normalization in `trybuild` crate doesn't work in the CI (but works fine locally).
Configuration menu - View commit details
-
Copy full SHA for 3714d23 - Browse repository at this point
Copy the full SHA 3714d23View commit details
Commits on Feb 28, 2023
-
Remove an unneeded exported macro
Instead, expand the match directly in `expand.rs` to minimize the public API.
Configuration menu - View commit details
-
Copy full SHA for 380b9ef - Browse repository at this point
Copy the full SHA 380b9efView commit details
Commits on Mar 5, 2023
-
Configuration menu - View commit details
-
Copy full SHA for 15225fb - Browse repository at this point
Copy the full SHA 15225fbView commit details