Skip to content

Commit da96b5f

Browse files
committed
Update for Zig 0.14.0
Changes: - zig-xml updated to fix issue with passing buffers to std.unicode - std.builtin.Type field names updated to the new naming scheme
1 parent 03ee43c commit da96b5f

File tree

8 files changed

+75
-75
lines changed

8 files changed

+75
-75
lines changed

build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
},
1111
.dependencies = .{
1212
.xml = .{
13-
.url = "git+https://github.com/ianprime0509/zig-xml?ref=0.1.0#0747fa10b28ade9a8516bc5b122dcad997bd8fa7",
14-
.hash = "1220fcb9b8da8bcfdaa18c81678c6b5cf41d63a2bf9fde7551b4390279cc473a2520",
13+
.url = "git+https://github.com/sin-ack/zig-xml?ref=zig-0.14.0-fix#353d365b18b942223c5a34181e4d8570f6935366",
14+
.hash = "12204f358836a6294cf9176db61f3b66b756d669b758abfdf4a788f8247e41bd931c",
1515
},
1616
.libxml2 = .{
1717
.url = "git+https://github.com/ianprime0509/zig-libxml2?ref=main#6cebb963e0ad5789825eb2333a4d21fab8f35a92",

extensions/glib2.zig

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ pub inline fn new(comptime T: type, value: T) *T {
2020
/// Destroys a value created using `create`.
2121
pub fn destroy(ptr: anytype) void {
2222
const type_info = @typeInfo(@TypeOf(ptr));
23-
if (type_info != .Pointer or type_info.Pointer.size != .One) @compileError("must be a single-item pointer");
24-
glib.freeSized(@ptrCast(ptr), @sizeOf(type_info.Pointer.child));
23+
if (type_info != .pointer or type_info.pointer.size != .one) @compileError("must be a single-item pointer");
24+
glib.freeSized(@ptrCast(ptr), @sizeOf(type_info.pointer.child));
2525
}
2626

2727
/// Heap allocates a slice of `n` values of type `T` using `glib.mallocN`. `T`
@@ -36,8 +36,8 @@ pub fn alloc(comptime T: type, n: usize) []T {
3636
/// Frees a slice created using `alloc`.
3737
pub fn free(ptr: anytype) void {
3838
const type_info = @typeInfo(@TypeOf(ptr));
39-
if (type_info != .Pointer or type_info.Pointer.size != .Slice) @compileError("must be a slice");
40-
glib.freeSized(@ptrCast(ptr.ptr), @sizeOf(type_info.Pointer.child) * ptr.len);
39+
if (type_info != .pointer or type_info.pointer.size != .Slice) @compileError("must be a slice");
40+
glib.freeSized(@ptrCast(ptr.ptr), @sizeOf(type_info.pointer.child) * ptr.len);
4141
}
4242

4343
pub const Bytes = struct {
@@ -91,27 +91,27 @@ pub const Variant = struct {
9191
child.* = newFrom(item);
9292
}
9393
return glib.Variant.newArray(child_type, &children, children.len);
94-
} else if (type_info == .Pointer and type_info.Pointer.size == .Slice) {
95-
const child_type = glib.ext.VariantType.newFor(type_info.Pointer.child);
94+
} else if (type_info == .pointer and type_info.pointer.size == .Slice) {
95+
const child_type = glib.ext.VariantType.newFor(type_info.pointer.child);
9696
defer child_type.free();
9797
const children = alloc(*glib.Variant, contents.len);
9898
defer free(children);
9999
for (contents, children) |item, *child| {
100100
child.* = newFrom(item);
101101
}
102102
return glib.Variant.newArray(child_type, children.ptr, children.len);
103-
} else if (type_info == .Optional) {
104-
const child_type = glib.ext.VariantType.newFor(type_info.Optional.child);
103+
} else if (type_info == .optional) {
104+
const child_type = glib.ext.VariantType.newFor(type_info.optional.child);
105105
defer child_type.free();
106106
if (contents) |value| {
107107
const child = newFrom(value);
108108
return glib.Variant.newMaybe(child_type, child);
109109
} else {
110110
return glib.Variant.newMaybe(child_type, null);
111111
}
112-
} else if (type_info == .Struct and type_info.Struct.is_tuple) {
113-
var children: [type_info.Struct.fields.len]*glib.Variant = undefined;
114-
inline for (type_info.Struct.fields, &children) |field, *child| {
112+
} else if (type_info == .@"struct" and type_info.@"struct".is_tuple) {
113+
var children: [type_info.@"struct".fields.len]*glib.Variant = undefined;
114+
inline for (type_info.@"struct".fields, &children) |field, *child| {
115115
child.* = newFrom(@field(contents, field.name));
116116
}
117117
return glib.Variant.newTuple(&children, children.len);
@@ -153,14 +153,14 @@ pub const VariantType = struct {
153153
} else if (T == *glib.Variant) {
154154
return "v";
155155
} else if (type_info == .Array) {
156-
return "a" ++ stringFor(type_info.Array.child);
157-
} else if (type_info == .Pointer and type_info.Pointer.size == .Slice) {
158-
return "a" ++ stringFor(type_info.Pointer.child);
159-
} else if (type_info == .Optional) {
160-
return "m" ++ stringFor(type_info.Optional.child);
161-
} else if (type_info == .Struct and type_info.Struct.is_tuple) {
156+
return "a" ++ stringFor(type_info.array.child);
157+
} else if (type_info == .pointer and type_info.pointer.size == .Slice) {
158+
return "a" ++ stringFor(type_info.pointer.child);
159+
} else if (type_info == .optional) {
160+
return "m" ++ stringFor(type_info.optional.child);
161+
} else if (type_info == .@"struct" and type_info.@"struct".is_tuple) {
162162
comptime var str: [:0]const u8 = "(";
163-
inline for (type_info.Struct.fields) |field| {
163+
inline for (type_info.@"struct".fields) |field| {
164164
str = str ++ comptime stringFor(field.type);
165165
}
166166
return str ++ ")";
@@ -172,12 +172,12 @@ pub const VariantType = struct {
172172

173173
fn isCString(comptime T: type) bool {
174174
return switch (@typeInfo(T)) {
175-
.Pointer => |info| switch (info.size) {
176-
.One => switch (@typeInfo(info.child)) {
177-
.Array => |child| child.child == u8 and std.meta.sentinel(info.child) == @as(u8, 0),
175+
.pointer => |info| switch (info.size) {
176+
.one => switch (@typeInfo(info.child)) {
177+
.array => |child| child.child == u8 and std.meta.sentinel(info.child) == @as(u8, 0),
178178
else => false,
179179
},
180-
.Many, .Slice => info.child == u8 and std.meta.sentinel(T) == @as(u8, 0),
180+
.many, .slice => info.child == u8 and std.meta.sentinel(T) == @as(u8, 0),
181181
else => false,
182182
},
183183
else => false,

extensions/gobject2.zig

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -173,32 +173,32 @@ pub fn defineClass(
173173
comptime options: DefineClassOptions(Instance),
174174
) fn () callconv(.C) gobject.Type {
175175
const instance_info = @typeInfo(Instance);
176-
if (instance_info != .Struct or instance_info.Struct.layout != .@"extern") {
176+
if (instance_info != .@"struct" or instance_info.@"struct".layout != .@"extern") {
177177
@compileError("an instance type must be an extern struct");
178178
}
179179

180180
if (!@hasDecl(Instance, "Parent")) {
181181
@compileError("a class type must have a declaration named Parent pointing to the parent type");
182182
}
183183
const parent_info = @typeInfo(Instance.Parent);
184-
if (parent_info != .Struct or parent_info.Struct.layout != .@"extern" or !@hasDecl(Instance.Parent, "getGObjectType")) {
184+
if (parent_info != .@"struct" or parent_info.@"struct".layout != .@"extern" or !@hasDecl(Instance.Parent, "getGObjectType")) {
185185
@compileError("the defined parent type " ++ @typeName(Instance.Parent) ++ " does not appear to be a GObject class type");
186186
}
187-
if (instance_info.Struct.fields.len == 0 or instance_info.Struct.fields[0].type != Instance.Parent) {
187+
if (instance_info.@"struct".fields.len == 0 or instance_info.@"struct".fields[0].type != Instance.Parent) {
188188
@compileError("the first field of the instance struct must have type " ++ @typeName(Instance.Parent));
189189
}
190190

191191
if (!@hasDecl(Instance, "Class")) {
192192
@compileError("a class type must have a member named Class pointing to the class record");
193193
}
194194
const class_info = @typeInfo(Instance.Class);
195-
if (class_info != .Struct or class_info.Struct.layout != .@"extern") {
195+
if (class_info != .@"struct" or class_info.@"struct".layout != .@"extern") {
196196
@compileError("a class type must be an extern struct");
197197
}
198198
if (!@hasDecl(Instance.Class, "Instance") or Instance.Class.Instance != Instance) {
199199
@compileError("a class type must have a declaration named Instance pointing to the instance type");
200200
}
201-
if (class_info.Struct.fields.len == 0 or class_info.Struct.fields[0].type != Instance.Parent.Class) {
201+
if (class_info.@"struct".fields.len == 0 or class_info.@"struct".fields[0].type != Instance.Parent.Class) {
202202
@compileError("the first field of the class struct must have type " ++ @typeName(Instance.Parent.Class));
203203
}
204204

@@ -338,16 +338,16 @@ pub fn defineEnum(
338338
comptime options: DefineEnumOptions,
339339
) fn () callconv(.C) gobject.Type {
340340
const enum_info = @typeInfo(Enum);
341-
if (enum_info != .Enum or enum_info.Enum.tag_type != c_int) {
341+
if (enum_info != .@"enum" or enum_info.@"enum".tag_type != c_int) {
342342
@compileError("an enum type must have a tag type of c_int");
343343
}
344-
if (!enum_info.Enum.is_exhaustive) {
344+
if (!enum_info.@"enum".is_exhaustive) {
345345
@compileError("an enum type must be exhaustive");
346346
}
347347

348-
const n_values = enum_info.Enum.fields.len;
349-
var enum_values: [n_values + 1]gobject.EnumValue = undefined;
350-
for (enum_info.Enum.fields, enum_values[0..n_values]) |field, *value| {
348+
const n_values = enum_info.@"enum".fields.len;
349+
var enum_values: [n_values + 1]gobject.enum_value = undefined;
350+
for (enum_info.@"enum".fields, enum_values[0..n_values]) |field, *value| {
351351
value.* = .{
352352
.value = field.value,
353353
.value_name = field.name,
@@ -394,12 +394,12 @@ pub fn defineFlags(
394394
comptime options: DefineFlagsOptions,
395395
) fn () callconv(.C) gobject.Type {
396396
const flags_info = @typeInfo(Flags);
397-
if (flags_info != .Struct or flags_info.Struct.layout != .@"packed" or flags_info.Struct.backing_integer != c_uint) {
397+
if (flags_info != .@"struct" or flags_info.@"struct".layout != .@"packed" or flags_info.@"struct".backing_integer != c_uint) {
398398
@compileError("a flags type must have a backing integer type of c_uint");
399399
}
400400

401401
comptime var n_values = 0;
402-
for (flags_info.Struct.fields) |field| {
402+
for (flags_info.@"struct".fields) |field| {
403403
if (!std.mem.startsWith(u8, field.name, "_")) {
404404
if (@bitSizeOf(field.type) != 1) {
405405
@compileError("non-padding flags field " ++ field.name ++ " must be 1 bit");
@@ -409,7 +409,7 @@ pub fn defineFlags(
409409
}
410410
comptime var flags_values: [n_values + 1]gobject.FlagsValue = undefined;
411411
var current_value = 0;
412-
for (flags_info.Struct.fields) |field| {
412+
for (flags_info.@"struct".fields) |field| {
413413
if (!std.mem.startsWith(u8, field.name, "_")) {
414414
flags_values[current_value] = .{
415415
.value = 1 << @bitOffsetOf(Flags, field.name),
@@ -458,7 +458,7 @@ pub fn Accessor(comptime Owner: type, comptime Data: type) type {
458458
}
459459

460460
fn FieldType(comptime T: type, comptime name: []const u8) type {
461-
return for (@typeInfo(T).Struct.fields) |field| {
461+
return for (@typeInfo(T).@"struct".fields) |field| {
462462
if (std.mem.eql(u8, field.name, name)) break field.type;
463463
} else @compileError("no field named " ++ name ++ " in " ++ @typeName(T));
464464
}
@@ -698,15 +698,15 @@ pub fn defineProperty(
698698
);
699699
} else if (std.meta.hasFn(Data, "getGObjectType")) {
700700
return switch (@typeInfo(Data)) {
701-
.Enum => gobject.paramSpecEnum(
701+
.@"enum" => gobject.paramSpecEnum(
702702
name,
703703
options.nick orelse null,
704704
options.blurb orelse null,
705705
Data.getGObjectType(),
706706
@intFromEnum(options.default),
707707
flags,
708708
),
709-
.Struct => gobject.paramSpecFlags(
709+
.@"struct" => gobject.paramSpecFlags(
710710
name,
711711
options.nick orelse null,
712712
options.blurb orelse null,
@@ -752,7 +752,7 @@ pub fn defineProperty(
752752
/// The properties passed in `properties` should be the structs returned by
753753
/// `defineProperty`.
754754
pub fn registerProperties(class: anytype, properties: []const type) void {
755-
const Instance = @typeInfo(@TypeOf(class)).Pointer.child.Instance;
755+
const Instance = @typeInfo(@TypeOf(class)).pointer.child.Instance;
756756
gobject.Object.virtual_methods.get_property.implement(class, struct {
757757
fn getProperty(object: *Instance, id: c_uint, value: *gobject.Value, _: *gobject.ParamSpec) callconv(.C) void {
758758
inline for (properties, 1..) |property, i| {
@@ -810,10 +810,10 @@ pub fn defineSignal(
810810
comptime param_types: []const type,
811811
comptime ReturnType: type,
812812
) type {
813-
const EmitParams = @Type(.{ .Struct = .{
813+
const EmitParams = @Type(.{ .@"struct" = .{
814814
.layout = .auto,
815815
.fields = fields: {
816-
var fields: [param_types.len]std.builtin.Type.StructField = undefined;
816+
var fields: [param_types.len]std.builtin.Type.struct_field = undefined;
817817
for (param_types, &fields, 0..) |ParamType, *field, i| {
818818
field.* = .{
819819
.name = std.fmt.comptimePrint("{}", .{i}),
@@ -878,7 +878,7 @@ pub fn defineSignal(
878878
pub fn connect(
879879
target: anytype,
880880
comptime T: type,
881-
callback: SignalHandler(@typeInfo(@TypeOf(target)).Pointer.child, param_types, T, ReturnType),
881+
callback: SignalHandler(@typeInfo(@TypeOf(target)).pointer.child, param_types, T, ReturnType),
882882
data: T,
883883
options: struct {
884884
after: bool = false,
@@ -917,10 +917,10 @@ pub const impl_helpers = struct {
917917
/// guaranteed.
918918
pub inline fn as(comptime T: type, self: anytype) *T {
919919
const self_info = @typeInfo(@TypeOf(self));
920-
if (self_info != .Pointer or self_info.Pointer.size != .One) {
920+
if (self_info != .pointer or self_info.pointer.size != .One) {
921921
@compileError("cannot cast a non-pointer type");
922922
}
923-
const Self = self_info.Pointer.child;
923+
const Self = self_info.pointer.child;
924924

925925
if (isAssignableFrom(T, Self)) {
926926
return @ptrCast(@alignCast(self));
@@ -979,7 +979,7 @@ pub fn isA(self: anytype, comptime T: type) bool {
979979

980980
/// Creates a new instance of an object type with the given properties.
981981
pub fn newInstance(comptime T: type, properties: anytype) *T {
982-
const typeInfo = @typeInfo(@TypeOf(properties)).Struct;
982+
const typeInfo = @typeInfo(@TypeOf(properties)).@"struct";
983983
const n_props = typeInfo.fields.len;
984984
var names: [n_props][*:0]const u8 = undefined;
985985
var values: [n_props]gobject.Value = undefined;
@@ -1085,10 +1085,10 @@ pub const Value = struct {
10851085
} else if (T == f64) {
10861086
return value.getDouble();
10871087
} else if (isCString(T)) {
1088-
if (@typeInfo(T) != .Optional) {
1088+
if (@typeInfo(T) != .optional) {
10891089
@compileError("cannot guarantee value is non-null");
10901090
}
1091-
const Pointer = @typeInfo(@typeInfo(T).Optional.child).Pointer;
1091+
const Pointer = @typeInfo(@typeInfo(T).optional.child).pointer;
10921092
if (!Pointer.is_const) {
10931093
@compileError("get does not take ownership; can only return const strings");
10941094
}
@@ -1099,12 +1099,12 @@ pub const Value = struct {
10991099
};
11001100
} else if (std.meta.hasFn(T, "getGObjectType")) {
11011101
return switch (@typeInfo(T)) {
1102-
.Enum => @enumFromInt(value.getEnum()),
1103-
.Struct => @bitCast(value.getFlags()),
1102+
.@"enum" => @enumFromInt(value.getEnum()),
1103+
.@"struct" => @bitCast(value.getFlags()),
11041104
else => @compileError("cannot extract " ++ @typeName(T) ++ " from Value"),
11051105
};
11061106
} else if (singlePointerChild(T)) |Child| {
1107-
if (@typeInfo(T) != .Optional) {
1107+
if (@typeInfo(T) != .optional) {
11081108
@compileError("cannot guarantee value is non-null");
11091109
}
11101110
if (Child == gobject.ParamSpec) {
@@ -1156,14 +1156,14 @@ pub const Value = struct {
11561156
} else if (comptime isCString(T)) {
11571157
// orelse null as temporary workaround for https://github.com/ziglang/zig/issues/12523
11581158
switch (@typeInfo(T)) {
1159-
.Pointer => value.setString(contents),
1160-
.Optional => value.setString(contents orelse null),
1159+
.pointer => value.setString(contents),
1160+
.optional => value.setString(contents orelse null),
11611161
else => unreachable,
11621162
}
11631163
} else if (std.meta.hasFn(T, "getGObjectType")) {
11641164
switch (@typeInfo(T)) {
1165-
.Enum => value.setEnum(@intFromEnum(contents)),
1166-
.Struct => value.setFlags(@bitCast(contents)),
1165+
.@"enum" => value.setEnum(@intFromEnum(contents)),
1166+
.@"struct" => value.setFlags(@bitCast(contents)),
11671167
else => @compileError("cannot construct Value from " ++ @typeName(T)),
11681168
}
11691169
} else if (singlePointerChild(T)) |Child| {
@@ -1192,18 +1192,18 @@ inline fn isObject(comptime T: type) bool {
11921192

11931193
inline fn isCString(comptime T: type) bool {
11941194
return switch (@typeInfo(T)) {
1195-
.Pointer => |pointer| switch (pointer.size) {
1195+
.pointer => |pointer| switch (pointer.size) {
11961196
.One => switch (@typeInfo(pointer.child)) {
1197-
.Array => |child| child.child == u8 and std.meta.sentinel(pointer.child) == @as(u8, 0),
1197+
.array => |child| child.child == u8 and std.meta.sentinel(pointer.child) == @as(u8, 0),
11981198
else => false,
11991199
},
12001200
.Many, .Slice => pointer.child == u8 and std.meta.sentinel(T) == @as(u8, 0),
12011201
.C => pointer.child == u8,
12021202
},
1203-
.Optional => |optional| switch (@typeInfo(optional.child)) {
1204-
.Pointer => |pointer| switch (pointer.size) {
1203+
.optional => |optional| switch (@typeInfo(optional.child)) {
1204+
.pointer => |pointer| switch (pointer.size) {
12051205
.One => switch (@typeInfo(pointer.child)) {
1206-
.Array => |child| child.child == u8 and std.meta.sentinel(pointer.child) == @as(u8, 0),
1206+
.array => |child| child.child == u8 and std.meta.sentinel(pointer.child) == @as(u8, 0),
12071207
else => false,
12081208
},
12091209
.Many, .Slice => pointer.child == u8 and std.meta.sentinel(optional.child) == @as(u8, 0),
@@ -1217,13 +1217,13 @@ inline fn isCString(comptime T: type) bool {
12171217

12181218
inline fn singlePointerChild(comptime T: type) ?type {
12191219
return switch (@typeInfo(T)) {
1220-
.Pointer => |pointer| switch (pointer.size) {
1220+
.pointer => |pointer| switch (pointer.size) {
12211221
.One, .C => pointer.child,
12221222
else => null,
12231223
},
1224-
.Optional => |optional| switch (@typeInfo(optional.child)) {
1225-
.Pointer => |pointer| switch (pointer.size) {
1226-
.One => pointer.child,
1224+
.optional => |optional| switch (@typeInfo(optional.child)) {
1225+
.pointer => |pointer| switch (pointer.size) {
1226+
.one => pointer.child,
12271227
else => null,
12281228
},
12291229
else => null,

0 commit comments

Comments
 (0)