Skip to content

[discussion] Designing a crash-resistant library in Zig #1740

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

Closed
thejoshwolfe opened this issue Nov 17, 2018 · 4 comments
Closed

[discussion] Designing a crash-resistant library in Zig #1740

thejoshwolfe opened this issue Nov 17, 2018 · 4 comments
Labels
question No questions on the issue tracker, please.
Milestone

Comments

@thejoshwolfe
Copy link
Contributor

I want to make a library that an IDE links against. It would be unacceptable if a bug in the library crashed the IDE process. Obviously perfect crash-proofness is unattainable (halting problem), but there's a lot of bugs that can be checked with Zig's runtime safety checks.

Is it possible to install a panic handler in my library so that if anything in the library panics, my library functions return with an error instead of bringing down the host application? Possibly something with setjmp/longjmp?

(This might be outside the scope of Zig) Is it possible to install a segfault handler that does something similar?

The library's API would all be mostly stateless functions, possibly doing IO, but not spawning extra threads or anything. The library would not call any non-zig library, so the whole library should be statically linked, I think.

@thejoshwolfe thejoshwolfe added the question No questions on the issue tracker, please. label Nov 17, 2018
@emekoi
Copy link
Contributor

emekoi commented Nov 17, 2018

you can define your own panic function. it just has to go in your root project file.

@andrewrk
Copy link
Member

Related: #426

@andrewrk andrewrk added this to the 1.0.0 milestone Nov 17, 2018
@emekoi
Copy link
Contributor

emekoi commented Nov 18, 2018

here is a custom segfault handler for posix and windows that might point you in the right direction. i'm not sure if you know nim but i imagine you can understand whats going on.

edit: i ported the windows portion to zig here.

@andrewrk
Copy link
Member

Crash resisting should be solved using appropriate OS features, e.g. threads or processes.

@andrewrk andrewrk modified the milestones: 1.0.0, 0.7.0 Apr 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question No questions on the issue tracker, please.
Projects
None yet
Development

No branches or pull requests

3 participants