3 ms·
It looks like it uses setjmp/longjmp for error handling. Is there a way to ensure Janet never calls setjmp/longjmp? If not, it won't be embeddable in Rust (and
by m0th87 8y ago
It looks like it uses setjmp/longjmp for error handling. Is there a way to ensure Janet never calls setjmp/longjmp? If not, it won't be embeddable in Rust (and maybe C++?) due to RAII.
- kosinus 8y agoI ran into this earlier with Lua for different reason, and recently discovered PHP does this too. Maybe we just need to find a way around it? I was thinking of trying to bridge jumps with the Rust panic mechanism. (Basically try-catch at each boundary.)
- steveklabnik 8y agoI’m on my phone so I can’t get into it, but there were bugs around this with lua and rust that got resolved, so there is some way of dealing with this.
- bakpakin 8y agoJanet uses setjmp/longjmp for error handling because most alternatives in C don't compose well or are incredibly verbose/inefficient. The C API is not documented yet, but in general one could use setjmp at C++/Rust <-> C boundary points to prevent panics from jumping over C++/Rust stack frames. However, many functions in the C API will not panic (longjmp to the last save point). The overhead could be minimized by only calling setjmp for API calls that can panic. Just spitballing here.
- cbcoutinho 8y agoHandling exceptions might be different in Janet compared to perl, but it is possible to handle them while being embedded. You could essentially try/catch around every ffi boundary, which is the point brought up in this talk at 14.45 https://youtu.be/gwmtFzggE18 https://youtu.be/gwmtFzggE18