diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-10-17 15:46:36 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-10-17 15:46:36 -0700 |
| commit | 0011def2b24f63233f2ee24909701f92264c2ef5 (patch) | |
| tree | e196ebce13d03869524583f41fea46e3d83c0f52 /lib/std/start.zig | |
| parent | 245d98d32dd29e80de9732f415a4731748008acf (diff) | |
| download | zig-0011def2b24f63233f2ee24909701f92264c2ef5.tar.gz zig-0011def2b24f63233f2ee24909701f92264c2ef5.zip | |
fix compilation error when building with io_mode evented
The merge of #5613 introduced a regression when building with io_mode
evented, fixed in this commit.
closes #6715
Diffstat (limited to 'lib/std/start.zig')
| -rw-r--r-- | lib/std/start.zig | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig index cb838fef34..b8e0de9574 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -159,7 +159,7 @@ fn WinStartup() callconv(.Stdcall) noreturn { std.debug.maybeEnableSegfaultHandler(); - std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain(u8, callMain)); + std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain()); } fn wWinMainCRTStartup() callconv(.Stdcall) noreturn { @@ -170,8 +170,7 @@ fn wWinMainCRTStartup() callconv(.Stdcall) noreturn { std.debug.maybeEnableSegfaultHandler(); - const result = initEventLoopAndCallMain(std.os.windows.INT, call_wWinMain); - std.os.windows.kernel32.ExitProcess(@bitCast(std.os.windows.UINT, result)); + std.os.windows.kernel32.ExitProcess(initEventLoopAndCallWinMain()); } // TODO https://github.com/ziglang/zig/issues/265 @@ -225,7 +224,7 @@ fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 { std.debug.maybeEnableSegfaultHandler(); - return initEventLoopAndCallMain(u8, callMain); + return initEventLoopAndCallMain(); } fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) callconv(.C) i32 { @@ -240,7 +239,7 @@ const bad_main_ret = "expected return type of main to be 'void', '!void', 'noret // 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. -inline fn initEventLoopAndCallMain(comptime Out: type, comptime mainFunc: fn () Out) Out { +inline fn initEventLoopAndCallMain() u8 { if (std.event.Loop.instance) |loop| { if (!@hasDecl(root, "event_loop")) { loop.init() catch |err| { @@ -254,7 +253,7 @@ inline fn initEventLoopAndCallMain(comptime Out: type, comptime mainFunc: fn () var result: u8 = undefined; var frame: @Frame(callMainAsync) = undefined; - _ = @asyncCall(&frame, &result, callMainAsync, .{ u8, mainFunc, loop }); + _ = @asyncCall(&frame, &result, callMainAsync, .{loop}); loop.run(); return result; } @@ -262,13 +261,44 @@ inline fn initEventLoopAndCallMain(comptime Out: type, comptime mainFunc: fn () // 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 @call(.{ .modifier = .always_inline }, mainFunc, .{}); + return @call(.{ .modifier = .always_inline }, callMain, .{}); } -fn callMainAsync(comptime Out: type, comptime mainProc: fn () Out, loop: *std.event.Loop) callconv(.Async) Out { + +// 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. +// TODO This function is duplicated from initEventLoopAndCallMain instead of using generics +// because it is working around stage1 compiler bugs. +inline fn initEventLoopAndCallWinMain() std.os.windows.INT { + if (std.event.Loop.instance) |loop| { + if (!@hasDecl(root, "event_loop")) { + loop.init() catch |err| { + std.log.err("{}", .{@errorName(err)}); + if (@errorReturnTrace()) |trace| { + std.debug.dumpStackTrace(trace.*); + } + return 1; + }; + defer loop.deinit(); + + var result: u8 = undefined; + var frame: @Frame(callMainAsync) = undefined; + _ = @asyncCall(&frame, &result, callMainAsync, .{loop}); + 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 @call(.{ .modifier = .always_inline }, call_wWinMain, .{}); +} + +fn callMainAsync(loop: *std.event.Loop) callconv(.Async) u8 { // This prevents the event loop from terminating at least until main() has returned. + // TODO This shouldn't be needed here; it should be in the event loop code. loop.beginOneEvent(); defer loop.finishOneEvent(); - return mainProc(); + return callMain(); } // This is not marked inline because it is called with @asyncCall when |
