Skip to content
Closed
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
4 changes: 2 additions & 2 deletions lib/std/Build/Step/ConfigHeader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ fn putValue(config_header: *ConfigHeader, field_name: []const u8, comptime T: ty
.pointer => |ptr| {
switch (@typeInfo(ptr.child)) {
.array => |array| {
if (ptr.size == .One and array.child == u8) {
if (ptr.size == .one and array.child == u8) {
try config_header.values.put(field_name, .{ .string = v });
return;
}
},
.int => {
if (ptr.size == .Slice and ptr.child == u8) {
if (ptr.size == .slice and ptr.child == u8) {
try config_header.values.put(field_name, .{ .string = v });
return;
}
Expand Down
6 changes: 2 additions & 4 deletions lib/std/Build/Step/Options.zig
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ fn printType(options: *Options, out: anytype, comptime T: type, value: T, indent
return;
},
.pointer => |p| {
if (p.size != .Slice) {
if (p.size != .slice) {
@compileError("Non-slice pointers are not yet supported in build options");
}

Expand Down Expand Up @@ -318,9 +318,7 @@ fn printStruct(options: *Options, out: anytype, comptime T: type, comptime val:
try out.print(" {p_}: {s}", .{ std.zig.fmtId(field.name), type_name });
}

if (field.default_value != null) {
const default_value = @as(*field.type, @ptrCast(@alignCast(@constCast(field.default_value.?)))).*;

if (field.defaultValue()) |default_value| {
try out.writeAll(" = ");
switch (@typeInfo(@TypeOf(default_value))) {
.@"enum" => try out.print(".{s},\n", .{@tagName(default_value)}),
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Progress.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ fn maybeUpdateSize(resize_flag: bool) void {
}
}

fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) void {
fn handleSigWinch(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) void {
_ = info;
_ = ctx_ptr;
assert(sig == posix.SIG.WINCH);
Expand Down
2 changes: 1 addition & 1 deletion lib/std/Random.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fillFn: *const fn (ptr: *anyopaque, buf: []u8) void,
pub fn init(pointer: anytype, comptime fillFn: fn (ptr: @TypeOf(pointer), buf: []u8) void) Random {
const Ptr = @TypeOf(pointer);
assert(@typeInfo(Ptr) == .pointer); // Must be a pointer
assert(@typeInfo(Ptr).pointer.size == .One); // Must be a single-item pointer
assert(@typeInfo(Ptr).pointer.size == .one); // Must be a single-item pointer
assert(@typeInfo(@typeInfo(Ptr).pointer.child) == .@"struct"); // Must point to a struct
const gen = struct {
fn fill(ptr: *anyopaque, buf: []u8) void {
Expand Down
45 changes: 36 additions & 9 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -607,16 +607,24 @@ pub const Type = union(enum) {

/// The type of the sentinel is the element type of the pointer, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use pointer to `anyopaque`.
sentinel: ?*const anyopaque,
/// to refer to that type here, so we use `*const anyopaque`.
/// See also: `sentinel`
sentinel_ptr: ?*const anyopaque,

/// Loads the pointer type's sentinel value from `sentinel_ptr`.
/// Returns `null` if the pointer type has no sentinel.
pub inline fn sentinel(comptime ptr: Pointer) ?ptr.child {
const sp: *const ptr.child = @ptrCast(@alignCast(ptr.sentinel_ptr orelse return null));
return sp.*;
}

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const Size = enum(u2) {
One,
Many,
Slice,
C,
one,
many,
slice,
c,
};
};

Expand All @@ -628,8 +636,16 @@ pub const Type = union(enum) {

/// The type of the sentinel is the element type of the array, which is
/// the value of the `child` field in this struct. However there is no way
/// to refer to that type here, so we use pointer to `anyopaque`.
sentinel: ?*const anyopaque,
/// to refer to that type here, so we use `*const anyopaque`.
/// See also: `sentinel`.
sentinel_ptr: ?*const anyopaque,

/// Loads the array type's sentinel value from `sentinel_ptr`.
/// Returns `null` if the array type has no sentinel.
pub inline fn sentinel(comptime arr: Array) ?arr.child {
const sp: *const arr.child = @ptrCast(@alignCast(arr.sentinel_ptr orelse return null));
return sp.*;
}
};

/// This data structure is used by the Zig language code generation and
Expand All @@ -645,9 +661,20 @@ pub const Type = union(enum) {
pub const StructField = struct {
name: [:0]const u8,
type: type,
default_value: ?*const anyopaque,
/// The type of the default value is the type of this struct field, which
/// is the value of the `type` field in this struct. However there is no
/// way to refer to that type here, so we use `*const anyopaque`.
/// See also: `defaultValue`.
default_value_ptr: ?*const anyopaque,
is_comptime: bool,
alignment: comptime_int,

/// Loads the field's default value from `default_value_ptr`.
/// Returns `null` if the field has no default value.
pub inline fn defaultValue(comptime sf: StructField) ?sf.type {
const dp: *const sf.type = @ptrCast(@alignCast(sf.default_value_ptr orelse return null));
return dp.*;
}
};

/// This data structure is used by the Zig language code generation and
Expand Down
62 changes: 31 additions & 31 deletions lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2733,48 +2733,48 @@ pub const Sigaction = switch (native_os) {
=> if (builtin.target.isMusl())
linux.Sigaction
else if (builtin.target.ptrBitWidth() == 64) extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

flags: c_uint,
handler: extern union {
handler: ?handler_fn,
sigaction: ?sigaction_fn,
},
mask: sigset_t,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
} else extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

flags: c_uint,
handler: extern union {
handler: ?handler_fn,
sigaction: ?sigaction_fn,
},
mask: sigset_t,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
__resv: [1]c_int = .{0},
},
.s390x => if (builtin.abi == .gnu) extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

handler: extern union {
handler: ?handler_fn,
sigaction: ?sigaction_fn,
},
__glibc_reserved0: c_int = 0,
flags: c_uint,
restorer: ?*const fn () callconv(.C) void = null,
restorer: ?*const fn () callconv(.c) void = null,
mask: sigset_t,
} else linux.Sigaction,
else => linux.Sigaction,
},
.emscripten => emscripten.Sigaction,
.netbsd, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

handler: extern union {
handler: ?handler_fn,
Expand All @@ -2784,8 +2784,8 @@ pub const Sigaction = switch (native_os) {
flags: c_uint,
},
.dragonfly, .freebsd => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

/// signal handler
handler: extern union {
Expand All @@ -2798,8 +2798,8 @@ pub const Sigaction = switch (native_os) {
mask: sigset_t,
},
.solaris, .illumos => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

/// signal options
flags: c_uint,
Expand All @@ -2812,8 +2812,8 @@ pub const Sigaction = switch (native_os) {
mask: sigset_t,
},
.haiku => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

/// signal handler
handler: extern union {
Expand All @@ -2831,8 +2831,8 @@ pub const Sigaction = switch (native_os) {
userdata: *allowzero anyopaque = undefined,
},
.openbsd => extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.C) void;
pub const handler_fn = *align(1) const fn (i32) callconv(.c) void;
pub const sigaction_fn = *const fn (i32, *const siginfo_t, ?*anyopaque) callconv(.c) void;

/// signal handler
handler: extern union {
Expand Down Expand Up @@ -6410,7 +6410,7 @@ pub const EAI = switch (native_os) {
else => void,
};

pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.C) c_int;
pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize, data: ?*anyopaque) callconv(.c) c_int;

pub const Stat = switch (native_os) {
.linux => switch (native_arch) {
Expand Down Expand Up @@ -9396,7 +9396,7 @@ pub extern "c" fn futimens(fd: fd_t, times: *const [2]timespec) c_int;
pub extern "c" fn pthread_create(
noalias newthread: *pthread_t,
noalias attr: ?*const pthread_attr_t,
start_routine: *const fn (?*anyopaque) callconv(.C) ?*anyopaque,
start_routine: *const fn (?*anyopaque) callconv(.c) ?*anyopaque,
noalias arg: ?*anyopaque,
) E;
pub extern "c" fn pthread_attr_init(attr: *pthread_attr_t) E;
Expand All @@ -9408,13 +9408,13 @@ pub extern "c" fn pthread_self() pthread_t;
pub extern "c" fn pthread_join(thread: pthread_t, arg_return: ?*?*anyopaque) E;
pub extern "c" fn pthread_detach(thread: pthread_t) E;
pub extern "c" fn pthread_atfork(
prepare: ?*const fn () callconv(.C) void,
parent: ?*const fn () callconv(.C) void,
child: ?*const fn () callconv(.C) void,
prepare: ?*const fn () callconv(.c) void,
parent: ?*const fn () callconv(.c) void,
child: ?*const fn () callconv(.c) void,
) c_int;
pub extern "c" fn pthread_key_create(
key: *pthread_key_t,
destructor: ?*const fn (value: *anyopaque) callconv(.C) void,
destructor: ?*const fn (value: *anyopaque) callconv(.c) void,
) E;
pub extern "c" fn pthread_key_delete(key: pthread_key_t) E;
pub extern "c" fn pthread_getspecific(key: pthread_key_t) ?*anyopaque;
Expand Down Expand Up @@ -9530,12 +9530,12 @@ pub extern "c" fn pthread_cond_signal(cond: *pthread_cond_t) E;
pub extern "c" fn pthread_cond_broadcast(cond: *pthread_cond_t) E;
pub extern "c" fn pthread_cond_destroy(cond: *pthread_cond_t) E;

pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.C) E;
pub extern "c" fn pthread_rwlock_destroy(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_rdlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_wrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_tryrdlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_trywrlock(rwl: *pthread_rwlock_t) callconv(.c) E;
pub extern "c" fn pthread_rwlock_unlock(rwl: *pthread_rwlock_t) callconv(.c) E;

pub const pthread_t = *opaque {};
pub const FILE = opaque {};
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 @@ -379,7 +379,7 @@ pub const MACH_MSG_TYPE = enum(mach_msg_type_name_t) {
};

extern "c" var mach_task_self_: mach_port_t;
pub fn mach_task_self() callconv(.C) mach_port_t {
pub fn mach_task_self() callconv(.c) mach_port_t {
return mach_task_self_;
}

Expand Down Expand Up @@ -873,7 +873,7 @@ pub const DISPATCH_TIME_FOREVER = ~@as(dispatch_time_t, 0);
pub extern "c" fn dispatch_time(when: dispatch_time_t, delta: i64) dispatch_time_t;

const dispatch_once_t = usize;
const dispatch_function_t = fn (?*anyopaque) callconv(.C) void;
const dispatch_function_t = fn (?*anyopaque) callconv(.c) void;
pub extern fn dispatch_once_f(
predicate: *dispatch_once_t,
context: ?*anyopaque,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/c/dragonfly.zig
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub const E = enum(u16) {

pub const BADSIG = SIG.ERR;

pub const sig_t = *const fn (i32) callconv(.C) void;
pub const sig_t = *const fn (i32) callconv(.c) void;

pub const cmsghdr = extern struct {
len: socklen_t,
Expand Down
2 changes: 1 addition & 1 deletion lib/std/crypto/phc_encoding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn deserialize(comptime HashResult: type, str: []const u8) Error!HashResult
// with default values
var expected_fields: usize = 0;
inline for (comptime meta.fields(HashResult)) |p| {
if (@typeInfo(p.type) != .optional and p.default_value == null) {
if (@typeInfo(p.type) != .optional and p.default_value_ptr == null) {
expected_fields += 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/crypto/tlcsprng.zig
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn setupPthreadAtforkAndFill(buffer: []u8) void {
return initAndFill(buffer);
}

fn childAtForkHandler() callconv(.C) void {
fn childAtForkHandler() callconv(.c) void {
// The atfork handler is global, this function may be called after
// fork()-ing threads that never initialized the CSPRNG context.
if (wipe_mem.len == 0) return;
Expand Down
2 changes: 1 addition & 1 deletion lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ fn resetSegfaultHandler() void {
updateSegfaultHandler(&act);
}

fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.C) noreturn {
fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopaque) callconv(.c) noreturn {
// Reset to the default handler so that if a segfault happens in this handler it will crash
// the process. Also when this handler returns, the original instruction will be repeated
// and the resulting segfault will crash the process rather than continually dump stack traces.
Expand Down
2 changes: 1 addition & 1 deletion lib/std/enums.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn EnumFieldStruct(comptime E: type, comptime Data: type, comptime field_def
struct_field.* = .{
.name = enum_field.name ++ "",
.type = Data,
.default_value = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null,
.default_value_ptr = if (field_default) |d| @as(?*const anyopaque, @ptrCast(&d)) else null,
.is_comptime = false,
.alignment = if (@sizeOf(Data) > 0) @alignOf(Data) else 0,
};
Expand Down
Loading
Loading