Skip to content

Commit 21c9dde

Browse files
karlseguinkrichprollsch
authored andcommittedMar 19, 2025
Zig 0.14 compatibility
1 parent 17d3d62 commit 21c9dde

26 files changed

+78
-197
lines changed
 

‎.github/actions/install/action.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inputs:
55
zig:
66
description: 'Zig version to install'
77
required: false
8-
default: '0.13.0'
8+
default: '0.14.0'
99
arch:
1010
description: 'CPU arch used to select the v8 lib'
1111
required: false

‎.github/workflows/zig-fmt.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: zig-fmt
22

33
env:
4-
ZIG_VERSION: 0.13.0
4+
ZIG_VERSION: 0.14.0
55

66
on:
77
pull_request:

‎.gitmodules

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[submodule "vendor/zig-js-runtime"]
22
path = vendor/zig-js-runtime
33
url = https://github.com/lightpanda-io/zig-js-runtime.git/
4+
branch = zig-0.14
45
[submodule "vendor/netsurf/libwapcaplet"]
56
path = vendor/netsurf/libwapcaplet
67
url = https://github.com/lightpanda-io/libwapcaplet.git/
@@ -28,3 +29,4 @@
2829
[submodule "vendor/zig-async-io"]
2930
path = vendor/zig-async-io
3031
url = https://github.com/lightpanda-io/zig-async-io.git/
32+
branch = zig-0.14

‎Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM ubuntu:24.04
22

