startup code respects root source file's event_loop if present

This commit is contained in:
Andrew Kelley 2019-10-31 14:21:04 -04:00
parent 081c62fc00
commit d6dec80261
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9

View File

@ -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