Unwinding through FFI after Rust 1.33

You keep editing your post before I can reply! :slight_smile:

It is possible to "unwind" over Rust code using longjmp, so you could have C call setjmp then call back into Rust for a group of operations, but no, it wouldn't work with Drop, so you would have to avoid having any variables with destructors in that code (or at least accept that they wouldn't run).

Hmm... another option would be to include wrappers in your crate for each libjpeg API, but written in C++ instead of C. The error handler would also be written in C++ and would throw a C++ exception, and the API wrappers would catch the exception and translate it into a return code. That would avoid the upfront cost of setjmp.