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

Unwinding into FFI is undefined behavior #56

Open
janderholm opened this issue Jan 6, 2018 · 1 comment
Open

Unwinding into FFI is undefined behavior #56

janderholm opened this issue Jan 6, 2018 · 1 comment

Comments

@janderholm
Copy link

janderholm commented Jan 6, 2018

Some of the examples are using the assert! macro. This will panic and thus unwind. Unwinding across FFI boundaries however is undefined behavior and needs to be catched.

This can be solved either by:

  1. Build with panic = "abort" in cargo.toml
  2. Use std::panic::catch_unwind to catch the unwinding before it hits FFI code
  3. Same as 2. but made easier by using the macro callback_guard! from the glib crate

I prefer number 1 (better performance) as long as the library created does not actively use unwinding, for example by restarting paniced threads. Since unwinding is a very important topic when it comes to FFI I think there should be a chapter with pros and cons in the book.

@janderholm janderholm changed the title Unwinding into FFI is Undefined behaviour in examples Unwinding into FFI is undefined behaviour Jan 6, 2018
@janderholm janderholm changed the title Unwinding into FFI is undefined behaviour Unwinding into FFI is undefined behavior Jan 6, 2018
@jhg
Copy link

jhg commented Dec 25, 2020

Maybe it changed: rust-lang/rust#58760

The default was changed to abort-by-default in extern functions in this PR.

rust-lang/rust#55982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants