mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
upgrade to zig 0.12
0.12.0-dev.3439+31a7f22b8
This commit is contained in:
@@ -247,7 +247,7 @@ pub const Connection = struct {
|
||||
read_buf: [buffer_size]u8 = undefined,
|
||||
write_buf: [buffer_size]u8 = undefined,
|
||||
|
||||
pub fn readvDirectTls(conn: *Connection, buffers: []std.os.iovec) ReadError!usize {
|
||||
pub fn readvDirectTls(conn: *Connection, buffers: []std.posix.iovec) ReadError!usize {
|
||||
return conn.tls_client.readv(conn.stream, buffers) catch |err| {
|
||||
// https://github.com/ziglang/zig/issues/2473
|
||||
if (mem.startsWith(u8, @errorName(err), "TlsAlert")) return error.TlsAlert;
|
||||
@@ -261,7 +261,7 @@ pub const Connection = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn readvDirect(conn: *Connection, buffers: []std.os.iovec) ReadError!usize {
|
||||
pub fn readvDirect(conn: *Connection, buffers: []std.posix.iovec) ReadError!usize {
|
||||
if (conn.protocol == .tls) {
|
||||
if (disable_tls) unreachable;
|
||||
|
||||
@@ -279,7 +279,7 @@ pub const Connection = struct {
|
||||
pub fn fill(conn: *Connection) ReadError!void {
|
||||
if (conn.read_end != conn.read_start) return;
|
||||
|
||||
var iovecs = [1]std.os.iovec{
|
||||
var iovecs = [1]std.posix.iovec{
|
||||
.{ .iov_base = &conn.read_buf, .iov_len = conn.read_buf.len },
|
||||
};
|
||||
const nread = try conn.readvDirect(&iovecs);
|
||||
@@ -315,7 +315,7 @@ pub const Connection = struct {
|
||||
return available_read;
|
||||
}
|
||||
|
||||
var iovecs = [2]std.os.iovec{
|
||||
var iovecs = [2]std.posix.iovec{
|
||||
.{ .iov_base = buffer.ptr, .iov_len = buffer.len },
|
||||
.{ .iov_base = &conn.read_buf, .iov_len = conn.read_buf.len },
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
const io = std.io;
|
||||
const assert = std.debug.assert;
|
||||
|
||||
@@ -28,15 +28,15 @@ pub const Stream = struct {
|
||||
alloc: std.mem.Allocator,
|
||||
conn: *tcp.Conn,
|
||||
|
||||
handle: std.os.socket_t,
|
||||
handle: posix.socket_t,
|
||||
|
||||
pub fn close(self: Stream) void {
|
||||
os.closeSocket(self.handle);
|
||||
posix.closeSocket(self.handle);
|
||||
self.alloc.destroy(self.conn);
|
||||
}
|
||||
|
||||
pub const ReadError = os.ReadError;
|
||||
pub const WriteError = os.WriteError;
|
||||
pub const ReadError = posix.ReadError;
|
||||
pub const WriteError = posix.WriteError;
|
||||
|
||||
pub const Reader = io.Reader(Stream, ReadError, read);
|
||||
pub const Writer = io.Writer(Stream, WriteError, write);
|
||||
@@ -55,8 +55,8 @@ pub const Stream = struct {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn readv(s: Stream, iovecs: []const os.iovec) ReadError!usize {
|
||||
return os.readv(s.handle, iovecs);
|
||||
pub fn readv(s: Stream, iovecs: []const posix.iovec) ReadError!usize {
|
||||
return posix.readv(s.handle, iovecs);
|
||||
}
|
||||
|
||||
/// Returns the number of bytes read. If the number read is smaller than
|
||||
@@ -105,7 +105,7 @@ pub const Stream = struct {
|
||||
|
||||
/// See https://github.com/ziglang/zig/issues/7699
|
||||
/// See equivalent function: `std.fs.File.writev`.
|
||||
pub fn writev(self: Stream, iovecs: []const os.iovec_const) WriteError!usize {
|
||||
pub fn writev(self: Stream, iovecs: []const posix.iovec_const) WriteError!usize {
|
||||
if (iovecs.len == 0) return 0;
|
||||
const first_buffer = iovecs[0].iov_base[0..iovecs[0].iov_len];
|
||||
return try self.write(first_buffer);
|
||||
@@ -115,7 +115,7 @@ pub const Stream = struct {
|
||||
/// order to handle partial writes from the underlying OS layer.
|
||||
/// See https://github.com/ziglang/zig/issues/7699
|
||||
/// See equivalent function: `std.fs.File.writevAll`.
|
||||
pub fn writevAll(self: Stream, iovecs: []os.iovec_const) WriteError!void {
|
||||
pub fn writevAll(self: Stream, iovecs: []posix.iovec_const) WriteError!void {
|
||||
if (iovecs.len == 0) return;
|
||||
|
||||
var i: usize = 0;
|
||||
|
||||
@@ -59,19 +59,19 @@ pub const Conn = struct {
|
||||
|
||||
loop: *Loop,
|
||||
|
||||
pub fn connect(self: *Conn, socket: std.os.socket_t, address: std.net.Address) !void {
|
||||
pub fn connect(self: *Conn, socket: std.posix.socket_t, address: std.net.Address) !void {
|
||||
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
|
||||
cmd.impl.connect(&cmd, socket, address);
|
||||
_ = try cmd.wait();
|
||||
}
|
||||
|
||||
pub fn send(self: *Conn, socket: std.os.socket_t, buffer: []const u8) !usize {
|
||||
pub fn send(self: *Conn, socket: std.posix.socket_t, buffer: []const u8) !usize {
|
||||
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
|
||||
cmd.impl.send(&cmd, socket, buffer);
|
||||
return try cmd.wait();
|
||||
}
|
||||
|
||||
pub fn receive(self: *Conn, socket: std.os.socket_t, buffer: []u8) !usize {
|
||||
pub fn receive(self: *Conn, socket: std.posix.socket_t, buffer: []u8) !usize {
|
||||
var cmd = Command{ .impl = NetworkImpl.init(self.loop) };
|
||||
cmd.impl.receive(&cmd, socket, buffer);
|
||||
return try cmd.wait();
|
||||
@@ -93,12 +93,12 @@ pub fn tcpConnectToHost(alloc: std.mem.Allocator, loop: *Loop, name: []const u8,
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
return std.os.ConnectError.ConnectionRefused;
|
||||
return std.posix.ConnectError.ConnectionRefused;
|
||||
}
|
||||
|
||||
pub fn tcpConnectToAddress(alloc: std.mem.Allocator, loop: *Loop, addr: net.Address) !Stream {
|
||||
const sockfd = try std.os.socket(addr.any.family, std.os.SOCK.STREAM, std.os.IPPROTO.TCP);
|
||||
errdefer std.os.closeSocket(sockfd);
|
||||
const sockfd = try std.posix.socket(addr.any.family, std.posix.SOCK.STREAM, std.posix.IPPROTO.TCP);
|
||||
errdefer std.posix.closeSocket(sockfd);
|
||||
|
||||
var conn = try alloc.create(Conn);
|
||||
conn.* = Conn{ .loop = loop };
|
||||
|
||||
@@ -35,9 +35,9 @@ fn itoa(comptime i: u8) ![]const u8 {
|
||||
return try std.fmt.bufPrint(buf[0..], "{d}", .{i});
|
||||
}
|
||||
|
||||
fn fmtName(comptime T: type) []const u8 {
|
||||
fn fmtName(comptime T: type) [:0]const u8 {
|
||||
var it = std.mem.splitBackwards(u8, @typeName(T), ".");
|
||||
return it.first();
|
||||
return it.first() ++ "";
|
||||
}
|
||||
|
||||
// Union
|
||||
@@ -168,7 +168,11 @@ pub const Union = struct {
|
||||
T = *T;
|
||||
}
|
||||
union_fields[done] = .{
|
||||
.name = fmtName(member_T),
|
||||
// UnionField.name expect a null terminated string.
|
||||
// concatenate the `[]const u8` string with an empty string
|
||||
// literal (`name ++ ""`) to explicitly coerce it to `[:0]const
|
||||
// u8`.
|
||||
.name = fmtName(member_T) ++ "",
|
||||
.type = T,
|
||||
.alignment = @alignOf(T),
|
||||
};
|
||||
@@ -176,7 +180,7 @@ pub const Union = struct {
|
||||
}
|
||||
}
|
||||
const union_info = std.builtin.Type.Union{
|
||||
.layout = .Auto,
|
||||
.layout = .auto,
|
||||
.tag_type = enum_T,
|
||||
.fields = &union_fields,
|
||||
.decls = &decls,
|
||||
@@ -286,7 +290,11 @@ fn TupleT(comptime tuple: anytype) type {
|
||||
continue;
|
||||
}
|
||||
fields[done] = .{
|
||||
.name = try itoa(done),
|
||||
// StructField.name expect a null terminated string.
|
||||
// concatenate the `[]const u8` string with an empty string
|
||||
// literal (`name ++ ""`) to explicitly coerce it to `[:0]const
|
||||
// u8`.
|
||||
.name = try itoa(done) ++ "",
|
||||
.type = type,
|
||||
.default_value = null,
|
||||
.is_comptime = false,
|
||||
@@ -296,7 +304,7 @@ fn TupleT(comptime tuple: anytype) type {
|
||||
}
|
||||
const decls: [0]std.builtin.Type.Declaration = undefined;
|
||||
const info = std.builtin.Type.Struct{
|
||||
.layout = .Auto,
|
||||
.layout = .auto,
|
||||
.fields = &fields,
|
||||
.decls = &decls,
|
||||
.is_tuple = true,
|
||||
|
||||
@@ -30,7 +30,7 @@ pub const UserContext = apiweb.UserContext;
|
||||
const socket_path = "/tmp/browsercore-server.sock";
|
||||
|
||||
var doc: *parser.DocumentHTML = undefined;
|
||||
var server: std.net.StreamServer = undefined;
|
||||
var server: std.net.Server = undefined;
|
||||
|
||||
fn execJS(
|
||||
alloc: std.mem.Allocator,
|
||||
@@ -91,7 +91,7 @@ pub fn main() !void {
|
||||
// reuse_address (SO_REUSEADDR flag) does not seems to work on unix socket
|
||||
// see: https://gavv.net/articles/unix-socket-reuse/
|
||||
// TODO: use a lock file instead
|
||||
std.os.unlink(socket_path) catch |err| {
|
||||
std.posix.unlink(socket_path) catch |err| {
|
||||
if (err != error.FileNotFound) {
|
||||
return err;
|
||||
}
|
||||
@@ -99,9 +99,8 @@ pub fn main() !void {
|
||||
|
||||
// server
|
||||
const addr = try std.net.Address.initUnix(socket_path);
|
||||
server = std.net.StreamServer.init(.{});
|
||||
server = try addr.listen(.{});
|
||||
defer server.deinit();
|
||||
try server.listen(addr);
|
||||
std.debug.print("Listening on: {s}...\n", .{socket_path});
|
||||
|
||||
try jsruntime.loadEnv(&arena, null, execJS);
|
||||
|
||||
@@ -58,7 +58,7 @@ pub fn main() !void {
|
||||
while (args.next()) |arg| {
|
||||
if (std.mem.eql(u8, "-h", arg) or std.mem.eql(u8, "--help", arg)) {
|
||||
try std.io.getStdErr().writer().print(usage, .{execname});
|
||||
std.os.exit(0);
|
||||
std.posix.exit(0);
|
||||
}
|
||||
if (std.mem.eql(u8, "--dump", arg)) {
|
||||
dump = true;
|
||||
@@ -67,14 +67,14 @@ pub fn main() !void {
|
||||
// allow only one url
|
||||
if (url.len != 0) {
|
||||
try std.io.getStdErr().writer().print(usage, .{execname});
|
||||
std.os.exit(1);
|
||||
std.posix.exit(1);
|
||||
}
|
||||
url = arg;
|
||||
}
|
||||
|
||||
if (url.len == 0) {
|
||||
try std.io.getStdErr().writer().print(usage, .{execname});
|
||||
std.os.exit(1);
|
||||
std.posix.exit(1);
|
||||
}
|
||||
|
||||
const vm = jsruntime.VM.init();
|
||||
|
||||
@@ -76,7 +76,7 @@ pub fn main() !void {
|
||||
while (args.next()) |arg| {
|
||||
if (std.mem.eql(u8, "-h", arg) or std.mem.eql(u8, "--help", arg)) {
|
||||
try std.io.getStdErr().writer().print(usage, .{execname});
|
||||
std.os.exit(0);
|
||||
std.posix.exit(0);
|
||||
}
|
||||
if (std.mem.eql(u8, "--json", arg)) {
|
||||
out = .json;
|
||||
@@ -214,12 +214,12 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
try std.json.stringify(output.items, .{ .whitespace = .indent_2 }, std.io.getStdOut().writer());
|
||||
std.os.exit(0);
|
||||
std.posix.exit(0);
|
||||
}
|
||||
|
||||
if (out == .text and failures > 0) {
|
||||
std.debug.print("{d}/{d} tests suites failures\n", .{ failures, run });
|
||||
std.os.exit(1);
|
||||
std.posix.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -265,8 +265,8 @@ pub const Tag = enum(u8) {
|
||||
pub fn all() []Tag {
|
||||
comptime {
|
||||
const info = @typeInfo(Tag).Enum;
|
||||
comptime var l: [info.fields.len]Tag = undefined;
|
||||
inline for (info.fields, 0..) |field, i| {
|
||||
var l: [info.fields.len]Tag = undefined;
|
||||
for (info.fields, 0..) |field, i| {
|
||||
l[i] = @as(Tag, @enumFromInt(field.value));
|
||||
}
|
||||
return &l;
|
||||
@@ -277,7 +277,7 @@ pub const Tag = enum(u8) {
|
||||
comptime {
|
||||
const tags = all();
|
||||
var names: [tags.len][]const u8 = undefined;
|
||||
inline for (tags, 0..) |tag, i| {
|
||||
for (tags, 0..) |tag, i| {
|
||||
names[i] = tag.elementName();
|
||||
}
|
||||
return &names;
|
||||
|
||||
Reference in New Issue
Block a user