srctree

Gregory Mullen parent e2ba59d1 489f6b4b
update to zig v0.14.0-dev

build.zig added: 73, removed: 75, total 0
@@ -153,7 +153,7 @@ pub const Compiler = struct {
.root_source_file = .{
.cwd_relative = self.b.pathJoin(&.{ local_dir, "src/template/struct-emit.zig" }),
},
.target = self.b.host,
.target = self.b.graph.host,
});
 
const comptime_templates = try self.buildTemplates();
 
src/antibiotic.zig added: 73, removed: 75, total 0
@@ -75,7 +75,8 @@ pub fn cleanHtml(in: u8, out: ?[]u8) Error!usize {
else => &same,
};
 
if (comptime out) |o| {
// I would like the null check to be comptime, but happy to defer that for now
if (out) |o| {
if (replace.len > o.len) return error.NoSpaceLeft;
@memcpy(o[0..replace.len], replace);
}
@@ -117,7 +118,8 @@ pub fn cleanPath(in: u8, out: ?[]u8) Error!usize {
else => "",
};
 
if (comptime out) |o| {
// I would like the null check to be comptime, but happy to defer that for now
if (out) |o| {
if (replace.len > o.len) return error.NoSpaceLeft;
@memcpy(o[0..replace.len], replace);
}
@@ -133,7 +135,8 @@ pub fn cleanFilename(in: u8, out: ?[]u8) Error!usize {
else => return cleanPath(in, out),
};
 
if (comptime out) |o| {
// I would like the null check to be comptime, but happy to defer that for now
if (out) |o| {
if (replace.len > o.len) return error.NoSpaceLeft;
@memcpy(o[0..replace.len], replace);
}
 
src/auth/provider.zig added: 73, removed: 75, total 0
@@ -21,7 +21,7 @@ pub const VTable = struct {
pub const CreateSessionFn = *const fn (*anyopaque, *User) Error!void;
pub const GetCookieFn = *const fn (*anyopaque, User) Error!?RequestCookie;
 
pub const Empty = .{
pub const Empty: VTable = .{
.authenticate = null,
.lookup_user = null,
.valid = null,
 
src/content-type.zig added: 73, removed: 75, total 0
@@ -100,7 +100,7 @@ pub const MultiPart = union(enum) {
@"form-data": FormData,
 
pub fn fromStr(str: []const u8) !MultiPart {
inline for (@typeInfo(MultiPart).Union.fields) |f| {
inline for (@typeInfo(MultiPart).@"union".fields) |f| {
if (startsWith(u8, str, f.name)) {
return try f.type.fromStr(str);
}
 
src/endpoint.zig added: 73, removed: 75, total 0
@@ -11,7 +11,7 @@ pub const Options = Server.Options;
/// for verse to construct a valid server route.
/// TODO enumerate minimal example
pub fn Endpoints(endpoints: anytype) type {
if (@typeInfo(@TypeOf(endpoints)).Struct.is_tuple == false) return error.InvalidEndpointTypes;
if (@typeInfo(@TypeOf(endpoints)).@"struct".is_tuple == false) return error.InvalidEndpointTypes;
inline for (endpoints) |ep| {
validateEndpoint(ep);
}
@@ -96,7 +96,7 @@ fn routeCount(endpoints: anytype) usize {
if (@hasDecl(ep, "verse_router")) {
count += 1;
} else {
if (@hasDecl(ep, "index") and @typeInfo(@TypeOf(ep.index)) == .Fn) {
if (@hasDecl(ep, "index") and @typeInfo(@TypeOf(ep.index)) == .@"fn") {
count += 1;
}
 
 
src/request-data.zig added: 73, removed: 75, total 0
@@ -191,11 +191,12 @@ pub fn RequestData(comptime T: type) type {
var query_valid = data.query.validator();
var mpost_valid = if (data.post) |post| post.validator() else null;
var req: T = undefined;
inline for (@typeInfo(T).Struct.fields) |field| {
inline for (@typeInfo(T).@"struct".fields) |field| {
if (mpost_valid) |*post_valid| {
@field(req, field.name) = get(field.type, field.name, post_valid, field.default_value) catch try get(field.type, field.name, &query_valid, field.default_value);
@field(req, field.name) = get(field.type, field.name, post_valid, field.defaultValue()) catch
try get(field.type, field.name, &query_valid, field.defaultValue());
} else {
@field(req, field.name) = try get(field.type, field.name, &query_valid, field.default_value);
@field(req, field.name) = try get(field.type, field.name, &query_valid, field.defaultValue());
}
}
return req;
@@ -208,20 +209,17 @@ pub fn RequestData(comptime T: type) type {
return error.NotImplemented;
}
 
fn get(FieldType: type, comptime name: []const u8, valid: anytype, default: ?*const anyopaque) !FieldType {
return switch (@typeInfo(FieldType)) {
.Optional => |opt| get(opt.child, name, valid, default) catch |err| switch (err) {
error.DataMissing => if (default != null)
@as(*const FieldType, @alignCast(@ptrCast(default.?))).*
else
return null,
fn get(FT: type, comptime name: []const u8, valid: anytype, default: ?FT) !FT {
return switch (@typeInfo(FT)) {
.optional => |opt| get(opt.child, name, valid, null) catch |err| switch (err) {
error.DataMissing => if (default) |d| d else return null,
else => return err,
},
.Bool => valid.optional(bool, name) orelse return error.DataMissing,
.Int => try parseInt(FieldType, (try valid.require(name)).value, 10),
.Float => try parseFloat(FieldType, (try valid.require(name)).value),
.Enum => return stringToEnum(FieldType, (try valid.require(name)).value) orelse error.InvalidEnumMember,
.Pointer => (try valid.require(name)).value,
.bool => valid.optional(bool, name) orelse return error.DataMissing,
.int => try parseInt(FT, (try valid.require(name)).value, 10),
.float => try parseFloat(FT, (try valid.require(name)).value),
.@"enum" => return stringToEnum(FT, (try valid.require(name)).value) orelse error.InvalidEnumMember,
.pointer => (try valid.require(name)).value,
else => comptime unreachable, // Not yet implemented
};
}
@@ -240,7 +238,7 @@ pub fn RequestData(comptime T: type) type {
 
var req: T = undefined;
inline for (std.meta.fields(T)) |field| {
@field(req, field.name) = try get(field.type, field.name, &valid, field.default_value);
@field(req, field.name) = try get(field.type, field.name, &valid, field.defaultValue());
}
return req;
}
@@ -251,8 +249,8 @@ pub fn RequestData(comptime T: type) type {
var req: T = undefined;
inline for (std.meta.fields(T)) |field| {
@field(req, field.name) = switch (@typeInfo(field.type)) {
.Optional => if (valid.optionalItem(field.name)) |o| o.value else null,
.Pointer => |fptr| switch (fptr.child) {
.optional => if (valid.optionalItem(field.name)) |o| o.value else null,
.pointer => |fptr| switch (fptr.child) {
u8 => (try valid.require(field.name)).value,
[]const u8 => arr: {
const count = valid.count(field.name);
 
src/request.zig added: 73, removed: 75, total 0
@@ -48,7 +48,7 @@ pub const Encoding = packed struct(usize) {
 
pub fn fromStr(str: []const u8) Encoding {
var e = Encoding.default;
inline for (@typeInfo(Encoding).Struct.fields) |f| {
inline for (@typeInfo(Encoding).@"struct".fields) |f| {
if (indexOf(u8, str, f.name)) |_| {
@field(e, f.name) = if (f.type == bool) true else 0;
}
 
src/router.zig added: 73, removed: 75, total 0
@@ -121,15 +121,15 @@ pub fn ROUTE(comptime name: []const u8, comptime match: anytype) Match {
 
fn buildTarget(comptime match: anytype) Target {
return switch (@typeInfo(@TypeOf(match))) {
.Pointer => |ptr| switch (@typeInfo(ptr.child)) {
.Fn => |fnc| switch (fnc.return_type orelse null) {
.pointer => |ptr| switch (@typeInfo(ptr.child)) {
.@"fn" => |fnc| switch (fnc.return_type orelse null) {
Error!void => .{ .build = match },
RoutingError!BuildFn => .{ .route = match },
else => @compileError("unknown function return type" ++ @typeName(ptr.child)),
},
else => .{ .simple = match },
},
.Fn => |fnc| switch (fnc.return_type orelse null) {
.@"fn" => |fnc| switch (fnc.return_type orelse null) {
Error!void => .{ .build = match },
RoutingError!BuildFn => .{ .route = match },
else => @compileError("unknown function return type"),
 
src/template/directive.zig added: 73, removed: 75, total 0
@@ -296,11 +296,11 @@ pub fn doTyped(self: Directive, T: type, ctx: anytype, out: anytype) anyerror!vo
var local: [0xff]u8 = undefined;
const realname = local[0..makeFieldName(self.noun, &local)];
switch (@typeInfo(T)) {
.Struct => {
.@"struct" => {
inline for (std.meta.fields(T)) |field| {
if (comptime isStringish(field.type)) continue;
switch (@typeInfo(field.type)) {
.Pointer => {
.pointer => {
if (eql(u8, field.name, realname)) {
const child = @field(ctx, field.name);
for (child) |each| {
@@ -319,7 +319,7 @@ pub fn doTyped(self: Directive, T: type, ctx: anytype, out: anytype) anyerror!vo
}
}
},
.Optional => {
.optional => {
if (eql(u8, field.name, realname)) {
//@compileLog("optional for {s}\n", field.name, field.type, T);
const child = @field(ctx, field.name);
@@ -331,14 +331,14 @@ pub fn doTyped(self: Directive, T: type, ctx: anytype, out: anytype) anyerror!vo
}
}
},
.Struct => {
.@"struct" => {
if (eql(u8, field.name, realname)) {
const child = @field(ctx, field.name);
std.debug.assert(self.verb == .build);
try self.withTyped(@TypeOf(child), child, out);
}
},
.Int => |int| {
.int => |int| {
if (eql(u8, field.name, realname)) {
std.debug.assert(int.bits == 64);
try std.fmt.formatInt(@field(ctx, field.name), 10, .lower, .{}, out);
@@ -348,7 +348,7 @@ pub fn doTyped(self: Directive, T: type, ctx: anytype, out: anytype) anyerror!vo
}
}
},
.Int => {
.int => {
//std.debug.assert(int.bits == 64);
try std.fmt.formatInt(ctx, 10, .lower, .{}, out);
},
@@ -404,7 +404,7 @@ fn getBuiltin(name: []const u8) ?Template {
}
 
fn typeField(T: type, name: []const u8, data: T) ?[]const u8 {
if (@typeInfo(T) != .Struct) return null;
if (@typeInfo(T) != .@"struct") return null;
var local: [0xff]u8 = undefined;
const realname = local[0..makeFieldName(name, &local)];
inline for (std.meta.fields(T)) |field| {
@@ -444,10 +444,10 @@ pub fn formatTyped(d: Directive, comptime T: type, ctx: T, out: anytype) !void {
.delete => {},
.template => |template| {
if (T == usize) unreachable;
if (@typeInfo(T) != .Struct) unreachable;
if (@typeInfo(T) != .@"struct") unreachable;
inline for (std.meta.fields(T)) |field| {
switch (@typeInfo(field.type)) {
.Optional => |otype| {
.optional => |otype| {
if (otype.child == []const u8) continue;
 
var local: [0xff]u8 = undefined;
@@ -462,7 +462,7 @@ pub fn formatTyped(d: Directive, comptime T: type, ctx: T, out: anytype) !void {
);
}
},
.Struct => {
.@"struct" => {
if (std.mem.eql(u8, field.name, noun)) {
const subdata = @field(ctx, field.name);
var subpage = template.pageOf(@TypeOf(subdata), subdata);
 
src/template/page.zig added: 73, removed: 75, total 0
@@ -92,7 +92,7 @@ pub fn PageRuntime(comptime PageDataType: type) type {
 
fn getOffset(T: type, name: []const u8, base: usize) usize {
switch (@typeInfo(T)) {
.Struct => {
.@"struct" => {
var local: [0xff]u8 = undefined;
const end = makeFieldName(name, &local);
const field = local[0..end];
@@ -156,10 +156,10 @@ fn baseType(T: type, name: []const u8) type {
?[]const u8 => unreachable,
?usize => unreachable,
else => switch (@typeInfo(f.type)) {
.Pointer => |ptr| return ptr.child,
.Optional => |opt| return opt.child,
.Struct => return f.type,
.Int => return f.type,
.pointer => |ptr| return ptr.child,
.optional => |opt| return opt.child,
.@"struct" => return f.type,
.int => return f.type,
else => @compileError("Unexpected kind " ++ f.name),
},
}
@@ -450,14 +450,14 @@ pub fn Page(comptime template: Template, comptime PageDataType: type) type {
skip = t.len;
},
.array => |array| switch (@typeInfo(array.kind)) {
.Pointer => {
.pointer => {
const child_data: array.kind = dos.getData(array.kind, data).*;
for (child_data) |cd| {
count += iovecCount(ofs[idx..][0..array.len], @ptrCast(&cd));
}
skip = array.len;
},
.Optional => {
.optional => {
const child_data = dos.getData(array.kind, data).*;
if (child_data) |cd| {
count += iovecCount(ofs[idx..][0..array.len], @ptrCast(&cd));
@@ -498,8 +498,8 @@ pub fn Page(comptime template: Template, comptime PageDataType: type) type {
fn offsetOptionalItem(T: type, item: ?T, comptime ofs: []const Offset, html: []const u8, out: anytype) !void {
if (comptime T == ?[]const u8) return offsetDirective(T, item.?, ofs[0], out);
switch (@typeInfo(T)) {
.Int => std.debug.print("skipped int\n", .{}),
.Struct => if (item) |itm| try formatDirective(T, itm, ofs, html, out),
.int => std.debug.print("skipped int\n", .{}),
.@"struct" => if (item) |itm| try formatDirective(T, itm, ofs, html, out),
else => comptime unreachable,
}
}
@@ -519,11 +519,11 @@ pub fn Page(comptime template: Template, comptime PageDataType: type) type {
}
},
else => switch (@typeInfo(T)) {
.Pointer => |ptr| {
std.debug.assert(ptr.size == .Slice);
.pointer => |ptr| {
std.debug.assert(ptr.size == .slice);
for (data) |each| try formatDirective(ptr.child, each, ofs, html, out);
},
.Optional => |opt| {
.optional => |opt| {
if (opt.child == []const u8) unreachable;
try offsetOptionalItem(opt.child, data, ofs, html, out);
},
@@ -622,15 +622,15 @@ pub fn Page(comptime template: Template, comptime PageDataType: type) type {
}
},
else => switch (@typeInfo(T)) {
.Pointer => |ptr| {
std.debug.assert(ptr.size == .Slice);
.pointer => |ptr| {
std.debug.assert(ptr.size == .slice);
for (data) |each| idx += try ioVecCore(ptr.child, each, ofs, vec[idx..], a);
},
.Optional => |opt| {
.optional => |opt| {
if (opt.child == []const u8) unreachable;
switch (@typeInfo(opt.child)) {
.Int => std.debug.print("skipped int\n", .{}),
.Struct => {
.int => std.debug.print("skipped int\n", .{}),
.@"struct" => {
if (data) |d| return try ioVecCore(opt.child, d, ofs, vec, a);
},
else => unreachable,
@@ -738,7 +738,7 @@ test Page {
 
const makeFieldName = @import("builtins.zig").makeFieldName;
fn typeField(T: type, name: []const u8, data: T) ?[]const u8 {
if (@typeInfo(T) != .Struct) return null;
if (@typeInfo(T) != .@"struct") return null;
var local: [0xff]u8 = undefined;
const realname = local[0..makeFieldName(name, &local)];
inline for (std.meta.fields(T)) |field| {
 
src/zwsgi.zig added: 73, removed: 75, total 0
@@ -48,10 +48,7 @@ pub fn serve(z: *zWSGI) !void {
@panic("Cleanup failed");
};
 
signalListen(SIG.INT) catch {
log.err("Unable to install sigint handler", .{});
return error.Unexpected;
};
signalListen(SIG.INT);
 
const uaddr = try std.net.Address.initUnix(z.unix_file);
var server = try uaddr.listen(.{});
@@ -113,8 +110,8 @@ export fn sig_cb(sig: c_int, _: *const siginfo_t, _: ?*const anyopaque) callconv
}
}
 
fn signalListen(signal: u6) !void {
try std.posix.sigaction(signal, &std.posix.Sigaction{
fn signalListen(signal: u6) void {
std.posix.sigaction(signal, &std.posix.Sigaction{
.handler = .{ .sigaction = sig_cb },
.mask = std.posix.empty_sigset,
.flags = SA.SIGINFO,