33
ARG MINISIG=0.12
4-
ARG ZIG=0.13.0
4+
ARG ZIG=0.14.0
55
ARG ZIG_MINISIG=RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U
66
ARG ARCH=x86_64
77
ARG V8=11.1.134

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ You can also follow the progress of our Javascript support in our dedicated [zig
140140

141141
### Prerequisites
142142

143-
Lightpanda is written with [Zig](https://ziglang.org/) `0.13.0`. You have to
143+
Lightpanda is written with [Zig](https://ziglang.org/) `0.14.0`. You have to
144144
install it with the right version in order to build the project.
145145

146146
Lightpanda also depends on

‎build.zig

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub fn build(b: *std.Build) !void {
108108
// compile
109109
const tests = b.addTest(.{
110110
.root_source_file = b.path("src/main_tests.zig"),
111-
.test_runner = b.path("src/main_tests.zig"),
111+
.test_runner = .{ .path = b.path("src/main_tests.zig"), .mode = .simple },
112112
.target = target,
113113
.optimize = mode,
114114
});
@@ -134,7 +134,7 @@ pub fn build(b: *std.Build) !void {
134134
// compile
135135
const unit_tests = b.addTest(.{
136136
.root_source_file = b.path("src/unit_tests.zig"),
137-
.test_runner = b.path("src/unit_tests.zig"),
137+
.test_runner = .{ .path = b.path("src/unit_tests.zig"), .mode = .simple },
138138
.target = target,
139139
.optimize = mode,
140140
});
@@ -195,7 +195,7 @@ fn common(
195195
step.root_module.addImport("asyncio", asyncio);
196196

197197
const tlsmod = b.addModule("tls", .{
198-
.root_source_file = b.path("vendor/tls.zig/src/main.zig"),
198+
.root_source_file = b.path("vendor/tls.zig/src/root.zig"),
199199
});
200200
step.root_module.addImport("tls", tlsmod);
201201
}

‎src/browser/browser.zig

+13-19
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,16 @@ pub const Session = struct {
156156

157157
const ContextT = @TypeOf(ctx);
158158
const InspectorContainer = switch (@typeInfo(ContextT)) {
159-
.Struct => ContextT,
160-
.Pointer => |ptr| ptr.child,
161-
.Void => NoopInspector,
159+
.@"struct" => ContextT,
160+
.pointer => |ptr| ptr.child,
161+
.void => NoopInspector,
162162
else => @compileError("invalid context type"),
163163
};
164164

165165
// const ctx_opaque = @as(*anyopaque, @ptrCast(ctx));
166166
self.inspector = try jsruntime.Inspector.init(
167167
arena,
168-
self.env, // TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
168+
&self.env,
169169
if (@TypeOf(ctx) == void) @constCast(@ptrCast(&{})) else ctx,
170170
InspectorContainer.onInspectorResponse,
171171
InspectorContainer.onInspectorEvent,
@@ -231,7 +231,7 @@ pub const Session = struct {
231231

232232
// load polyfills
233233
// TODO: change to 'env' when https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
234-
try polyfill.load(self.arena.allocator(), self.env);
234+
try polyfill.load(self.arena.allocator(), &self.env);
235235

236236
// inspector
237237
self.contextCreated(page, aux_data);
@@ -264,7 +264,7 @@ pub const Session = struct {
264264

265265
fn contextCreated(self: *Session, page: *Page, aux_data: ?[]const u8) void {
266266
log.debug("inspector context created", .{});
267-
self.inspector.contextCreated(self.env, "", page.origin orelse "://", aux_data);
267+
self.inspector.contextCreated(&self.env, "", page.origin orelse "://", aux_data);
268268
}
269269
};
270270

@@ -316,15 +316,15 @@ pub const Page = struct {
316316
pub fn wait(self: *Page) !void {
317317
// try catch
318318
var try_catch: jsruntime.TryCatch = undefined;
319-
try_catch.init(self.session.env);
319+
try_catch.init(&self.session.env);
320320
defer try_catch.deinit();
321321

322322
self.session.env.wait() catch |err| {
323323
// the js env could not be started if the document wasn't an HTML.
324324
if (err == error.EnvNotStarted) return;
325325

326326
const arena = self.arena;
327-
if (try try_catch.err(arena, self.session.env)) |msg| {
327+
if (try try_catch.err(arena, &self.session.env)) |msg| {
328328
defer arena.free(msg);
329329
log.info("wait error: {s}", .{msg});
330330
return;
@@ -591,9 +591,7 @@ pub const Page = struct {
591591
// TODO handle charset attribute
592592
const opt_text = try parser.nodeTextContent(parser.elementToNode(s.element));
593593
if (opt_text) |text| {
594-
// TODO: change to &self.session.env when
595-
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
596-
try s.eval(self.arena, self.session.env, text);
594+
try s.eval(self.arena, &self.session.env, text);
597595
return;
598596
}
599597

@@ -656,11 +654,8 @@ pub const Page = struct {
656654
// received.
657655
fn fetchScript(self: *const Page, s: *const Script) !void {
658656
const arena = self.arena;
659-
660657
const body = try self.fetchData(arena, s.src, null);
661-
// TODO: change to &self.session.env when
662-
// https://github.com/lightpanda-io/zig-js-runtime/pull/285 lands
663-
try s.eval(arena, self.session.env, body);
658+
try s.eval(arena, &self.session.env, body);
664659
}
665660

666661
const Script = struct {
@@ -683,9 +678,8 @@ pub const Page = struct {
683678

684679
return .{
685680
.element = e,
686-
.kind = kind(try parser.elementGetAttribute(e, "type")),
681+
.kind = parseKind(try parser.elementGetAttribute(e, "type")),
687682
.is_async = try parser.elementGetAttribute(e, "async") != null,
688-
689683
.src = try parser.elementGetAttribute(e, "src") orelse "inline",
690684
};
691685
}
@@ -695,15 +689,15 @@ pub const Page = struct {
695689
// > type indicates that the script is a "classic script", containing
696690
// > JavaScript code.
697691
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type
698-
fn kind(stype: ?[]const u8) Kind {
692+
fn parseKind(stype: ?[]const u8) Kind {
699693
if (stype == null or stype.?.len == 0) return .javascript;
700694
if (std.mem.eql(u8, stype.?, "application/javascript")) return .javascript;
701695
if (std.mem.eql(u8, stype.?, "module")) return .module;
702696

703697
return .unknown;
704698
}
705699

706-
fn eval(self: Script, arena: Allocator, env: Env, body: []const u8) !void {
700+
fn eval(self: Script, arena: Allocator, env: *const Env, body: []const u8) !void {
707701
var try_catch: jsruntime.TryCatch = undefined;
708702
try_catch.init(env);
709703
defer try_catch.deinit();

‎src/browser/mime.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ pub const Mime = struct {
245245
const bit_len = @bitSizeOf(@TypeOf(target.*)) - 8;
246246
const byte_len = bit_len / 8;
247247

248-
const T = @Type(.{ .Int = .{
248+
const T = @Type(.{ .int = .{
249249
.bits = bit_len,
250250
.signedness = .unsigned,
251251
} });

‎src/cdp/cdp.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
454454
pub fn sendResult(self: *Self, result: anytype, opts: SendResultOpts) !void {
455455
return self.sender.sendJSON(.{
456456
.id = self.input.id,
457-
.result = if (comptime @typeInfo(@TypeOf(result)) == .Null) struct {}{} else result,
457+
.result = if (comptime @typeInfo(@TypeOf(result)) == .null) struct {}{} else result,
458458
.sessionId = if (opts.include_session_id) self.input.session_id else null,
459459
});
460460
}
@@ -466,7 +466,7 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
466466
// Events ALWAYS go to the client. self.sender should not be used
467467
return self.cdp.sendJSON(.{
468468
.method = method,
469-
.params = if (comptime @typeInfo(@TypeOf(p)) == .Null) struct {}{} else p,
469+
.params = if (comptime @typeInfo(@TypeOf(p)) == .null) struct {}{} else p,
470470
.sessionId = opts.session_id,
471471
});
472472
}

‎src/cdp/testing.zig

+4-97
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ const TestContext = struct {
174174

175175
pub fn processMessage(self: *TestContext, msg: anytype) !void {
176176
var json_message: []const u8 = undefined;
177-
if (@typeInfo(@TypeOf(msg)) != .Pointer) {
178-
json_message = try json.stringifyAlloc(self.arena.allocator(), msg, .{});
177+
if (@typeInfo(@TypeOf(msg)) != .pointer) {
178+
json_message = try std.json.stringifyAlloc(self.arena.allocator(), msg, .{});
179179
} else {
180180
// assume this is a string we want to send as-is, if it isn't, we'll
181181
// get a compile error, so no big deal.
@@ -196,7 +196,7 @@ const TestContext = struct {
196196
pub fn expectSentResult(self: *TestContext, expected: anytype, opts: ExpectResultOpts) !void {
197197
const expected_result = .{
198198
.id = opts.id,
199-
.result = if (comptime @typeInfo(@TypeOf(expected)) == .Null) struct {}{} else expected,
199+
.result = if (comptime @typeInfo(@TypeOf(expected)) == .null) struct {}{} else expected,
200200
.sessionId = opts.session_id,
201201
};
202202

@@ -210,7 +210,7 @@ const TestContext = struct {
210210
pub fn expectSentEvent(self: *TestContext, method: []const u8, params: anytype, opts: ExpectEventOpts) !void {
211211
const expected_event = .{
212212
.method = method,
213-
.params = if (comptime @typeInfo(@TypeOf(params)) == .Null) struct {}{} else params,
213+
.params = if (comptime @typeInfo(@TypeOf(params)) == .null) struct {}{} else params,
214214
.sessionId = opts.session_id,
215215
};
216216

@@ -323,96 +323,3 @@ fn compareJsonValues(a: std.json.Value, b: std.json.Value) bool {
323323
},
324324
}
325325
}
326-
327-
// fn compareAnyToJsonValue(expected: anytype, actual: json.Value) bool {
328-
// switch (@typeInfo(@TypeOf(expected))) {
329-
// .Optional => {
330-
// if (expected) |e| {
331-
// return compareAnyToJsonValue(e, actual);
332-
// }
333-
// return actual == .null;
334-
// },
335-
// .Int, .ComptimeInt => {
336-
// if (actual != .integer) {
337-
// return false;
338-
// }
339-
// return expected == actual.integer;
340-
// },
341-
// .Float, .ComptimeFloat => {
342-
// if (actual != .float) {
343-
// return false;
344-
// }
345-
// return expected == actual.float;
346-
// },
347-
// .Bool => {
348-
// if (actual != .bool) {
349-
// return false;
350-
// }
351-
// return expected == actual.bool;
352-
// },
353-
// .Pointer => |ptr| switch (ptr.size) {
354-
// .One => switch (@typeInfo(ptr.child)) {
355-
// .Struct => return compareAnyToJsonValue(expected.*, actual),
356-
// .Array => |arr| if (arr.child == u8) {
357-
// if (actual != .string) {
358-
// return false;
359-
// }
360-
// return std.mem.eql(u8, expected, actual.string);
361-
// },
362-
// else => {},
363-
// },
364-
// .Slice => switch (ptr.child) {
365-
// u8 => {
366-
// if (actual != .string) {
367-
// return false;
368-
// }
369-
// return std.mem.eql(u8, expected, actual.string);
370-
// },
371-
// else => {},
372-
// },
373-
// else => {},
374-
// },
375-
// .Struct => |s| {
376-
// if (s.is_tuple) {
377-
// // how an array might look in an anytype
378-
// if (actual != .array) {
379-
// return false;
380-
// }
381-
// if (s.fields.len != actual.array.items.len) {
382-
// return false;
383-
// }
384-
385-
// inline for (s.fields, 0..) |f, i| {
386-
// const e = @field(expected, f.name);
387-
// if (compareAnyToJsonValue(e, actual.array.items[i]) == false) {
388-
// return false;
389-
// }
390-
// }
391-
// return true;
392-
// }
393-
394-
// if (s.fields.len == 0) {
395-
// return (actual == .array and actual.array.items.len == 0);
396-
// }
397-
398-
// if (actual != .object) {
399-
// return false;
400-
// }
401-
// inline for (s.fields) |f| {
402-
// const e = @field(expected, f.name);
403-
// if (actual.object.get(f.name)) |a| {
404-
// if (compareAnyToJsonValue(e, a) == false) {
405-
// return false;
406-
// }
407-
// } else if (@typeInfo(f.type) != .Optional or e != null) {
408-
// // We don't JSON serialize nulls. So if we're expecting
409-
// // a null, that should show up as a missing field.
410-
// return false;
411-
// }
412-
// }
413-
// return true;
414-
// },
415-
// else => {},
416-
// }
417-
// @compileError("Can't compare " ++ @typeName(@TypeOf(expected)));
418-
// }

‎src/generate.zig

+9-9
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn Union(interfaces: anytype) type {
6363
.decls = &.{},
6464
.is_exhaustive = true,
6565
};
66-
const enum_T = @Type(.{ .Enum = enum_info });
66+
const enum_T = @Type(.{ .@"enum" = enum_info });
6767

6868
// third iteration to generate union type
6969
var union_fields: [fields.len]Type.UnionField = undefined;
@@ -79,7 +79,7 @@ pub fn Union(interfaces: anytype) type {
7979
};
8080
}
8181

82-
return @Type(.{ .Union = .{
82+
return @Type(.{ .@"union" = .{
8383
.layout = .auto,
8484
.tag_type = enum_T,
8585
.fields = &union_fields,
@@ -115,12 +115,12 @@ pub fn Tuple(args: anytype) type {
115115
// has to be true in order to properly capture the default value
116116
.is_comptime = true,
117117
.alignment = @alignOf(type),
118-
.default_value = @ptrCast(&interfaces[i]),
118+
.default_value_ptr = @ptrCast(&interfaces[i]),
119119
};
120120
field_index += 1;
121121
}
122122

123-
return @Type(.{ .Struct = .{
123+
return @Type(.{ .@"struct" = .{
124124
.layout = .auto,
125125
.fields = &fields,
126126
.decls = &.{},
@@ -130,7 +130,7 @@ pub fn Tuple(args: anytype) type {
130130

131131
fn countInterfaces(args: anytype, count: usize) usize {
132132
var new_count = count;
133-
for (@typeInfo(@TypeOf(args)).Struct.fields) |f| {
133+
for (@typeInfo(@TypeOf(args)).@"struct".fields) |f| {
134134
const member = @field(args, f.name);
135135
if (@TypeOf(member) == type) {
136136
new_count += 1;
@@ -143,7 +143,7 @@ fn countInterfaces(args: anytype, count: usize) usize {
143143

144144
fn flattenInterfaces(args: anytype, interfaces: []type, index: usize) usize {
145145
var new_index = index;
146-
for (@typeInfo(@TypeOf(args)).Struct.fields) |f| {
146+
for (@typeInfo(@TypeOf(args)).@"struct".fields) |f| {
147147
const member = @field(args, f.name);
148148
if (@TypeOf(member) == type) {
149149
interfaces[new_index] = member;
@@ -186,7 +186,7 @@ test "generate.Union" {
186186
};
187187

188188
const value = Union(.{ Astruct, Bstruct, .{Cstruct} });
189-
const ti = @typeInfo(value).Union;
189+
const ti = @typeInfo(value).@"union";
190190
try std.testing.expectEqual(3, ti.fields.len);
191191
try std.testing.expectEqualStrings("*generate.test.generate.Union.Astruct.Other", @typeName(ti.fields[0].type));
192192
try std.testing.expectEqualStrings(ti.fields[0].name, "Astruct");
@@ -209,7 +209,7 @@ test "generate.Tuple" {
209209

210210
{
211211
const tuple = Tuple(.{ Astruct, Bstruct }){};
212-
const ti = @typeInfo(@TypeOf(tuple)).Struct;
212+
const ti = @typeInfo(@TypeOf(tuple)).@"struct";
213213
try std.testing.expectEqual(true, ti.is_tuple);
214214
try std.testing.expectEqual(2, ti.fields.len);
215215
try std.testing.expectEqual(Astruct, tuple.@"0");
@@ -219,7 +219,7 @@ test "generate.Tuple" {
219219
{
220220
// dedupe
221221
const tuple = Tuple(.{ Cstruct, Astruct, .{Astruct}, Bstruct, .{ Astruct, .{ Astruct, Bstruct } } }){};
222-
const ti = @typeInfo(@TypeOf(tuple)).Struct;
222+
const ti = @typeInfo(@TypeOf(tuple)).@"struct";
223223
try std.testing.expectEqual(true, ti.is_tuple);
224224
try std.testing.expectEqual(3, ti.fields.len);
225225
try std.testing.expectEqual(Cstruct, tuple.@"0");

‎src/http/Client.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ pub fn connectTcp(client: *Client, host: []const u8, port: u16, protocol: Connec
13581358

13591359
conn.data.tls_client.* = tls23.client(stream, .{
13601360
.host = host,
1361-
.root_ca = client.ca_bundle,
1361+
.root_ca = .{ .bundle = client.ca_bundle },
13621362
}) catch return error.TlsInitializationFailed;
13631363
}
13641364

‎src/id.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn Incrementing(comptime T: type, comptime prefix: []const u8) type {
2727
break :blk b;
2828
};
2929

30-
const PrefixIntType = @Type(.{ .Int = .{
30+
const PrefixIntType = @Type(.{ .int = .{
3131
.bits = NUMERIC_START * 8,
3232
.signedness = .unsigned,
3333
} });

‎src/log.zig

+11-11
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn LogT(comptime Out: type, comptime enhanced_readability: bool) type {
151151
buffer.appendSliceAssumeCapacity(inject);
152152
}
153153

154-
inline for (@typeInfo(@TypeOf(data)).Struct.fields) |f| {
154+
inline for (@typeInfo(@TypeOf(data)).@"struct".fields) |f| {
155155
// + 2 for the leading space and the equal sign
156156
// + 5 to save space for null/false/true common values
157157
const key_len = f.name.len + 7;
@@ -179,30 +179,30 @@ fn LogT(comptime Out: type, comptime enhanced_readability: bool) type {
179179
fn writeValue(allocator: Allocator, buffer: *std.ArrayListUnmanaged(u8), value: anytype) !void {
180180
const T = @TypeOf(value);
181181
switch (@typeInfo(T)) {
182-
.Optional => {
182+
.optional => {
183183
if (value) |v| {
184184
return writeValue(allocator, buffer, v);
185185
}
186186
// in _log, we reserved space for a value of up to 5 bytes.
187187
return buffer.appendSliceAssumeCapacity("null");
188188
},
189-
.ComptimeInt, .Int, .ComptimeFloat, .Float => {
189+
.comptime_int, .int, .comptime_float, .float => {
190190
return std.fmt.format(buffer.writer(allocator), "{d}", .{value});
191191
},
192-
.Bool => {
192+
.bool => {
193193
// in _log, we reserved space for a value of up to 5 bytes.
194194
return buffer.appendSliceAssumeCapacity(if (value) "true" else "false");
195195
},
196-
.ErrorSet => return buffer.appendSlice(allocator, @errorName(value)),
197-
.Enum => return buffer.appendSlice(allocator, @tagName(value)),
198-
.Array => return writeValue(allocator, buffer, &value),
199-
.Pointer => |ptr| switch (ptr.size) {
200-
.Slice => switch (ptr.child) {
196+
.error_set => return buffer.appendSlice(allocator, @errorName(value)),
197+
.@"enum" => return buffer.appendSlice(allocator, @tagName(value)),
198+
.array => return writeValue(allocator, buffer, &value),
199+
.pointer => |ptr| switch (ptr.size) {
200+
.slice => switch (ptr.child) {
201201
u8 => return writeString(allocator, buffer, value),
202202
else => {},
203203
},
204-
.One => switch (@typeInfo(ptr.child)) {
205-
.Array => |arr| if (arr.child == u8) {
204+
.one => switch (@typeInfo(ptr.child)) {
205+
.array => |arr| if (arr.child == u8) {
206206
return writeString(allocator, buffer, value);
207207
},
208208
else => return false,

‎src/main.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const version = @import("build_info").git_commit;
3535

3636
const log = std.log.scoped(.cli);
3737

38-
pub const std_options = .{
38+
pub const std_options = std.Options{
3939
// Set the log level to info
4040
.log_level = .debug,
4141

@@ -344,7 +344,7 @@ fn parseFetchArgs(
344344
var verbose: bool = builtin.mode == .Debug; // In debug mode, force verbose.
345345
fn logFn(
346346
comptime level: std.log.Level,
347-
comptime scope: @Type(.EnumLiteral),
347+
comptime scope: @Type(.enum_literal),
348348
comptime format: []const u8,
349349
args: anytype,
350350
) void {

‎src/netsurf/netsurf.zig

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ pub const Tag = enum(u8) {
260260

261261
pub fn all() []Tag {
262262
comptime {
263-
const info = @typeInfo(Tag).Enum;
263+
const info = @typeInfo(Tag).@"enum";
264264
var l: [info.fields.len]Tag = undefined;
265265
for (info.fields, 0..) |field, i| {
266266
l[i] = @as(Tag, @enumFromInt(field.value));
@@ -804,7 +804,7 @@ pub fn eventTargetDispatchEvent(et: *EventTarget, event: *Event) !bool {
804804
pub fn eventTargetTBaseFieldName(comptime T: type) ?[]const u8 {
805805
std.debug.assert(@inComptime());
806806
switch (@typeInfo(T)) {
807-
.Struct => |ti| {
807+
.@"struct" => |ti| {
808808
for (ti.fields) |f| {
809809
if (f.type == EventTargetTBase) return f.name;
810810
}

‎src/polyfill/fetch.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub fn testExecFn(
2020
alloc: std.mem.Allocator,
2121
js_env: *jsruntime.Env,
2222
) anyerror!void {
23-
try @import("polyfill.zig").load(alloc, js_env.*);
23+
try @import("polyfill.zig").load(alloc, js_env);
2424

2525
var fetch = [_]Case{
2626
.{

‎src/polyfill/polyfill.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const modules = [_]struct {
3333
.{ .name = "polyfill-fetch", .source = @import("fetch.zig").source },
3434
};
3535

36-
pub fn load(alloc: std.mem.Allocator, env: Env) !void {
36+
pub fn load(alloc: std.mem.Allocator, env: *const Env) !void {
3737
var try_catch: jsruntime.TryCatch = undefined;
3838
try_catch.init(env);
3939
defer try_catch.deinit();

‎src/server.zig

+5-27
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,14 @@ const Server = struct {
5757
listener: posix.socket_t,
5858
timeout: u64,
5959

60-
// A memory poor for our Clients. Because we only allow 1 client to be
61-
// connected at a time, and because of the way we accept, we don't need
62-
// a lock for this, since the creation of a new client cannot happen at the
63-
// same time as the destruction of a client.
64-
client_pool: std.heap.MemoryPool(Client),
65-
client_pool_lock: std.Thread.Mutex = .{},
66-
6760
// I/O fields
6861
accept_completion: Completion,
6962

7063
// The response to send on a GET /json/version request
7164
json_version_response: []const u8,
7265

7366
fn deinit(self: *Server) void {
74-
self.client_pool.deinit();
67+
_ = self;
7568
}
7669

7770
fn queueAccept(self: *Server) void {
@@ -102,28 +95,14 @@ const Server = struct {
10295
result: AcceptError!posix.socket_t,
10396
) !void {
10497
const socket = try result;
105-
106-
const client = blk: {
107-
self.client_pool_lock.lock();
108-
defer self.client_pool_lock.unlock();
109-
break :blk try self.client_pool.create();
110-
};
111-
112-
errdefer {
113-
self.client_pool_lock.lock();
114-
self.client_pool.destroy(client);
115-
self.client_pool_lock.unlock();
116-
}
117-
98+
const client = try self.allocator.create(Client);
11899
client.* = Client.init(socket, self);
119100
client.start();
120101
log.info("client connected", .{});
121102
}
122103

123104
fn releaseClient(self: *Server, client: *Client) void {
124-
self.client_pool_lock.lock();
125-
self.client_pool.destroy(client);
126-
self.client_pool_lock.unlock();
105+
self.allocator.destroy(client);
127106
}
128107
};
129108

@@ -1053,7 +1032,6 @@ pub fn run(
10531032
.allocator = allocator,
10541033
.accept_completion = undefined,
10551034
.json_version_response = json_version_response,
1056-
.client_pool = std.heap.MemoryPool(Client).init(allocator),
10571035
};
10581036
defer server.deinit();
10591037

@@ -1488,8 +1466,8 @@ fn createTestClient() !TestClient {
14881466
const stream = try std.net.tcpConnectToAddress(address);
14891467

14901468
const timeout = std.mem.toBytes(posix.timeval{
1491-
.tv_sec = 2,
1492-
.tv_usec = 0,
1469+
.sec = 2,
1470+
.usec = 0,
14931471
});
14941472
try posix.setsockopt(stream.handle, posix.SOL.SOCKET, posix.SO.RCVTIMEO, &timeout);
14951473
try posix.setsockopt(stream.handle, posix.SOL.SOCKET, posix.SO.SNDTIMEO, &timeout);

‎src/storage/cookie.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ fn expectAttribute(expected: anytype, url: ?[]const u8, set_cookie: []const u8)
922922
var cookie = try Cookie.parse(testing.allocator, uri, set_cookie);
923923
defer cookie.deinit();
924924

925-
inline for (@typeInfo(@TypeOf(expected)).Struct.fields) |f| {
925+
inline for (@typeInfo(@TypeOf(expected)).@"struct".fields) |f| {
926926
if (comptime std.mem.eql(u8, f.name, "expires")) {
927927
try testing.expectDelta(expected.expires, cookie.expires, 1);
928928
} else {

‎src/str/parser.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub fn asUint(comptime string: anytype) AsUintReturn(string) {
6666

6767
fn AsUintReturn(comptime string: anytype) type {
6868
return @Type(.{
69-
.Int = .{
69+
.int = .{
7070
.bits = @bitSizeOf(@TypeOf(string.*)) - 8, // (- 8) to exclude sentinel 0
7171
.signedness = .unsigned,
7272
},

‎src/testing.zig

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ const App = @import("app.zig").App;
1111
// exactly how to assert equality
1212
pub fn expectEqual(expected: anytype, actual: anytype) !void {
1313
switch (@typeInfo(@TypeOf(actual))) {
14-
.Array => |arr| if (arr.child == u8) {
14+
.array => |arr| if (arr.child == u8) {
1515
return std.testing.expectEqualStrings(expected, &actual);
1616
},
17-
.Pointer => |ptr| {
17+
.pointer => |ptr| {
1818
if (ptr.child == u8) {
1919
return std.testing.expectEqualStrings(expected, actual);
2020
} else if (comptime isStringArray(ptr.child)) {
@@ -23,19 +23,19 @@ pub fn expectEqual(expected: anytype, actual: anytype) !void {
2323
return expectString(expected, actual);
2424
}
2525
},
26-
.Struct => |structType| {
26+
.@"struct" => |structType| {
2727
inline for (structType.fields) |field| {
2828
try expectEqual(@field(expected, field.name), @field(actual, field.name));
2929
}
3030
return;
3131
},
32-
.Optional => {
32+
.optional => {
3333
if (actual == null) {
3434
return std.testing.expectEqual(null, expected);
3535
}
3636
return expectEqual(expected, actual.?);
3737
},
38-
.Union => |union_info| {
38+
.@"union" => |union_info| {
3939
if (union_info.tag_type == null) {
4040
@compileError("Unable to compare untagged union values");
4141
}
@@ -59,12 +59,12 @@ pub fn expectEqual(expected: anytype, actual: anytype) !void {
5959
}
6060

6161
pub fn expectDelta(expected: anytype, actual: anytype, delta: anytype) !void {
62-
if (@typeInfo(@TypeOf(expected)) == .Null) {
62+
if (@typeInfo(@TypeOf(expected)) == .null) {
6363
return std.testing.expectEqual(null, actual);
6464
}
6565

6666
switch (@typeInfo(@TypeOf(actual))) {
67-
.Optional => {
67+
.optional => {
6868
if (actual) |value| {
6969
return expectDelta(expected, value, delta);
7070
}
@@ -74,7 +74,7 @@ pub fn expectDelta(expected: anytype, actual: anytype, delta: anytype) !void {
7474
}
7575

7676
switch (@typeInfo(@TypeOf(expected))) {
77-
.Optional => {
77+
.optional => {
7878
if (expected) |value| {
7979
return expectDelta(value, actual, delta);
8080
}
@@ -96,7 +96,7 @@ pub fn expectDelta(expected: anytype, actual: anytype, delta: anytype) !void {
9696
}
9797

9898
fn isStringArray(comptime T: type) bool {
99-
if (!is(.Array)(T) and !isPtrTo(.Array)(T)) {
99+
if (!is(.array)(T) and !isPtrTo(.array)(T)) {
100100
return false;
101101
}
102102
return std.meta.Elem(T) == u8;
@@ -124,7 +124,7 @@ pub fn isPtrTo(comptime id: std.builtin.TypeId) TraitFn {
124124

125125
pub fn isSingleItemPtr(comptime T: type) bool {
126126
if (comptime is(.pointer)(T)) {
127-
return @typeInfo(T).Pointer.size == .one;
127+
return @typeInfo(T).pointer.size == .one;
128128
}
129129
return false;
130130
}

‎src/url/query.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn testParseQuery(expected: anytype, query: []const u8) !void {
420420
defer values.deinit();
421421

422422
var count: usize = 0;
423-
inline for (@typeInfo(@TypeOf(expected)).Struct.fields) |f| {
423+
inline for (@typeInfo(@TypeOf(expected)).@"struct".fields) |f| {
424424
const actual = values.get(f.name);
425425
const expect = @field(expected, f.name);
426426
try testing.expectEqual(expect.len, actual.len);

0 commit comments

Comments
 (0)
Please sign in to comment.