| author | |
| committer | |
| log | a1777cb5cb378374377fd1c5e37bef9292b90910 |
| tree | 01d5ca0d0657672a8ac28ef0a2d558f21d79a4f7 |
| parent | 687a756bf9b443ae53aa6dc3ee8f4a1550a09597 |
| signature |
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.6 files changed, 18 insertions(+), 18 deletions(-)
lib/std/Thread.zig+8-8| ... | @@ -75,7 +75,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { | ... | @@ -75,7 +75,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 75 | } | 75 | } |
| 76 | } else { | 76 | } else { |
| 77 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); | 77 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); |
| 78 | switch (err) { | 78 | switch (@as(posix.E, @enumFromInt(err))) { |
| 79 | .SUCCESS => return, | 79 | .SUCCESS => return, |
| 80 | .RANGE => unreachable, | 80 | .RANGE => unreachable, |
| 81 | else => |e| return posix.unexpectedErrno(e), | 81 | else => |e| return posix.unexpectedErrno(e), |
| ... | @@ -119,14 +119,14 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { | ... | @@ -119,14 +119,14 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 119 | if (self.getHandle() != std.c.pthread_self()) return error.Unsupported; | 119 | if (self.getHandle() != std.c.pthread_self()) return error.Unsupported; |
| 120 | 120 | ||
| 121 | const err = std.c.pthread_setname_np(name_with_terminator.ptr); | 121 | const err = std.c.pthread_setname_np(name_with_terminator.ptr); |
| 122 | switch (err) { | 122 | switch (@as(posix.E, @enumFromInt(err))) { |
| 123 | .SUCCESS => return, | 123 | .SUCCESS => return, |
| 124 | else => |e| return posix.unexpectedErrno(e), | 124 | else => |e| return posix.unexpectedErrno(e), |
| 125 | } | 125 | } |
| 126 | }, | 126 | }, |
| 127 | .netbsd, .solaris, .illumos => if (use_pthreads) { | 127 | .netbsd, .solaris, .illumos => if (use_pthreads) { |
| 128 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null); | 128 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null); |
| 129 | switch (err) { | 129 | switch (@as(posix.E, @enumFromInt(err))) { |
| 130 | .SUCCESS => return, | 130 | .SUCCESS => return, |
| 131 | .INVAL => unreachable, | 131 | .INVAL => unreachable, |
| 132 | .SRCH => unreachable, | 132 | .SRCH => unreachable, |
| ... | @@ -144,7 +144,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { | ... | @@ -144,7 +144,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void { |
| 144 | }, | 144 | }, |
| 145 | .dragonfly => if (use_pthreads) { | 145 | .dragonfly => if (use_pthreads) { |
| 146 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); | 146 | const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr); |
| 147 | switch (err) { | 147 | switch (@as(posix.E, @enumFromInt(err))) { |
| 148 | .SUCCESS => return, | 148 | .SUCCESS => return, |
| 149 | .INVAL => unreachable, | 149 | .INVAL => unreachable, |
| 150 | .FAULT => unreachable, | 150 | .FAULT => unreachable, |
| ... | @@ -180,7 +180,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co | ... | @@ -180,7 +180,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 180 | } | 180 | } |
| 181 | } else { | 181 | } else { |
| 182 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); | 182 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); |
| 183 | switch (err) { | 183 | switch (@as(posix.E, @enumFromInt(err))) { |
| 184 | .SUCCESS => return std.mem.sliceTo(buffer, 0), | 184 | .SUCCESS => return std.mem.sliceTo(buffer, 0), |
| 185 | .RANGE => unreachable, | 185 | .RANGE => unreachable, |
| 186 | else => |e| return posix.unexpectedErrno(e), | 186 | else => |e| return posix.unexpectedErrno(e), |
| ... | @@ -219,7 +219,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co | ... | @@ -219,7 +219,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 219 | }, | 219 | }, |
| 220 | .macos, .ios, .watchos, .tvos, .visionos => if (use_pthreads) { | 220 | .macos, .ios, .watchos, .tvos, .visionos => if (use_pthreads) { |
| 221 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); | 221 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); |
| 222 | switch (err) { | 222 | switch (@as(posix.E, @enumFromInt(err))) { |
| 223 | .SUCCESS => return std.mem.sliceTo(buffer, 0), | 223 | .SUCCESS => return std.mem.sliceTo(buffer, 0), |
| 224 | .SRCH => unreachable, | 224 | .SRCH => unreachable, |
| 225 | else => |e| return posix.unexpectedErrno(e), | 225 | else => |e| return posix.unexpectedErrno(e), |
| ... | @@ -227,7 +227,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co | ... | @@ -227,7 +227,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 227 | }, | 227 | }, |
| 228 | .netbsd, .solaris, .illumos => if (use_pthreads) { | 228 | .netbsd, .solaris, .illumos => if (use_pthreads) { |
| 229 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); | 229 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); |
| 230 | switch (err) { | 230 | switch (@as(posix.E, @enumFromInt(err))) { |
| 231 | .SUCCESS => return std.mem.sliceTo(buffer, 0), | 231 | .SUCCESS => return std.mem.sliceTo(buffer, 0), |
| 232 | .INVAL => unreachable, | 232 | .INVAL => unreachable, |
| 233 | .SRCH => unreachable, | 233 | .SRCH => unreachable, |
| ... | @@ -243,7 +243,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co | ... | @@ -243,7 +243,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co |
| 243 | }, | 243 | }, |
| 244 | .dragonfly => if (use_pthreads) { | 244 | .dragonfly => if (use_pthreads) { |
| 245 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); | 245 | const err = std.c.pthread_getname_np(self.getHandle(), buffer.ptr, max_name_len + 1); |
| 246 | switch (err) { | 246 | switch (@as(posix.E, @enumFromInt(err))) { |
| 247 | .SUCCESS => return std.mem.sliceTo(buffer, 0), | 247 | .SUCCESS => return std.mem.sliceTo(buffer, 0), |
| 248 | .INVAL => unreachable, | 248 | .INVAL => unreachable, |
| 249 | .FAULT => unreachable, | 249 | .FAULT => unreachable, |
lib/std/c/darwin.zig+2-2| ... | @@ -851,8 +851,8 @@ pub const pthread_attr_t = extern struct { | ... | @@ -851,8 +851,8 @@ pub const pthread_attr_t = extern struct { |
| 851 | }; | 851 | }; |
| 852 | 852 | ||
| 853 | pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int; | 853 | pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int; |
| 854 | pub extern "c" fn pthread_setname_np(name: [*:0]const u8) E; | 854 | pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int; |
| 855 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; | 855 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; |
| 856 | pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int; | 856 | pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int; |
| 857 | pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int; | 857 | pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int; |
| 858 | pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int; | 858 | pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int; |
lib/std/c/dragonfly.zig+2-2| ... | @@ -29,8 +29,8 @@ pub const pthread_attr_t = extern struct { // copied from freebsd | ... | @@ -29,8 +29,8 @@ pub const pthread_attr_t = extern struct { // copied from freebsd |
| 29 | 29 | ||
| 30 | pub const sem_t = ?*opaque {}; | 30 | pub const sem_t = ?*opaque {}; |
| 31 | 31 | ||
| 32 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E; | 32 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int; |
| 33 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; | 33 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; |
| 34 | 34 | ||
| 35 | pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int; | 35 | pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int; |
| 36 | pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int; | 36 | pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int; |
lib/std/c/linux.zig+2-2| ... | @@ -318,8 +318,8 @@ pub const sem_t = extern struct { | ... | @@ -318,8 +318,8 @@ pub const sem_t = extern struct { |
| 318 | 318 | ||
| 319 | const __SIZEOF_SEM_T = 4 * @sizeOf(usize); | 319 | const __SIZEOF_SEM_T = 4 * @sizeOf(usize); |
| 320 | 320 | ||
| 321 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E; | 321 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int; |
| 322 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; | 322 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; |
| 323 | 323 | ||
| 324 | pub const RTLD = struct { | 324 | pub const RTLD = struct { |
| 325 | pub const LAZY = 1; | 325 | pub const LAZY = 1; |
lib/std/c/netbsd.zig+2-2| ... | @@ -51,8 +51,8 @@ pub const pthread_attr_t = extern struct { | ... | @@ -51,8 +51,8 @@ pub const pthread_attr_t = extern struct { |
| 51 | 51 | ||
| 52 | pub const sem_t = ?*opaque {}; | 52 | pub const sem_t = ?*opaque {}; |
| 53 | 53 | ||
| 54 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E; | 54 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int; |
| 55 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; | 55 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; |
| 56 | 56 | ||
| 57 | pub const blkcnt_t = i64; | 57 | pub const blkcnt_t = i64; |
| 58 | pub const blksize_t = i32; | 58 | pub const blksize_t = i32; |
lib/std/c/solaris.zig+2-2| ... | @@ -34,8 +34,8 @@ pub const sem_t = extern struct { | ... | @@ -34,8 +34,8 @@ pub const sem_t = extern struct { |
| 34 | __pad2: [2]u64 = [_]u64{0} ** 2, | 34 | __pad2: [2]u64 = [_]u64{0} ** 2, |
| 35 | }; | 35 | }; |
| 36 | 36 | ||
| 37 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E; | 37 | pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int; |
| 38 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E; | 38 | pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int; |
| 39 | 39 | ||
| 40 | pub const blkcnt_t = i64; | 40 | pub const blkcnt_t = i64; |
| 41 | pub const blksize_t = i32; | 41 | pub const blksize_t = i32; |