From 229800482d28c9d55abf116cb315c78adddabe11 Mon Sep 17 00:00:00 2001 From: mlugg Date: Thu, 7 Mar 2024 15:28:26 +0000 Subject: [PATCH] std.os.linux: do not use `usingnamespace` to define getauxval This usage of `usingnamespace` was removed fairly trivially - the resulting code is, IMO, more clear. Eliminates one more usage of `usingnamespace` from the standard library. --- lib/std/os/linux.zig | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index a665d10e14..2539444f26 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -388,20 +388,21 @@ pub usingnamespace @import("linux/io_uring.zig"); /// Set by startup code, used by `getauxval`. pub var elf_aux_maybe: ?[*]std.elf.Auxv = null; -pub usingnamespace if (switch (builtin.zig_backend) { +const extern_getauxval = switch (builtin.zig_backend) { // Calling extern functions is not yet supported with these backends .stage2_aarch64, .stage2_arm, .stage2_riscv64, .stage2_sparc64 => false, else => !builtin.link_libc, -}) struct { - /// See `std.elf` for the constants. - /// This matches the libc getauxval function. - pub extern fn getauxval(index: usize) usize; - comptime { +}; + +comptime { + if (extern_getauxval) { @export(getauxvalImpl, .{ .name = "getauxval", .linkage = .Weak }); } -} else struct { - pub const getauxval = getauxvalImpl; -}; +} + +pub const getauxval = if (extern_getauxval) struct { + extern fn getauxval(index: usize) usize; +}.getauxval else getauxvalImpl; fn getauxvalImpl(index: usize) callconv(.C) usize { const auxv = elf_aux_maybe orelse return 0;