mirror of
https://github.com/ziglang/zig.git
synced 2026-02-14 05:20:34 +00:00
startup code respects root source file's event_loop if present
This commit is contained in:
parent
081c62fc00
commit
d6dec80261
@ -191,25 +191,27 @@ const bad_main_ret = "expected return type of main to be 'void', '!void', 'noret
|
||||
// and we want fewer call frames in stack traces.
|
||||
inline fn initEventLoopAndCallMain() u8 {
|
||||
if (std.event.Loop.instance) |loop| {
|
||||
loop.init() catch |err| {
|
||||
std.debug.warn("error: {}\n", @errorName(err));
|
||||
if (@errorReturnTrace()) |trace| {
|
||||
std.debug.dumpStackTrace(trace.*);
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
defer loop.deinit();
|
||||
if (!@hasDecl(root, "event_loop")) {
|
||||
loop.init() catch |err| {
|
||||
std.debug.warn("error: {}\n", @errorName(err));
|
||||
if (@errorReturnTrace()) |trace| {
|
||||
std.debug.dumpStackTrace(trace.*);
|
||||
}
|
||||
return 1;
|
||||
};
|
||||
defer loop.deinit();
|
||||
|
||||
var result: u8 = undefined;
|
||||
var frame: @Frame(callMain) = undefined;
|
||||
_ = @asyncCall(&frame, &result, callMain);
|
||||
loop.run();
|
||||
return result;
|
||||
} else {
|
||||
// This is marked inline because for some reason LLVM in release mode fails to inline it,
|
||||
// and we want fewer call frames in stack traces.
|
||||
return @inlineCall(callMain);
|
||||
var result: u8 = undefined;
|
||||
var frame: @Frame(callMain) = undefined;
|
||||
_ = @asyncCall(&frame, &result, callMain);
|
||||
loop.run();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// This is marked inline because for some reason LLVM in release mode fails to inline it,
|
||||
// and we want fewer call frames in stack traces.
|
||||
return @inlineCall(callMain);
|
||||
}
|
||||
|
||||
// This is not marked inline because it is called with @asyncCall when
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user