Skip to content

Commit c555c32

Browse files
committed
upgrade to zig 0.12
0.12.0-dev.3439+31a7f22b8
1 parent 9310b91 commit c555c32

File tree

8 files changed

+45
-38
lines changed

8 files changed

+45
-38
lines changed

src/async/Client.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub const Connection = struct {
247247
read_buf: [buffer_size]u8 = undefined,
248248
write_buf: [buffer_size]u8 = undefined,
249249

250-
pub fn readvDirectTls(conn: *Connection, buffers: []std.os.iovec) ReadError!usize {
250+
pub fn readvDirectTls(conn: *Connection, buffers: []std.posix.iovec) ReadError!usize {
251251
return conn.tls_client.readv(conn.stream, buffers) catch |err| {
252252
// https://github.com/ziglang/zig/issues/2473
253253
if (mem.startsWith(u8, @errorName(err), "TlsAlert")) return error.TlsAlert;
@@ -261,7 +261,7 @@ pub const Connection = struct {
261261
};
262262
}
263263

264-
pub fn readvDirect(conn: *Connection, buffers: []std.os.iovec) ReadError!usize {
264+
pub fn readvDirect(conn: *Connection, buffers: []std.posix.iovec) ReadError!usize {
265265
if (conn.protocol == .tls) {
266266
if (disable_tls) unreachable;
267267

@@ -279,7 +279,7 @@ pub const Connection = struct {
279279
pub fn fill(conn: *Connection) ReadError!void {
280280
if (conn.read_end != conn.read_start) return;
281281

282-
var iovecs = [1]std.os.iovec{
282+
var iovecs = [1]std.posix.iovec{
283283
.{ .iov_base = &conn.read_buf, .iov_len = conn.read_buf.len },
284284
};
285285
const nread = try conn.readvDirect(&iovecs);
@@ -315,7 +315,7 @@ pub const Connection = struct {
315315
return available_read;
316316
}
317317

318-
var iovecs = [2]std.os.iovec{
318+
var iovecs = [2]std.posix.iovec{
319319
.{ .iov_base = buffer.ptr, .iov_len = buffer.len },
320320
.{ .iov_base = &conn.read_buf, .iov_len = conn.read_buf.len },
321321
};

src/async/stream.zig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
const std = @import("std");
2020
const builtin = @import("builtin");
21-
const os = std.os;
21+
const posix = std.posix;
2222
const io = std.io;
2323
const assert = std.debug.assert;
2424

@@ -28,15 +28,15 @@ pub const Stream = struct {
2828
alloc: std.mem.Allocator,
2929
conn: *tcp.Conn,
3030

31-
handle: std.os.socket_t,
31+
handle: posix.socket_t,
3232

3333
pub fn close(self: Stream) void {
34-
os.closeSocket(self.handle);
34+
posix.closeSocket(self.handle);
3535
self.alloc.destroy(self.conn);
3636
}
3737

38-
pub const ReadError = os.ReadError;
39-
pub const WriteError = os.WriteError;
38+
pub const ReadError = posix.ReadError;
39+
pub const WriteError = posix.WriteError;
4040

4141
pub const Reader = io.Reader(Stream, ReadError, read);
4242
pub const Writer = io.Writer(Stream, WriteError, write);
@@ -55,8 +55,8 @@ pub const Stream = struct {
5555
};
5656
}
5757

58-
pub fn readv(s: Stream, iovecs: []const os.iovec) ReadError!usize {
59-
return os.readv(s.handle, iovecs);
58+
pub fn readv(s: Stream, iovecs: []const posix.iovec) ReadError!usize {
59+
return posix.readv(s.handle, iovecs);
6060
}
6161

6262
/// Returns the number of bytes read. If the number read is smaller than
@@ -105,7 +105,7 @@ pub const Stream = struct {
105105

106106
/// See https://github.com/ziglang/zig/issues/7699
107107
/// See equivalent function: `std.fs.File.writev`.
108-
pub fn writev(self: Stream, iovecs: []const os.iovec_const) WriteError!usize {
108+
pub fn writev(self: Stream, iovecs: []const posix.iovec_const) WriteError!usize {
109109
if (iovecs.len == 0) return 0;
110110
const first_buffer = iovecs[0].iov_base[0..iovecs[0].iov_len];
111111
return try self.write(first_buffer);
@@ -115,7 +115,7 @@ pub const Stream = struct {
115115
/// order to handle partial writes from the underlying OS layer.
116116
/// See https://github.com/ziglang/zig/issues/7699
117117
/// See equivalent function: `std.fs.File.writevAll`.
118-
pub fn writevAll(self: Stream, iovecs: []os.iovec_const) WriteError!void {
118+
pub fn writevAll(self: Stream, iovecs: []posix.iovec_const) WriteError!void {
119119
if (iovecs.len == 0) return;
120120

121121
var i: usize = 0;

src/async/tcp.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ pub const Conn = struct {
5959

6060
loop: *Loop,
6161

62-
pub fn connect(self: *Conn, socket: std.os.socket_t, address: std.net.Address) !void {
62+
pub fn connect(self: *Conn, socket: std.posix.socket_t, address: std.net.Address) !void {
6363
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
6464
cmd.impl.connect(&cmd, socket, address);
6565
_ = try cmd.wait();
6666
}
6767

68-
pub fn send(self: *Conn, socket: std.os.socket_t, buffer: []const u8) !usize {
68+
pub fn send(self: *Conn, socket: std.posix.socket_t, buffer: []const u8) !usize {
6969
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
7070
cmd.impl.send(&cmd, socket, buffer);
7171
return try cmd.wait();
7272
}
7373

74-
pub fn receive(self: *Conn, socket: std.os.socket_t, buffer: []u8) !usize {
74+
pub fn receive(self: *Conn, socket: std.posix.socket_t, buffer: []u8) !usize {
7575
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
7676
cmd.impl.receive(&cmd, socket, buffer);
7777
return try cmd.wait();
@@ -93,12 +93,12 @@ pub fn tcpConnectToHost(alloc: std.mem.Allocator, loop: *Loop, name: []const u8,
9393
else => return err,
9494
};
9595
}
96-
return std.os.ConnectError.ConnectionRefused;
96+
return std.posix.ConnectError.ConnectionRefused;
9797
}
9898

9999
pub fn tcpConnectToAddress(alloc: std.mem.Allocator, loop: *Loop, addr: net.Address) !Stream {
100-
const sockfd = try std.os.socket(addr.any.family, std.os.SOCK.STREAM, std.os.IPPROTO.TCP);
101-
errdefer std.os.closeSocket(sockfd);
100+
const sockfd = try std.posix.socket(addr.any.family, std.posix.SOCK.STREAM, std.posix.IPPROTO.TCP);
101+
errdefer std.posix.closeSocket(sockfd);
102102

103103
var conn = try alloc.create(Conn);
104104
conn.* = Conn{ .loop = loop };

src/generate.zig

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ fn itoa(comptime i: u8) ![]const u8 {
3535
return try std.fmt.bufPrint(buf[0..], "{d}", .{i});
3636
}
3737

38-
fn fmtName(comptime T: type) []const u8 {
38+
fn fmtName(comptime T: type) [:0]const u8 {
3939
var it = std.mem.splitBackwards(u8, @typeName(T), ".");
40-
return it.first();
40+
return it.first() ++ "";
4141
}
4242

4343
// Union
@@ -168,15 +168,19 @@ pub const Union = struct {
168168
T = *T;
169169
}
170170
union_fields[done] = .{
171-
.name = fmtName(member_T),
171+
// UnionField.name expect a null terminated string.
172+
// concatenate the `[]const u8` string with an empty string
173+
// literal (`name ++ ""`) to explicitly coerce it to `[:0]const
174+
// u8`.
175+
.name = fmtName(member_T) ++ "",
172176
.type = T,
173177
.alignment = @alignOf(T),
174178
};
175179
done += 1;
176180
}
177181
}
178182
const union_info = std.builtin.Type.Union{
179-
.layout = .Auto,
183+
.layout = .auto,
180184
.tag_type = enum_T,
181185
.fields = &union_fields,
182186
.decls = &decls,
@@ -286,7 +290,11 @@ fn TupleT(comptime tuple: anytype) type {
286290
continue;
287291
}
288292
fields[done] = .{
289-
.name = try itoa(done),
293+
// StructField.name expect a null terminated string.
294+
// concatenate the `[]const u8` string with an empty string
295+
// literal (`name ++ ""`) to explicitly coerce it to `[:0]const
296+
// u8`.
297+
.name = try itoa(done) ++ "",
290298
.type = type,
291299
.default_value = null,
292300
.is_comptime = false,
@@ -296,7 +304,7 @@ fn TupleT(comptime tuple: anytype) type {
296304
}
297305
const decls: [0]std.builtin.Type.Declaration = undefined;
298306
const info = std.builtin.Type.Struct{
299-
.layout = .Auto,
307+
.layout = .auto,
300308
.fields = &fields,
301309
.decls = &decls,
302310
.is_tuple = true,

src/main.zig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub const UserContext = apiweb.UserContext;
3030
const socket_path = "/tmp/browsercore-server.sock";
3131

3232
var doc: *parser.DocumentHTML = undefined;
33-
var server: std.net.StreamServer = undefined;
33+
var server: std.net.Server = undefined;
3434

3535
fn execJS(
3636
alloc: std.mem.Allocator,
@@ -91,17 +91,16 @@ pub fn main() !void {
9191
// reuse_address (SO_REUSEADDR flag) does not seems to work on unix socket
9292
// see: https://gavv.net/articles/unix-socket-reuse/
9393
// TODO: use a lock file instead
94-
std.os.unlink(socket_path) catch |err| {
94+
std.posix.unlink(socket_path) catch |err| {
9595
if (err != error.FileNotFound) {
9696
return err;
9797
}
9898
};
9999

100100
// server
101101
const addr = try std.net.Address.initUnix(socket_path);
102-
server = std.net.StreamServer.init(.{});
102+
server = try addr.listen(.{});
103103
defer server.deinit();
104-
try server.listen(addr);
105104
std.debug.print("Listening on: {s}...\n", .{socket_path});
106105

107106
try jsruntime.loadEnv(&arena, null, execJS);

src/main_get.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn main() !void {
5858
while (args.next()) |arg| {
5959
if (std.mem.eql(u8, "-h", arg) or std.mem.eql(u8, "--help", arg)) {
6060
try std.io.getStdErr().writer().print(usage, .{execname});
61-
std.os.exit(0);
61+
std.posix.exit(0);
6262
}
6363
if (std.mem.eql(u8, "--dump", arg)) {
6464
dump = true;
@@ -67,14 +67,14 @@ pub fn main() !void {
6767
// allow only one url
6868
if (url.len != 0) {
6969
try std.io.getStdErr().writer().print(usage, .{execname});
70-
std.os.exit(1);
70+
std.posix.exit(1);
7171
}
7272
url = arg;
7373
}
7474

7575
if (url.len == 0) {
7676
try std.io.getStdErr().writer().print(usage, .{execname});
77-
std.os.exit(1);
77+
std.posix.exit(1);
7878
}
7979

8080
const vm = jsruntime.VM.init();

src/main_wpt.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn main() !void {
7676
while (args.next()) |arg| {
7777
if (std.mem.eql(u8, "-h", arg) or std.mem.eql(u8, "--help", arg)) {
7878
try std.io.getStdErr().writer().print(usage, .{execname});
79-
std.os.exit(0);
79+
std.posix.exit(0);
8080
}
8181
if (std.mem.eql(u8, "--json", arg)) {
8282
out = .json;
@@ -214,12 +214,12 @@ pub fn main() !void {
214214
}
215215

216216
try std.json.stringify(output.items, .{ .whitespace = .indent_2 }, std.io.getStdOut().writer());
217-
std.os.exit(0);
217+
std.posix.exit(0);
218218
}
219219

220220
if (out == .text and failures > 0) {
221221
std.debug.print("{d}/{d} tests suites failures\n", .{ failures, run });
222-
std.os.exit(1);
222+
std.posix.exit(1);
223223
}
224224
}
225225

src/netsurf.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ pub const Tag = enum(u8) {
265265
pub fn all() []Tag {
266266
comptime {
267267
const info = @typeInfo(Tag).Enum;
268-
comptime var l: [info.fields.len]Tag = undefined;
269-
inline for (info.fields, 0..) |field, i| {
268+
var l: [info.fields.len]Tag = undefined;
269+
for (info.fields, 0..) |field, i| {
270270
l[i] = @as(Tag, @enumFromInt(field.value));
271271
}
272272
return &l;
@@ -277,7 +277,7 @@ pub const Tag = enum(u8) {
277277
comptime {
278278
const tags = all();
279279
var names: [tags.len][]const u8 = undefined;
280-
inline for (tags, 0..) |tag, i| {
280+
for (tags, 0..) |tag, i| {
281281
names[i] = tag.elementName();
282282
}
283283
return &names;

0 commit comments

Comments
 (0)