diff options
| author | Isaac Freund <mail@isaacfreund.com> | 2024-06-15 22:22:11 +0200 |
|---|---|---|
| committer | Isaac Freund <mail@isaacfreund.com> | 2024-06-17 23:26:53 +0200 |
| commit | a1777cb5cb378374377fd1c5e37bef9292b90910 (patch) | |
| tree | 01d5ca0d0657672a8ac28ef0a2d558f21d79a4f7 /lib/std/Thread.zig | |
| parent | 687a756bf9b443ae53aa6dc3ee8f4a1550a09597 (diff) | |
| download | zig-a1777cb5cb378374377fd1c5e37bef9292b90910.tar.gz zig-a1777cb5cb378374377fd1c5e37bef9292b90910.zip | |
std: fix pthread_{get,set}name_np return type ABI
I believe this was accidentally broken when the E enum for errno values
was introduces. These functions are quite the special case in that they
return the error value directly rather than returning -1 and passing the
error value through the errno variable.
In any case, using a u16 as the return type at the ABI boundary where a
c_int is expected is asking for trouble.
Diffstat (limited to 'lib/std/Thread.zig')
| -rw-r--r-- | lib/std/Thread.zig | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/std/Thread.zig b/lib/std/Thread.zig index c126792336..adb822173e 100644 --- a/lib/std/Thread.zig +++ b/lib/std/Thread.zig @@ -75,7 +75,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { } } else { const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return, .RANGE => unreachable, else => |e| return posix.unexpectedErrno(e), @@ -119,14 +119,14 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { if (self.getHandle() != std.c.pthread_self()) return error.Unsupported; const err = std.c.pthread_setname_np(name_with_terminator.ptr); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return, else => |e| return posix.unexpectedErrno(e), } }, .netbsd, .solaris, .illumos => if (use_pthreads) { const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return, .INVAL => unreachable, .SRCH => unreachable, @@ -144,7 +144,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { }, .dragonfly => if (use_pthreads) { const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return, .INVAL => unreachable, .FAULT => unreachable, @@ -180,7 +180,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co } } else { const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return std.mem.sliceTo(buffer, 0), .RANGE => unreachable, else => |e| return posix.unexpectedErrno(e), @@ -219,7 +219,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co }, .macos, .ios, .watchos, .tvos, .visionos => if (use_pthreads) { const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return std.mem.sliceTo(buffer, 0), .SRCH => unreachable, else => |e| return posix.unexpectedErrno(e), @@ -227,7 +227,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co }, .netbsd, .solaris, .illumos => if (use_pthreads) { const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return std.mem.sliceTo(buffer, 0), .INVAL => unreachable, .SRCH => unreachable, @@ -243,7 +243,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co }, .dragonfly => if (use_pthreads) { const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); - switch (err) { + switch (@as(posix.E, @enumFromInt(err))) { .SUCCESS => return std.mem.sliceTo(buffer, 0), .INVAL => unreachable, .FAULT => unreachable, |
