authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2024-06-15 22:22:11+02:00
committergravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2024-06-17 23:26:53+02:00
loga1777cb5cb378374377fd1c5e37bef9292b90910
tree01d5ca0d0657672a8ac28ef0a2d558f21d79a4f7
parent687a756bf9b443ae53aa6dc3ee8f4a1550a09597
signaturelock-open Commit is signed but in an unrecognized format.

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.

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;
120120
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};
852852
853pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int;853pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int;
854pub extern "c" fn pthread_setname_np(name: [*:0]const u8) E;854pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
855pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;855pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
856pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;856pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
857pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;857pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
858pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;858pub 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
2929
30pub const sem_t = ?*opaque {};30pub const sem_t = ?*opaque {};
3131
32pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;32pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
33pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;33pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
3434
35pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int;35pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int;
36pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int;36pub 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 {
318318
319const __SIZEOF_SEM_T = 4 * @sizeOf(usize);319const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
320320
321pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;321pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
322pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;322pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
323323
324pub const RTLD = struct {324pub 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 {
5151
52pub const sem_t = ?*opaque {};52pub const sem_t = ?*opaque {};
5353
54pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;54pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
55pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;55pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
5656
57pub const blkcnt_t = i64;57pub const blkcnt_t = i64;
58pub const blksize_t = i32;58pub 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};
3636
37pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;37pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
38pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;38pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
3939
40pub const blkcnt_t = i64;40pub const blkcnt_t = i64;
41pub const blksize_t = i32;41pub const blksize_t = i32;