Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove setjmp/longjmp #19

Closed
ludocode opened this issue Sep 7, 2015 · 1 comment
Closed

Remove setjmp/longjmp #19

ludocode opened this issue Sep 7, 2015 · 1 comment

Comments

@ludocode
Copy link
Owner

ludocode commented Sep 7, 2015

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.

@ludocode
Copy link
Owner Author

Fixed 68fc550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant