You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like support for setjmp/longjmp (and friends sigsetjmp/siglongjmp). The use case is as follows:
I am trying to integrate with postgres (written in C), which means calling into postgres functions. The postgres exception mechanism uses sigsetjmp/siglongjmp.
The idea is, right before calling a postgres function via FFI call, I would do what postgres does in its PG_TRY() / PG_CATCH() macros, which involves sigsetjmp() and some local variable manipulation, and updating a global pointer. That would allow me to catch the siglongjmp() before it bypasses any rust frames, turn it into a rust panic, and properly unwind.
Later, before returning to postgres, I could catch this panic unwind in the highest rust frame, and turn it back into a siglongjmp(). I could be careful that all non-trivial variables have gone out of scope before the siglongjmp() takes place, so that no important destructors are skipped.
If this is a reasonable thing to do, I'd be willing to try to implement it for the libc crate and offer a patch, though I may need some help getting the platform stuff right (because the jmp_buf struct size is platform-dependent).
If it's not a reasonable thing to do, please let me know.
The text was updated successfully, but these errors were encountered:
Based on discussion at #1216, it sounds like the correct thing to do would be to add intrinsics rather than binding the functions in libc. And that if we were to add these to libc, we would first need an attribute to indicate that a function may return twice.
There is also an open RFC issue at rust-lang/rfcs#2625 and I think some resolution there is necessary in order to do anything here, so I am just going to close this for now.
I would like support for setjmp/longjmp (and friends sigsetjmp/siglongjmp). The use case is as follows:
I am trying to integrate with postgres (written in C), which means calling into postgres functions. The postgres exception mechanism uses sigsetjmp/siglongjmp.
The idea is, right before calling a postgres function via FFI call, I would do what postgres does in its PG_TRY() / PG_CATCH() macros, which involves sigsetjmp() and some local variable manipulation, and updating a global pointer. That would allow me to catch the siglongjmp() before it bypasses any rust frames, turn it into a rust panic, and properly unwind.
Later, before returning to postgres, I could catch this panic unwind in the highest rust frame, and turn it back into a siglongjmp(). I could be careful that all non-trivial variables have gone out of scope before the siglongjmp() takes place, so that no important destructors are skipped.
If this is a reasonable thing to do, I'd be willing to try to implement it for the libc crate and offer a patch, though I may need some help getting the platform stuff right (because the jmp_buf struct size is platform-dependent).
If it's not a reasonable thing to do, please let me know.
The text was updated successfully, but these errors were encountered: