pkg/macos: do not use bitCast through a function

workaround Zig issue: https://github.com/ziglang/zig/issues/16290
This commit is contained in:
Mitchell Hashimoto
2023-07-01 13:38:10 -07:00
parent 1dd6e6f29d
commit 0a718ec3eb
10 changed files with 29 additions and 37 deletions

View File

@ -43,7 +43,7 @@ pub const MutableAttributedString = opaque {
) void { ) void {
c.CFAttributedStringReplaceString( c.CFAttributedStringReplaceString(
@ptrCast(self), @ptrCast(self),
range.cval(), @bitCast(range),
@ptrCast(replacement), @ptrCast(replacement),
); );
} }
@ -64,11 +64,15 @@ pub const MutableAttributedString = opaque {
c.CFAttributedStringSetAttribute( c.CFAttributedStringSetAttribute(
@ptrCast(self), @ptrCast(self),
range.cval(), @bitCast(range),
@ptrCast(key_arg), @ptrCast(key_arg),
value, value,
); );
} }
pub fn getLength(self: *MutableAttributedString) usize {
return @intCast(c.CFAttributedStringGetLength(@ptrCast(self)));
}
}; };
test "mutable attributed string" { test "mutable attributed string" {

View File

@ -1,3 +1,5 @@
const std = @import("std");
const assert = std.debug.assert;
const c = @import("c.zig"); const c = @import("c.zig");
pub const ComparisonResult = enum(c_int) { pub const ComparisonResult = enum(c_int) {
@ -13,8 +15,4 @@ pub const Range = extern struct {
pub fn init(loc: usize, len: usize) Range { pub fn init(loc: usize, len: usize) Range {
return @bitCast(c.CFRangeMake(@intCast(loc), @intCast(len))); return @bitCast(c.CFRangeMake(@intCast(loc), @intCast(len)));
} }
pub fn cval(self: Range) c.CFRange {
return @bitCast(self);
}
}; };

View File

@ -19,7 +19,7 @@ pub const CharacterSet = opaque {
) Allocator.Error!*CharacterSet { ) Allocator.Error!*CharacterSet {
return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInRange( return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInRange(
null, null,
range.cval(), @bitCast(range),
)))) orelse Allocator.Error.OutOfMemory; )))) orelse Allocator.Error.OutOfMemory;
} }

View File

@ -13,8 +13,4 @@ pub const AffineTransform = extern struct {
pub fn identity() AffineTransform { pub fn identity() AffineTransform {
return @bitCast(c.CGAffineTransformIdentity); return @bitCast(c.CGAffineTransformIdentity);
} }
pub fn cval(self: AffineTransform) c.struct_CGAffineTransform {
return @bitCast(self);
}
}; };

View File

@ -121,7 +121,7 @@ pub fn Context(comptime T: type) type {
pub fn setTextMatrix(self: *T, matrix: graphics.AffineTransform) void { pub fn setTextMatrix(self: *T, matrix: graphics.AffineTransform) void {
c.CGContextSetTextMatrix( c.CGContextSetTextMatrix(
@ptrCast(self), @ptrCast(self),
matrix.cval(), @bitCast(matrix),
); );
} }

View File

@ -1,12 +1,10 @@
const std = @import("std");
const assert = std.debug.assert;
const c = @import("c.zig"); const c = @import("c.zig");
pub const Point = extern struct { pub const Point = extern struct {
x: c.CGFloat, x: c.CGFloat,
y: c.CGFloat, y: c.CGFloat,
pub fn cval(self: Point) c.struct_CGPoint {
return @bitCast(self);
}
}; };
pub const Rect = extern struct { pub const Rect = extern struct {
@ -17,20 +15,20 @@ pub const Rect = extern struct {
return @bitCast(c.CGRectMake(x, y, width, height)); return @bitCast(c.CGRectMake(x, y, width, height));
} }
pub fn cval(self: Rect) c.struct_CGRect { pub fn isNull(self: Rect) bool {
return @bitCast(self); return c.CGRectIsNull(@bitCast(self));
} }
pub fn isNull(self: Rect) bool { pub fn getHeight(self: Rect) c.CGFloat {
return c.CGRectIsNull(self.cval()); return c.CGRectGetHeight(@bitCast(self));
}
pub fn getWidth(self: Rect) c.CGFloat {
return c.CGRectGetWidth(@bitCast(self));
} }
}; };
pub const Size = extern struct { pub const Size = extern struct {
width: c.CGFloat, width: c.CGFloat,
height: c.CGFloat, height: c.CGFloat,
pub fn cval(self: Size) c.struct_CGSize {
return @bitCast(self);
}
}; };

View File

@ -13,7 +13,7 @@ pub const Path = opaque {
return @as( return @as(
?*Path, ?*Path,
@ptrFromInt(@intFromPtr(c.CGPathCreateWithRect( @ptrFromInt(@intFromPtr(c.CGPathCreateWithRect(
rect.cval(), @bitCast(rect),
@ptrCast(transform), @ptrCast(transform),
))), ))),
) orelse Allocator.Error.OutOfMemory; ) orelse Allocator.Error.OutOfMemory;
@ -44,9 +44,13 @@ pub const MutablePath = opaque {
c.CGPathAddRect( c.CGPathAddRect(
@ptrCast(self), @ptrCast(self),
@ptrCast(transform), @ptrCast(transform),
rect.cval(), @bitCast(rect),
); );
} }
pub fn getBoundingBox(self: *MutablePath) graphics.Rect {
return @bitCast(c.CGPathGetBoundingBox(@ptrCast(self)));
}
}; };
test "mutable path" { test "mutable path" {

View File

@ -159,7 +159,7 @@ pub const FontTraitKey = enum {
} }
}; };
pub const FontSymbolicTraits = packed struct { pub const FontSymbolicTraits = packed struct(u32) {
italic: bool = false, italic: bool = false,
bold: bool = false, bold: bool = false,
_unused1: u3 = 0, _unused1: u3 = 0,
@ -179,10 +179,6 @@ pub const FontSymbolicTraits = packed struct {
return @as(FontSymbolicTraits, @bitCast(raw)); return @as(FontSymbolicTraits, @bitCast(raw));
} }
pub fn cval(self: FontSymbolicTraits) c.CTFontSymbolicTraits {
return @as(c.CTFontSymbolicTraits, @bitCast(self));
}
test { test {
try std.testing.expectEqual( try std.testing.expectEqual(
@bitSizeOf(c.CTFontSymbolicTraits), @bitSizeOf(c.CTFontSymbolicTraits),

View File

@ -32,7 +32,7 @@ pub const Line = opaque {
) graphics.Rect { ) graphics.Rect {
return @bitCast(c.CTLineGetBoundsWithOptions( return @bitCast(c.CTLineGetBoundsWithOptions(
@ptrCast(self), @ptrCast(self),
opts.cval(), @bitCast(opts),
)); ));
} }
@ -60,10 +60,6 @@ pub const LineBoundsOptions = packed struct {
language_extents: bool = false, language_extents: bool = false,
_padding: u58 = 0, _padding: u58 = 0,
pub fn cval(self: LineBoundsOptions) c.CTLineBoundsOptions {
return @bitCast(self);
}
test { test {
try std.testing.expectEqual( try std.testing.expectEqual(
@bitSizeOf(c.CTLineBoundsOptions), @bitSizeOf(c.CTLineBoundsOptions),

View File

@ -126,7 +126,7 @@ pub const Descriptor = struct {
.bold = self.bold, .bold = self.bold,
.italic = self.italic, .italic = self.italic,
}; };
const traits_cval = traits.cval(); const traits_cval: u32 = @bitCast(traits);
if (traits_cval > 0) { if (traits_cval > 0) {
// Setting traits is a pain. We have to create a nested dictionary // Setting traits is a pain. We have to create a nested dictionary
// of the symbolic traits value, and set that in our attributes. // of the symbolic traits value, and set that in our attributes.