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 {
7575 }
7676 } else {
7777 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
78 switch (err) {
78 switch (@as(posix.E, @enumFromInt(err))) {
7979 .SUCCESS => return,
8080 .RANGE => unreachable,
8181 else => |e| return posix.unexpectedErrno(e),
......@@ -119,14 +119,14 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
119119 if (self.getHandle() != std.c.pthread_self()) return error.Unsupported;
120120
121121 const err = std.c.pthread_setname_np(name_with_terminator.ptr);
122 switch (err) {
122 switch (@as(posix.E, @enumFromInt(err))) {
123123 .SUCCESS => return,
124124 else => |e| return posix.unexpectedErrno(e),
125125 }
126126 },
127127 .netbsd, .solaris, .illumos => if (use_pthreads) {
128128 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr, null);
129 switch (err) {
129 switch (@as(posix.E, @enumFromInt(err))) {
130130 .SUCCESS => return,
131131 .INVAL => unreachable,
132132 .SRCH => unreachable,
......@@ -144,7 +144,7 @@ pub fn setName(self: Thread, name: []const u8) SetNameError!void {
144144 },
145145 .dragonfly => if (use_pthreads) {
146146 const err = std.c.pthread_setname_np(self.getHandle(), name_with_terminator.ptr);
147 switch (err) {
147 switch (@as(posix.E, @enumFromInt(err))) {
148148 .SUCCESS => return,
149149 .INVAL => unreachable,
150150 .FAULT => unreachable,
......@@ -180,7 +180,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
180180 }
181181 } else {
182182 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))) {
184184 .SUCCESS => return std.mem.sliceTo(buffer, 0),
185185 .RANGE => unreachable,
186186 else => |e| return posix.unexpectedErrno(e),
......@@ -219,7 +219,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
219219 },
220220 .macos, .ios, .watchos, .tvos, .visionos => if (use_pthreads) {
221221 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))) {
223223 .SUCCESS => return std.mem.sliceTo(buffer, 0),
224224 .SRCH => unreachable,
225225 else => |e| return posix.unexpectedErrno(e),
......@@ -227,7 +227,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
227227 },
228228 .netbsd, .solaris, .illumos => if (use_pthreads) {
229229 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))) {
231231 .SUCCESS => return std.mem.sliceTo(buffer, 0),
232232 .INVAL => unreachable,
233233 .SRCH => unreachable,
......@@ -243,7 +243,7 @@ pub fn getName(self: Thread, buffer_ptr: *[max_name_len:0]u8) GetNameError!?[]co
243243 },
244244 .dragonfly => if (use_pthreads) {
245245 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))) {
247247 .SUCCESS => return std.mem.sliceTo(buffer, 0),
248248 .INVAL => unreachable,
249249 .FAULT => unreachable,
lib/std/c/darwin.zig+2-2
......@@ -851,8 +851,8 @@ pub const pthread_attr_t = extern struct {
851851};
852852
853853pub 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;
855pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) c_int;
856856pub extern "c" fn pthread_attr_set_qos_class_np(attr: *pthread_attr_t, qos_class: qos_class_t, relative_priority: c_int) c_int;
857857pub extern "c" fn pthread_attr_get_qos_class_np(attr: *pthread_attr_t, qos_class: *qos_class_t, relative_priority: *c_int) c_int;
858858pub 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
2929
3030pub const sem_t = ?*opaque {};
3131
32pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
33pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) c_int;
3434
3535pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int;
3636pub 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 {
318318
319319const __SIZEOF_SEM_T = 4 * @sizeOf(usize);
320320
321pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
322pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) c_int;
323323
324324pub const RTLD = struct {
325325 pub const LAZY = 1;
lib/std/c/netbsd.zig+2-2
......@@ -51,8 +51,8 @@ pub const pthread_attr_t = extern struct {
5151
5252pub const sem_t = ?*opaque {};
5353
54pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;
55pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) c_int;
5656
5757pub const blkcnt_t = i64;
5858pub const blksize_t = i32;
lib/std/c/solaris.zig+2-2
......@@ -34,8 +34,8 @@ pub const sem_t = extern struct {
3434 __pad2: [2]u64 = [_]u64{0} ** 2,
3535};
3636
37pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;
38pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) 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) c_int;
3939
4040pub const blkcnt_t = i64;
4141pub const blksize_t = i32;