From 83617eac5902a9e66449e8c409dfa9e560bf9f12 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 29 Mar 2022 22:16:43 -0700 Subject: [PATCH] std: avoid referencing event loop when io_mode is blocking This prevents unwanted symbols from ending up in the output binary. --- lib/std/event/loop.zig | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/std/event/loop.zig b/lib/std/event/loop.zig index 23c89aabc5..1eaa95d249 100644 --- a/lib/std/event/loop.zig +++ b/lib/std/event/loop.zig @@ -103,12 +103,17 @@ pub const Loop = struct { }; }; - var global_instance_state: Loop = undefined; - const default_instance: ?*Loop = switch (std.io.mode) { + const LoopOrVoid = switch (std.io.mode) { + .blocking => void, + .evented => Loop, + }; + + var global_instance_state: LoopOrVoid = undefined; + const default_instance: ?*LoopOrVoid = switch (std.io.mode) { .blocking => null, .evented => &global_instance_state, }; - pub const instance: ?*Loop = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance; + pub const instance: ?*LoopOrVoid = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance; /// TODO copy elision / named return values so that the threads referencing *Loop /// have the correct pointer value.