mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
config: C API read allows any packed struct that fits in c int
This commit is contained in:
@ -39,17 +39,24 @@ pub fn get(config: *const Config, k: Key, ptr_raw: *anyopaque) bool {
|
|||||||
ptr.* = @floatCast(value);
|
ptr.* = @floatCast(value);
|
||||||
},
|
},
|
||||||
|
|
||||||
Color => {
|
|
||||||
const ptr: *c_uint = @ptrCast(@alignCast(ptr_raw));
|
|
||||||
ptr.* = @as(c_uint, @as(u24, @bitCast(value)));
|
|
||||||
},
|
|
||||||
|
|
||||||
else => |T| switch (@typeInfo(T)) {
|
else => |T| switch (@typeInfo(T)) {
|
||||||
.Enum => {
|
.Enum => {
|
||||||
const ptr: *[*:0]const u8 = @ptrCast(@alignCast(ptr_raw));
|
const ptr: *[*:0]const u8 = @ptrCast(@alignCast(ptr_raw));
|
||||||
ptr.* = @tagName(value);
|
ptr.* = @tagName(value);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
.Struct => |info| {
|
||||||
|
// Packed structs that are less than or equal to the
|
||||||
|
// size of a C int can be passed directly as their
|
||||||
|
// bit representation.
|
||||||
|
if (info.layout != .Packed) return false;
|
||||||
|
const Backing = info.backing_integer orelse return false;
|
||||||
|
if (@bitSizeOf(Backing) > @bitSizeOf(c_uint)) return false;
|
||||||
|
|
||||||
|
const ptr: *c_uint = @ptrCast(@alignCast(ptr_raw));
|
||||||
|
ptr.* = @intCast(@as(Backing, @bitCast(value)));
|
||||||
|
},
|
||||||
|
|
||||||
else => return false,
|
else => return false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user