authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-31 14:21:04-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-31 14:21:04-04:00
logd6dec8026192503a8d64587063b2dc10b14df665
tree06e05ffb864e4fdbbe3575c27b751fecb15c5da7
parent081c62fc0044e3bbe8d87873ef1ccc985911c812
signaturelock-open Commit is signed but in an unrecognized format.

startup code respects root source file's event_loop if present


1 files changed, 20 insertions(+), 18 deletions(-)

lib/std/special/start.zig+20-18
......@@ -191,25 +191,27 @@ const bad_main_ret = "expected return type of main to be 'void', '!void', 'noret
191191// and we want fewer call frames in stack traces.
192192inline fn initEventLoopAndCallMain() u8 {
193193 if (std.event.Loop.instance) |loop| {
194 loop.init() catch |err| {
195 std.debug.warn("error: {}\n", @errorName(err));
196 if (@errorReturnTrace()) |trace| {
197 std.debug.dumpStackTrace(trace.*);
198 }
199 return 1;
200 };
201 defer loop.deinit();
202
203 var result: u8 = undefined;
204 var frame: @Frame(callMain) = undefined;
205 _ = @asyncCall(&frame, &result, callMain);
206 loop.run();
207 return result;
208 } else {
209 // This is marked inline because for some reason LLVM in release mode fails to inline it,
210 // and we want fewer call frames in stack traces.
211 return @inlineCall(callMain);
194 if (!@hasDecl(root, "event_loop")) {
195 loop.init() catch |err| {
196 std.debug.warn("error: {}\n", @errorName(err));
197 if (@errorReturnTrace()) |trace| {
198 std.debug.dumpStackTrace(trace.*);
199 }
200 return 1;
201 };
202 defer loop.deinit();
203
204 var result: u8 = undefined;
205 var frame: @Frame(callMain) = undefined;
206 _ = @asyncCall(&frame, &result, callMain);
207 loop.run();
208 return result;
209 }
212210 }
211
212 // This is marked inline because for some reason LLVM in release mode fails to inline it,
213 // and we want fewer call frames in stack traces.
214 return @inlineCall(callMain);
213215}
214216
215217// This is not marked inline because it is called with @asyncCall when