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

View File

@ -1,3 +1,5 @@
const std = @import("std");
const assert = std.debug.assert;
const c = @import("c.zig");
pub const ComparisonResult = enum(c_int) {
@ -13,8 +15,4 @@ pub const Range = extern struct {
pub fn init(loc: usize, len: usize) Range {
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 {
return @as(?*CharacterSet, @ptrFromInt(@intFromPtr(c.CFCharacterSetCreateWithCharactersInRange(
null,
range.cval(),
@bitCast(range),
)))) orelse Allocator.Error.OutOfMemory;
}

View File

@ -13,8 +13,4 @@ pub const AffineTransform = extern struct {
pub fn identity() AffineTransform {
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 {
c.CGContextSetTextMatrix(
@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");
pub const Point = extern struct {
x: c.CGFloat,
y: c.CGFloat,
pub fn cval(self: Point) c.struct_CGPoint {
return @bitCast(self);
}
};
pub const Rect = extern struct {
@ -17,20 +15,20 @@ pub const Rect = extern struct {
return @bitCast(c.CGRectMake(x, y, width, height));
}
pub fn cval(self: Rect) c.struct_CGRect {
return @bitCast(self);
pub fn isNull(self: Rect) bool {
return c.CGRectIsNull(@bitCast(self));
}
pub fn isNull(self: Rect) bool {
return c.CGRectIsNull(self.cval());
pub fn getHeight(self: Rect) c.CGFloat {
return c.CGRectGetHeight(@bitCast(self));
}
pub fn getWidth(self: Rect) c.CGFloat {
return c.CGRectGetWidth(@bitCast(self));
}
};
pub const Size = extern struct {
width: 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(
?*Path,
@ptrFromInt(@intFromPtr(c.CGPathCreateWithRect(
rect.cval(),
@bitCast(rect),
@ptrCast(transform),
))),
) orelse Allocator.Error.OutOfMemory;
@ -44,9 +44,13 @@ pub const MutablePath = opaque {
c.CGPathAddRect(
@ptrCast(self),
@ptrCast(transform),
rect.cval(),
@bitCast(rect),
);
}
pub fn getBoundingBox(self: *MutablePath) graphics.Rect {
return @bitCast(c.CGPathGetBoundingBox(@ptrCast(self)));
}
};
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,
bold: bool = false,
_unused1: u3 = 0,
@ -179,10 +179,6 @@ pub const FontSymbolicTraits = packed struct {
return @as(FontSymbolicTraits, @bitCast(raw));
}
pub fn cval(self: FontSymbolicTraits) c.CTFontSymbolicTraits {
return @as(c.CTFontSymbolicTraits, @bitCast(self));
}
test {
try std.testing.expectEqual(
@bitSizeOf(c.CTFontSymbolicTraits),

View File

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

View File

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