Make FFI Functions Panic-Safe to Avoid Undefined Behavior #8
Labels
No labels
Epic
GHA
Release
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
major
question
rust
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
NiXTheDev/Ogex#8
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal: Prevent Rust panics from unwinding across the C ABI boundary, which is undefined behavior.
All functions in
ffi.rsthat are called from C must not panic. Currently, they may indirectly panic viaunwrap(),expect(), or out-of-bounds access.Solution:
Wrap the body of every FFI-exported function with
std::panic::catch_unwind. Convert any panic into an error return (e.g., null pointer or error code) and optionally set an error message.Example:
Considerations:
Implementation Steps: