Skip to content
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

Out of date safety note on #[ffi_function]? #123

Open
recatek opened this issue Oct 15, 2024 · 1 comment
Open

Out of date safety note on #[ffi_function]? #123

recatek opened this issue Oct 15, 2024 · 1 comment
Labels
c-core Interoptopus Core Crate enhancement Make existing things better.

Comments

@recatek
Copy link
Contributor

recatek commented Oct 15, 2024

This is a complicated topic, so correct me if I'm wrong here, but #[ffi_function] states:

/// # Safety
///
/// ⚠️ You _must_ ensure that methods exported with `#[ffi_function]` will never panic. We highly encourage you
/// to wrap all your code in panic guards. This is a standard Rust FFI concern and has nothing to do with Interoptopus.
/// Failure to follow this advice will probably lead to undefined behavior down the road. The author has been there and does not recommend it.

I believe this is no longer the case now that c_unwind was stabilized and the default behavior for extern "C" was changed in Rust 1.81. See rust-lang/rust#116088

It still may be a good idea to use panic guards for functionality's sake, but I believe it's no longer UB as any extern "C" function that hits a panic will abort rather than let the unwind cross the FFI boundary now.

@ralfbiedert
Copy link
Owner

People using older compilers might still run into that issue, but with the next release(s) we could bump our MSRV to 1.81 and remove some auto-generated panic guards to increase performance a bit.

@ralfbiedert ralfbiedert added c-core Interoptopus Core Crate enhancement Make existing things better. labels Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-core Interoptopus Core Crate enhancement Make existing things better.
Projects
None yet
Development

No branches or pull requests

2 participants