-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
set error mode to remove error popups #2445
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
Conversation
@Sahnvour if you have time can I get your opinion on this PR?
|
Looks good to me, just a couple things:
|
i wasn't sure what the lowest version of windows that zig wanted to guarantee compatibility with was. because if edit: perhaps we should add a minimum version for the windows entries on the support table? |
Shouldn't we only do this for command-line applications? Perhaps change this based on SUBSYSTEM? |
@daurnimator zig doesn't expose the subsystem to user code. |
@Sahnvour what would the advantage be of using |
I would mainly do it because the docs say so. But after some research, it seems the problem is that the error mode is a process global and multiple threads accessing/modifying it is not safe. That's probably not a concern in this specific case because we know no other thread can mess with it, but as a rule of thumb I think using a more restricted API/feature should be preferred, when available. |
preferably merge #2462 before this one so, so we can switch on the subsystem and decide whether to enable error popups depending on that. |
93f99a5
to
bf769f4
Compare
std/special/start.zig
Outdated
@@ -61,6 +61,14 @@ extern fn WinMainCRTStartup() noreturn { | |||
if (!builtin.single_threaded) { | |||
_ = @import("start_windows_tls.zig"); | |||
} | |||
|
|||
// TODO we need a userland function for detecting the subsystem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this comment still accurate? What's the issue? Can I help with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry i forgot to remove this. that fucntion is std.os.windows.getSubSystem
std/os/windows.zig
Outdated
@@ -779,3 +779,18 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { | |||
} | |||
return error.Unexpected; | |||
} | |||
|
|||
pub fn getSubSystem() ?builtin.SubSystem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about making this be a pub const subsystem = blk: { ... };
rather than a function? This way it will always be comptime known.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, but this implementation isn't neccessarily complete. if you have const wWinMain = 0
in your root file it will report the wrong susbystem.
One thing I'm not clear on is why we should change from the default. Raymond Chen quotes from the documentation:
So it seems then that the parent process has chosen the error mode, why should zig programs override that before main()?
Note that this code is executing before main() and so the application has not had a chance to create threads yet. So a global function would not only work but probably be more appropriate. |
Ah, @emekoi already answered this in #2071 (comment). This does not say there should be a condition on the subsystem. Is there any reason to do this "best practice" thing based on the subsystem? Can anyone confirm that this is actually best practice? |
the condition on the subsystem is based on the reasoning that if you building an application under the windows subsystem error pop-ups are probably okay. if you're building a console application pop-ups probably aren't. |
This reasoning implies that the "best practice" advice is not entirely correct, or at least not complete. Which makes me sort of question the whole thing, and brings me back to the question "So it seems then that the parent process has chosen the error mode, why should zig programs override that before main()?" e.g. cmd.exe in theory has the correct error mode set, why should child processes need to set it? I think one data point that would be worth collecting here would be whether or not msvcrt calls SetErrorMode (or the threaded one) before calling main(). Is there a way to intercept Windows lib calls to find out? |
The original issue is "When linked against windows' libc, calling abort opens a popup". It seems to me that:
I don't see why zig would then call SetErrorMode before main(). If you were to write a C program linked against msvcrt and then call I mean, if this is a chance for zig to be better than C, great, let's do it. But there must be something I don't understand here, something smells fishy. By the way, I don't get error popups when I run the zig test suite, does anyone else? As far as I remember, I didn't override any default config. |
closes #2071