Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: fix a few ABI issues in the OS layer #20304

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/std/Thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -219,15 +219,15 @@ 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),
}
},
.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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lib/std/c/darwin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -851,8 +851,8 @@ pub const pthread_attr_t = extern struct {
};

pub extern "c" fn pthread_threadid_np(thread: ?std.c.pthread_t, thread_id: *u64) c_int;
pub extern "c" fn pthread_setname_np(name: [*:0]const u8) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub extern "c" fn pthread_setname_np(name: [*:0]const u8) c_int;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;
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;
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;
pub extern "c" fn pthread_set_qos_class_self_np(qos_class: qos_class_t, relative_priority: c_int) c_int;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/c/dragonfly.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub const pthread_attr_t = extern struct { // copied from freebsd

pub const sem_t = ?*opaque {};

pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;

pub extern "c" fn umtx_sleep(ptr: *const volatile c_int, value: c_int, timeout: c_int) c_int;
pub extern "c" fn umtx_wakeup(ptr: *const volatile c_int, count: c_int) c_int;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c/emscripten.zig
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub const RTLD = struct {
pub const LOCAL = 0;
};

pub const dirent = struct {
pub const dirent = extern struct {
ino: c_uint,
off: c_uint,
reclen: c_ushort,
Expand Down
8 changes: 4 additions & 4 deletions lib/std/c/linux.zig
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ pub const sem_t = extern struct {

const __SIZEOF_SEM_T = 4 * @sizeOf(usize);

pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8) c_int;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;

pub const RTLD = struct {
pub const LAZY = 1;
Expand All @@ -330,14 +330,14 @@ pub const RTLD = struct {
pub const LOCAL = 0;
};

pub const dirent = struct {
pub const dirent = extern struct {
ino: c_uint,
off: c_uint,
reclen: c_ushort,
type: u8,
name: [256]u8,
};
pub const dirent64 = struct {
pub const dirent64 = extern struct {
ino: c_ulong,
off: c_ulong,
reclen: c_ushort,
Expand Down
4 changes: 2 additions & 2 deletions lib/std/c/netbsd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub const pthread_attr_t = extern struct {

pub const sem_t = ?*opaque {};

pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;

pub const blkcnt_t = i64;
pub const blksize_t = i32;
Expand Down
4 changes: 2 additions & 2 deletions lib/std/c/solaris.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub const sem_t = extern struct {
__pad2: [2]u64 = [_]u64{0} ** 2,
};

pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) E;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) E;
pub extern "c" fn pthread_setname_np(thread: std.c.pthread_t, name: [*:0]const u8, arg: ?*anyopaque) c_int;
pub extern "c" fn pthread_getname_np(thread: std.c.pthread_t, name: [*:0]u8, len: usize) c_int;

pub const blkcnt_t = i64;
pub const blksize_t = i32;
Expand Down
Loading