Closed
Description
(as discussed on IRC):
Some C environments/libraries use setjmp+longjmp for control flow. e.g. writing PostgreSQL Extensions or the Lua C API.
A C function longjmp
-ing out may result in zig code not being run. This may include defer
-d code for cleanup, which will result in various resource leaks or even deadlocks.
Proposed Solution
Functions should gain a may longjmp
annotation (possibly with an arbitrary ID?).
- Such a function can only be called from other functions annotated with
may longjmp
unless a matchingsetjmp
annotation is found. - A compile error (possibly warning?) is thrown if
defer
occurs before amay longjmp
function call in the same (or child) scope.
It is fine if thedefer
block occurs after the call to themay longjmp
function, as thelongjmp()
would already have happened.
Activity