Fix debug I/O color detection for most targets

On POSIX, start.zig did not reset the `environ_initialized` field, which
prevented the environment variables from ever actually getting scanned.

On Windows, environment variable scanning is allocation-free, so it's
okay for `std.Io.Threaded.init_single_threaded` to use the global
environment block.
This commit is contained in:
Carl Åstholm
2026-04-08 00:56:58 +02:00
committed by Andrew Kelley
parent c61e18006f
commit 81be7f62ec
2 changed files with 18 additions and 14 deletions
+17 -14
View File
@@ -1671,20 +1671,23 @@ pub fn init(
/// When initialized this way:
/// * cancel requests have no effect.
/// * `deinit` is safe, but unnecessary to call.
pub const init_single_threaded: Threaded = .{
.allocator = .failing,
.stack_size = std.Thread.SpawnConfig.default_stack_size,
.async_limit = .nothing,
.cpu_count_error = null,
.concurrent_limit = .nothing,
.old_sig_io = undefined,
.old_sig_pipe = undefined,
.have_signal_handler = false,
.argv0 = .empty,
.environ_initialized = true,
.environ = .empty,
.worker_threads = .init(null),
.disable_memory_mapping = false,
pub const init_single_threaded: Threaded = init: {
const env_block: process.Environ.Block = if (is_windows) .global else .empty;
break :init .{
.allocator = .failing,
.stack_size = std.Thread.SpawnConfig.default_stack_size,
.async_limit = .nothing,
.cpu_count_error = null,
.concurrent_limit = .nothing,
.old_sig_io = undefined,
.old_sig_pipe = undefined,
.have_signal_handler = false,
.argv0 = .empty,
.environ_initialized = env_block.isEmpty(),
.environ = .{ .process_environ = .{ .block = env_block } },
.worker_threads = .init(null),
.disable_memory_mapping = false,
};
};
var global_single_threaded_instance: Threaded = .init_single_threaded;
+1
View File
@@ -631,6 +631,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [:null]?[*:0]u8)
if (std.Options.debug_threaded_io) |t| {
if (@sizeOf(std.Io.Threaded.Argv0) != 0) t.argv0.value = argv[0];
t.environ = .{ .process_environ = .{ .block = env_block } };
t.environ_initialized = env_block.isEmpty();
}
std.Thread.maybeAttachSignalStack();
std.debug.maybeEnableSegfaultHandler();