-
Notifications
You must be signed in to change notification settings - Fork 89
Description
Anybody using the setjmp/longjmp support in MPack? I'm going to remove it in 0.6 and replace it with an error callback and context.
The reason I'm removing it is because it's not safe to use in the straightforward way you would expect. The docs encourage putting a reader/writer/tree on the stack, but the contents of non-volatile stack variables that have changed after setjmp are undefined after the longjmp. To use it safely you'd have to declare the reader as volatile, or allocate it off the stack (and not change the pointer to it obviously.) Libraries like libpng that provide longjmp support wrap their structures so that they are allocated off the stack which is why they can offer this support safely.
I'll be retaining the non-local jump safety across MPack though, so from any error handler you'll still be able to longjmp or throw through MPack. An error callback will also make it easier to create C++ bindings which will have the option of throwing on error.