pkg/macos: use new @ptrcast for os.log

This commit is contained in:
Mitchell Hashimoto
2025-07-08 10:02:06 -07:00
parent b8f5cf9d52
commit d30771ecff
3 changed files with 10 additions and 4 deletions

View File

@ -8,10 +8,10 @@ pub const Log = opaque {
subsystem: [:0]const u8, subsystem: [:0]const u8,
category: [:0]const u8, category: [:0]const u8,
) *Log { ) *Log {
return @as(?*Log, @ptrFromInt(@intFromPtr(c.os_log_create( return @ptrCast(c.os_log_create(
subsystem.ptr, subsystem.ptr,
category.ptr, category.ptr,
)))).?; ).?);
} }
pub fn release(self: *Log) void { pub fn release(self: *Log) void {
@ -32,7 +32,11 @@ pub const Log = opaque {
comptime format: []const u8, comptime format: []const u8,
args: anytype, args: anytype,
) void { ) void {
const str = nosuspend std.fmt.allocPrintZ(alloc, format, args) catch return; const str = nosuspend std.fmt.allocPrintZ(
alloc,
format,
args,
) catch return;
defer alloc.free(str); defer alloc.free(str);
zig_os_log_with_type(self, typ, str.ptr); zig_os_log_with_type(self, typ, str.ptr);
} }

View File

@ -50,7 +50,7 @@ pub fn run(
build_config.bundle_id, build_config.bundle_id,
macos.os.signpost.Category.points_of_interest, macos.os.signpost.Category.points_of_interest,
); );
const id = macos.os.signpost.Id.generate(log); const id = macos.os.signpost.Id.forPointer(log, self.ptr);
macos.os.signpost.intervalBegin(log, id, signpost_name); macos.os.signpost.intervalBegin(log, id, signpost_name);
break :macos .{ .log = log, .id = id }; break :macos .{ .log = log, .id = id };
} else {}; } else {};

View File

@ -1,3 +1,5 @@
const std = @import("std"); const std = @import("std");
const builtin = @import("builtin");
const benchmark = @import("benchmark/main.zig"); const benchmark = @import("benchmark/main.zig");
pub const main = benchmark.cli.main; pub const main = benchmark.cli.main;