diff options
author | 2023-07-11 19:14:34 -0700 | |
---|---|---|
committer | 2023-07-11 19:14:34 -0700 | |
commit | cbb88672f217a90db1aa1eb29cd92d5d9035b22b (patch) | |
tree | 43a00501f3cde495967e116f0b660777051551f8 /src/deps | |
parent | 1f900cff453700b19bca2acadfe26da4468c1282 (diff) | |
parent | 34b0e7a2bbd8bf8097341cdb0075d0908283e834 (diff) | |
download | bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.gz bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.tar.zst bun-cbb88672f217a90db1aa1eb29cd92d5d9035b22b.zip |
Merge branch 'main' into jarred/esm-conditionsjarred/esm-conditions
Diffstat (limited to 'src/deps')
m--------- | src/deps/base64 | 0 | ||||
-rw-r--r-- | src/deps/boringssl.translated.zig | 20 | ||||
-rw-r--r-- | src/deps/c_ares.zig | 15 | ||||
-rw-r--r-- | src/deps/diffz/DiffMatchPatch.zig | 16 | ||||
m--------- | src/deps/lol-html | 0 | ||||
-rw-r--r-- | src/deps/lol-html.zig | 35 | ||||
-rw-r--r-- | src/deps/picohttp.zig | 4 | ||||
m--------- | src/deps/uws | 0 | ||||
-rw-r--r-- | src/deps/uws.zig | 319 | ||||
-rw-r--r-- | src/deps/zig-clap/clap.zig | 2 | ||||
-rw-r--r-- | src/deps/zig-datetime/src/datetime.zig | 26 |
11 files changed, 360 insertions, 77 deletions
diff --git a/src/deps/base64 b/src/deps/base64 new file mode 160000 +Subproject e77bd70bdd860c52c561568cffb251d88bba064 diff --git a/src/deps/boringssl.translated.zig b/src/deps/boringssl.translated.zig index 32fdb704b..ee4f76260 100644 --- a/src/deps/boringssl.translated.zig +++ b/src/deps/boringssl.translated.zig @@ -887,8 +887,8 @@ pub fn sk_OPENSSL_STRING_call_cmp_func(arg_cmp_func: stack_cmp_func, arg_a: [*c] var cmp_func = arg_cmp_func; var a = arg_a; var b = arg_b; - const a_ptr: OPENSSL_STRING = @intToPtr(OPENSSL_STRING, @ptrToInt(a.*)); - const b_ptr: OPENSSL_STRING = @intToPtr(OPENSSL_STRING, @ptrToInt(b.*)); + const a_ptr: OPENSSL_STRING = @ptrFromInt(OPENSSL_STRING, @intFromPtr(a.*)); + const b_ptr: OPENSSL_STRING = @ptrFromInt(OPENSSL_STRING, @intFromPtr(b.*)); return @ptrCast(stack_OPENSSL_STRING_cmp_func, @alignCast(@import("std").meta.alignment(fn ([*c]const OPENSSL_STRING, [*c]const OPENSSL_STRING) callconv(.C) c_int), cmp_func)).?(&a_ptr, &b_ptr); } pub fn sk_OPENSSL_STRING_new(arg_comp: stack_OPENSSL_STRING_cmp_func) callconv(.C) ?*struct_stack_st_OPENSSL_STRING { @@ -5237,7 +5237,7 @@ pub fn sk_SSL_CIPHER_call_free_func(arg_free_func: stack_free_func, arg_ptr: ?*a pub fn sk_SSL_CIPHER_call_copy_func(arg_copy_func: stack_copy_func, arg_ptr: ?*anyopaque) callconv(.C) ?*anyopaque { var copy_func = arg_copy_func; var ptr = arg_ptr; - return @intToPtr(?*anyopaque, @ptrToInt(@ptrCast(stack_SSL_CIPHER_copy_func, @alignCast(@import("std").meta.alignment(fn (?*const SSL_CIPHER) callconv(.C) ?*const SSL_CIPHER), copy_func)).?(@ptrCast(?*const SSL_CIPHER, ptr)))); + return @ptrFromInt(?*anyopaque, @intFromPtr(@ptrCast(stack_SSL_CIPHER_copy_func, @alignCast(@import("std").meta.alignment(fn (?*const SSL_CIPHER) callconv(.C) ?*const SSL_CIPHER), copy_func)).?(@ptrCast(?*const SSL_CIPHER, ptr)))); } pub fn sk_SSL_CIPHER_call_cmp_func(arg_cmp_func: stack_cmp_func, arg_a: [*c]?*const anyopaque, arg_b: [*c]?*const anyopaque) callconv(.C) c_int { var cmp_func = arg_cmp_func; @@ -5271,7 +5271,7 @@ pub fn sk_SSL_CIPHER_set(arg_sk: ?*struct_stack_st_SSL_CIPHER, arg_i: usize, arg var sk = arg_sk; var i = arg_i; var p = arg_p; - return @ptrCast(?*const SSL_CIPHER, sk_set(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), i, @intToPtr(?*anyopaque, @ptrToInt(p)))); + return @ptrCast(?*const SSL_CIPHER, sk_set(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), i, @ptrFromInt(?*anyopaque, @intFromPtr(p)))); } pub fn sk_SSL_CIPHER_free(arg_sk: ?*struct_stack_st_SSL_CIPHER) callconv(.C) void { var sk = arg_sk; @@ -5286,7 +5286,7 @@ pub fn sk_SSL_CIPHER_insert(arg_sk: ?*struct_stack_st_SSL_CIPHER, arg_p: ?*const var sk = arg_sk; var p = arg_p; var where = arg_where; - return sk_insert(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @intToPtr(?*anyopaque, @ptrToInt(p)), where); + return sk_insert(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @ptrFromInt(?*anyopaque, @intFromPtr(p)), where); } pub fn sk_SSL_CIPHER_delete(arg_sk: ?*struct_stack_st_SSL_CIPHER, arg_where: usize) callconv(.C) ?*const SSL_CIPHER { var sk = arg_sk; @@ -5311,7 +5311,7 @@ pub fn sk_SSL_CIPHER_shift(arg_sk: ?*struct_stack_st_SSL_CIPHER) callconv(.C) ?* pub fn sk_SSL_CIPHER_push(arg_sk: ?*struct_stack_st_SSL_CIPHER, arg_p: ?*const SSL_CIPHER) callconv(.C) usize { var sk = arg_sk; var p = arg_p; - return sk_push(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @intToPtr(?*anyopaque, @ptrToInt(p))); + return sk_push(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @ptrFromInt(?*anyopaque, @intFromPtr(p))); } pub fn sk_SSL_CIPHER_pop(arg_sk: ?*struct_stack_st_SSL_CIPHER) callconv(.C) ?*const SSL_CIPHER { var sk = arg_sk; @@ -5545,7 +5545,7 @@ pub fn sk_SRTP_PROTECTION_PROFILE_call_free_func(arg_free_func: stack_free_func, pub fn sk_SRTP_PROTECTION_PROFILE_call_copy_func(arg_copy_func: stack_copy_func, arg_ptr: ?*anyopaque) callconv(.C) ?*anyopaque { var copy_func = arg_copy_func; var ptr = arg_ptr; - return @intToPtr(?*anyopaque, @ptrToInt(@ptrCast(stack_SRTP_PROTECTION_PROFILE_copy_func, @alignCast(@import("std").meta.alignment(fn ([*c]const SRTP_PROTECTION_PROFILE) callconv(.C) [*c]const SRTP_PROTECTION_PROFILE), copy_func)).?(@ptrCast([*c]const SRTP_PROTECTION_PROFILE, @alignCast(@import("std").meta.alignment(SRTP_PROTECTION_PROFILE), ptr))))); + return @ptrFromInt(?*anyopaque, @intFromPtr(@ptrCast(stack_SRTP_PROTECTION_PROFILE_copy_func, @alignCast(@import("std").meta.alignment(fn ([*c]const SRTP_PROTECTION_PROFILE) callconv(.C) [*c]const SRTP_PROTECTION_PROFILE), copy_func)).?(@ptrCast([*c]const SRTP_PROTECTION_PROFILE, @alignCast(@import("std").meta.alignment(SRTP_PROTECTION_PROFILE), ptr))))); } pub fn sk_SRTP_PROTECTION_PROFILE_call_cmp_func(arg_cmp_func: stack_cmp_func, arg_a: [*c]?*const anyopaque, arg_b: [*c]?*const anyopaque) callconv(.C) c_int { var cmp_func = arg_cmp_func; @@ -5579,7 +5579,7 @@ pub fn sk_SRTP_PROTECTION_PROFILE_set(arg_sk: ?*struct_stack_st_SRTP_PROTECTION_ var sk = arg_sk; var i = arg_i; var p = arg_p; - return @ptrCast([*c]const SRTP_PROTECTION_PROFILE, @alignCast(@import("std").meta.alignment(SRTP_PROTECTION_PROFILE), sk_set(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), i, @intToPtr(?*anyopaque, @ptrToInt(p))))); + return @ptrCast([*c]const SRTP_PROTECTION_PROFILE, @alignCast(@import("std").meta.alignment(SRTP_PROTECTION_PROFILE), sk_set(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), i, @ptrFromInt(?*anyopaque, @intFromPtr(p))))); } pub fn sk_SRTP_PROTECTION_PROFILE_free(arg_sk: ?*struct_stack_st_SRTP_PROTECTION_PROFILE) callconv(.C) void { var sk = arg_sk; @@ -5594,7 +5594,7 @@ pub fn sk_SRTP_PROTECTION_PROFILE_insert(arg_sk: ?*struct_stack_st_SRTP_PROTECTI var sk = arg_sk; var p = arg_p; var where = arg_where; - return sk_insert(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @intToPtr(?*anyopaque, @ptrToInt(p)), where); + return sk_insert(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @ptrFromInt(?*anyopaque, @intFromPtr(p)), where); } pub fn sk_SRTP_PROTECTION_PROFILE_delete(arg_sk: ?*struct_stack_st_SRTP_PROTECTION_PROFILE, arg_where: usize) callconv(.C) [*c]const SRTP_PROTECTION_PROFILE { var sk = arg_sk; @@ -5619,7 +5619,7 @@ pub fn sk_SRTP_PROTECTION_PROFILE_shift(arg_sk: ?*struct_stack_st_SRTP_PROTECTIO pub fn sk_SRTP_PROTECTION_PROFILE_push(arg_sk: ?*struct_stack_st_SRTP_PROTECTION_PROFILE, arg_p: [*c]const SRTP_PROTECTION_PROFILE) callconv(.C) usize { var sk = arg_sk; var p = arg_p; - return sk_push(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @intToPtr(?*anyopaque, @ptrToInt(p))); + return sk_push(@ptrCast([*c]_STACK, @alignCast(@import("std").meta.alignment(_STACK), sk)), @ptrFromInt(?*anyopaque, @intFromPtr(p))); } pub fn sk_SRTP_PROTECTION_PROFILE_pop(arg_sk: ?*struct_stack_st_SRTP_PROTECTION_PROFILE) callconv(.C) [*c]const SRTP_PROTECTION_PROFILE { var sk = arg_sk; diff --git a/src/deps/c_ares.zig b/src/deps/c_ares.zig index 4539358d0..7813ff5e4 100644 --- a/src/deps/c_ares.zig +++ b/src/deps/c_ares.zig @@ -488,7 +488,7 @@ pub const Channel = opaque { break :brk null; } const len = @min(host.len, host_buf.len - 1); - @memcpy(&host_buf, host.ptr, len); + @memcpy(host_buf[0..len], host[0..len]); host_buf[len] = 0; break :brk host_buf[0..len :0].ptr; }; @@ -515,8 +515,9 @@ pub const Channel = opaque { if (name.len == 0 or name.len >= 1023) { break :brk null; } - const len = @min(name_buf.len, name_buf.len - 1); - @memcpy(&name_buf, name.ptr, len); + const len = @min(name.len, name_buf.len - 1); + @memcpy(name_buf[0..len], name[0..len]); + name_buf[len] = 0; break :brk name_buf[0..len :0]; }; @@ -1209,8 +1210,8 @@ pub const Error = enum(i32) { ESERVICE = ARES_ESERVICE, pub fn initEAI(rc: i32) ?Error { - return switch (@intToEnum(std.os.system.EAI, rc)) { - @intToEnum(std.os.system.EAI, 0) => return null, + return switch (@enumFromInt(std.os.system.EAI, rc)) { + @enumFromInt(std.os.system.EAI, 0) => return null, .ADDRFAMILY => Error.EBADFAMILY, .BADFLAGS => Error.EBADFLAGS, // Invalid hints .FAIL => Error.EBADRESP, @@ -1283,8 +1284,8 @@ pub const Error = enum(i32) { pub fn get(rc: i32) ?Error { return switch (rc) { 0 => null, - 1...ARES_ESERVICE => @intToEnum(Error, rc), - -ARES_ESERVICE...-1 => @intToEnum(Error, -rc), + 1...ARES_ESERVICE => @enumFromInt(Error, rc), + -ARES_ESERVICE...-1 => @enumFromInt(Error, -rc), else => unreachable, }; } diff --git a/src/deps/diffz/DiffMatchPatch.zig b/src/deps/diffz/DiffMatchPatch.zig index 7e545f364..a5cc02af4 100644 --- a/src/deps/diffz/DiffMatchPatch.zig +++ b/src/deps/diffz/DiffMatchPatch.zig @@ -178,7 +178,7 @@ fn diffInternal( } fn diffCommonPrefix(before: []const u8, after: []const u8) usize { - const n = std.math.min(before.len, after.len); + const n = @min(before.len, after.len); var i: usize = 0; while (i < n) : (i += 1) { @@ -191,7 +191,7 @@ fn diffCommonPrefix(before: []const u8, after: []const u8) usize { } fn diffCommonSuffix(before: []const u8, after: []const u8) usize { - const n = std.math.min(before.len, after.len); + const n = @min(before.len, after.len); var i: usize = 1; while (i <= n) : (i += 1) { @@ -996,8 +996,8 @@ fn diffCleanupSemantic(allocator: std.mem.Allocator, diffs: *DiffList) DiffError // Eliminate an equality that is smaller or equal to the edits on both // sides of it. if (last_equality != null and - (last_equality.?.len <= std.math.max(length_insertions1, length_deletions1)) and - (last_equality.?.len <= std.math.max(length_insertions2, length_deletions2))) + (last_equality.?.len <= @max(length_insertions1, length_deletions1)) and + (last_equality.?.len <= @max(length_insertions2, length_deletions2))) { // Duplicate record. try diffs.insert( @@ -1046,8 +1046,8 @@ fn diffCleanupSemantic(allocator: std.mem.Allocator, diffs: *DiffList) DiffError var overlap_length1: usize = diffCommonOverlap(deletion, insertion); var overlap_length2: usize = diffCommonOverlap(insertion, deletion); if (overlap_length1 >= overlap_length2) { - if (@intToFloat(f32, overlap_length1) >= @intToFloat(f32, deletion.len) / 2.0 or - @intToFloat(f32, overlap_length1) >= @intToFloat(f32, insertion.len) / 2.0) + if (@floatFromInt(f32, overlap_length1) >= @floatFromInt(f32, deletion.len) / 2.0 or + @floatFromInt(f32, overlap_length1) >= @floatFromInt(f32, insertion.len) / 2.0) { // Overlap found. // Insert an equality and trim the surrounding edits. @@ -1063,8 +1063,8 @@ fn diffCleanupSemantic(allocator: std.mem.Allocator, diffs: *DiffList) DiffError pointer += 1; } } else { - if (@intToFloat(f32, overlap_length2) >= @intToFloat(f32, deletion.len) / 2.0 or - @intToFloat(f32, overlap_length2) >= @intToFloat(f32, insertion.len) / 2.0) + if (@floatFromInt(f32, overlap_length2) >= @floatFromInt(f32, deletion.len) / 2.0 or + @floatFromInt(f32, overlap_length2) >= @floatFromInt(f32, insertion.len) / 2.0) { // Reverse overlap found. // Insert an equality and swap and trim the surrounding edits. diff --git a/src/deps/lol-html b/src/deps/lol-html -Subproject 2eed349dcdfa4ff5c19fe7c6e501cfd68760103 +Subproject 2681dcf0b3e6907111565199df8c43cc9aab7fe diff --git a/src/deps/lol-html.zig b/src/deps/lol-html.zig index 975aac2b3..bac422fb0 100644 --- a/src/deps/lol-html.zig +++ b/src/deps/lol-html.zig @@ -1,6 +1,6 @@ pub const Error = error{Fail}; const std = @import("std"); - +const bun = @import("root").bun; pub const MemorySettings = extern struct { preallocated_parsing_buffer_size: usize, max_allowed_memory_usage: usize, @@ -393,7 +393,8 @@ pub const Element = opaque { extern fn lol_html_element_is_removed(element: *const Element) bool; extern fn lol_html_element_user_data_set(element: *const Element, user_data: ?*anyopaque) void; extern fn lol_html_element_user_data_get(element: *const Element) ?*anyopaque; - extern fn lol_html_element_on_end_tag(element: *Element, end_tag_handler: lol_html_end_tag_handler_t, user_data: ?*anyopaque) c_int; + extern fn lol_html_element_add_end_tag_handler(element: *Element, end_tag_handler: lol_html_end_tag_handler_t, user_data: ?*anyopaque) c_int; + extern fn lol_html_element_clear_end_tag_handlers(element: *Element) void; pub fn getAttribute(element: *const Element, name: []const u8) HTMLString { auto_disable(); @@ -502,7 +503,10 @@ pub const Element = opaque { } pub fn onEndTag(element: *Element, end_tag_handler: lol_html_end_tag_handler_t, user_data: ?*anyopaque) Error!void { auto_disable(); - return switch (lol_html_element_on_end_tag(element, end_tag_handler, user_data)) { + + lol_html_element_clear_end_tag_handlers(element); + + return switch (lol_html_element_add_end_tag_handler(element, end_tag_handler, user_data)) { 0 => {}, -1 => error.Fail, else => unreachable, @@ -559,6 +563,27 @@ pub const HTMLString = extern struct { @setRuntimeSafety(false); return this.ptr[0..this.len]; } + + fn deinit_external(ctx: *anyopaque, ptr: *anyopaque, len: u32) callconv(.C) void { + _ = ctx; + auto_disable(); + lol_html_str_free(.{ .ptr = @ptrCast([*]const u8, ptr), .len = len }); + } + + pub fn toString(this: HTMLString) bun.String { + const bytes = this.slice(); + if (bun.strings.isAllASCII(bytes)) { + return bun.String.createExternal(bytes, true, @constCast(bytes.ptr), &deinit_external); + } + defer this.deinit(); + return bun.String.create(bytes); + } + + pub fn toJS(this: HTMLString, globalThis: *bun.JSC.JSGlobalObject) bun.JSC.JSValue { + var str = this.toString(); + defer str.deref(); + return str.toJS(globalThis); + } }; pub const EndTag = opaque { @@ -727,11 +752,11 @@ pub fn DirectiveHandler(comptime Container: type, comptime UserDataType: type, c return struct { pub fn callback(this: *Container, user_data: ?*anyopaque) callconv(.C) Directive { auto_disable(); - return @intToEnum( + return @enumFromInt( Directive, @as( c_uint, - @boolToInt( + @intFromBool( Callback( @ptrCast( *UserDataType, diff --git a/src/deps/picohttp.zig b/src/deps/picohttp.zig index d18cb7fa0..722475bb5 100644 --- a/src/deps/picohttp.zig +++ b/src/deps/picohttp.zig @@ -15,7 +15,7 @@ pub const Header = struct { value: []const u8, pub fn isMultiline(self: Header) bool { - return @ptrToInt(self.name.ptr) == 0; + return @intFromPtr(self.name.ptr) == 0; } pub fn format(self: Header, comptime _: []const u8, _: fmt.FormatOptions, writer: anytype) !void { @@ -101,7 +101,7 @@ pub const Request = struct { ); // Leave a sentinel value, for JavaScriptCore support. - if (rc > -1) @intToPtr([*]u8, @ptrToInt(path.ptr))[path.len] = 0; + if (rc > -1) @ptrFromInt([*]u8, @intFromPtr(path.ptr))[path.len] = 0; return switch (rc) { -1 => error.BadRequest, diff --git a/src/deps/uws b/src/deps/uws -Subproject d82c4a95de3af01614ecb12bfff821611b4cc6b +Subproject 875948226eede72861a5170212ff6b43c4b7d7f diff --git a/src/deps/uws.zig b/src/deps/uws.zig index 538756b71..83edbe410 100644 --- a/src/deps/uws.zig +++ b/src/deps/uws.zig @@ -23,7 +23,7 @@ fn NativeSocketHandleType(comptime ssl: bool) type { } pub fn NewSocketHandler(comptime ssl: bool) type { return struct { - const ssl_int: i32 = @boolToInt(ssl); + const ssl_int: i32 = @intFromBool(ssl); socket: *Socket, const ThisSocket = @This(); @@ -40,6 +40,120 @@ pub fn NewSocketHandler(comptime ssl: bool) type { return us_socket_timeout(comptime ssl_int, this.socket, seconds); } + pub fn startTLS(this: ThisSocket, is_client: bool) void { + _ = us_socket_open(comptime ssl_int, this.socket, @intFromBool(is_client), null, 0); + } + + // Note: this assumes that the socket is non-TLS and will be adopted and wrapped with a new TLS context + // context ext will not be copied to the new context, new context will contain us_wrapped_socket_context_t on ext + pub fn wrapTLS( + this: ThisSocket, + options: us_bun_socket_context_options_t, + socket_ext_size: i32, + comptime deref: bool, + comptime ContextType: type, + comptime Fields: anytype, + ) ?NewSocketHandler(true) { + const TLSSocket = NewSocketHandler(true); + const SocketHandler = struct { + const alignment = if (ContextType == anyopaque) + @sizeOf(usize) + else + std.meta.alignment(ContextType); + const deref_ = deref; + const ValueType = if (deref) ContextType else *ContextType; + fn getValue(socket: *Socket) ValueType { + if (comptime ContextType == anyopaque) { + return us_socket_ext(1, socket).?; + } + + if (comptime deref_) { + return (TLSSocket{ .socket = socket }).ext(ContextType).?.*; + } + + return (TLSSocket{ .socket = socket }).ext(ContextType).?; + } + + pub fn on_open(socket: *Socket, is_client: i32, _: [*c]u8, _: i32) callconv(.C) ?*Socket { + if (comptime @hasDecl(Fields, "onCreate")) { + if (is_client == 0) { + Fields.onCreate( + TLSSocket{ .socket = socket }, + ); + } + } + Fields.onOpen( + getValue(socket), + TLSSocket{ .socket = socket }, + ); + return socket; + } + pub fn on_close(socket: *Socket, code: i32, reason: ?*anyopaque) callconv(.C) ?*Socket { + Fields.onClose( + getValue(socket), + TLSSocket{ .socket = socket }, + code, + reason, + ); + return socket; + } + pub fn on_data(socket: *Socket, buf: ?[*]u8, len: i32) callconv(.C) ?*Socket { + Fields.onData( + getValue(socket), + TLSSocket{ .socket = socket }, + buf.?[0..@intCast(usize, len)], + ); + return socket; + } + pub fn on_writable(socket: *Socket) callconv(.C) ?*Socket { + Fields.onWritable( + getValue(socket), + TLSSocket{ .socket = socket }, + ); + return socket; + } + pub fn on_timeout(socket: *Socket) callconv(.C) ?*Socket { + Fields.onTimeout( + getValue(socket), + TLSSocket{ .socket = socket }, + ); + return socket; + } + pub fn on_connect_error(socket: *Socket, code: i32) callconv(.C) ?*Socket { + Fields.onConnectError( + getValue(socket), + TLSSocket{ .socket = socket }, + code, + ); + return socket; + } + pub fn on_end(socket: *Socket) callconv(.C) ?*Socket { + Fields.onEnd( + getValue(socket), + TLSSocket{ .socket = socket }, + ); + return socket; + } + pub fn on_handshake(socket: *Socket, success: i32, verify_error: us_bun_verify_error_t, _: ?*anyopaque) callconv(.C) void { + Fields.onHandshake(getValue(socket), TLSSocket{ .socket = socket }, success, verify_error); + } + }; + + var events: us_socket_events_t = .{ + .on_open = SocketHandler.on_open, + .on_close = SocketHandler.on_close, + .on_data = SocketHandler.on_data, + .on_writable = SocketHandler.on_writable, + .on_timeout = SocketHandler.on_timeout, + .on_connect_error = SocketHandler.on_connect_error, + .on_end = SocketHandler.on_end, + .on_handshake = SocketHandler.on_handshake, + }; + + const socket = us_socket_wrap_with_tls(ssl_int, this.socket, options, events, socket_ext_size) orelse return null; + return NewSocketHandler(true).from(socket); + } + pub fn getNativeHandle(this: ThisSocket) *NativeSocketHandleType(ssl) { return @ptrCast(*NativeSocketHandleType(ssl), us_socket_get_native_handle(comptime ssl_int, this.socket).?); } @@ -49,7 +163,7 @@ pub fn NewSocketHandler(comptime ssl: bool) type { @compileError("SSL sockets do not have a file descriptor accessible this way"); } - return @intCast(i32, @ptrToInt(us_socket_get_native_handle(0, this.socket))); + return @intCast(i32, @intFromPtr(us_socket_get_native_handle(0, this.socket))); } pub fn markNeedsMoreForSendfile(this: ThisSocket) void { @@ -92,18 +206,29 @@ pub fn NewSocketHandler(comptime ssl: bool) type { data.ptr, // truncate to 31 bits since sign bit exists @intCast(i32, @truncate(u31, data.len)), - @as(i32, @boolToInt(msg_more)), + @as(i32, @intFromBool(msg_more)), + ); + } + + pub fn rawWrite(this: ThisSocket, data: []const u8, msg_more: bool) i32 { + return us_socket_raw_write( + comptime ssl_int, + this.socket, + data.ptr, + // truncate to 31 bits since sign bit exists + @intCast(i32, @truncate(u31, data.len)), + @as(i32, @intFromBool(msg_more)), ); } pub fn shutdown(this: ThisSocket) void { - debug("us_socket_shutdown({d})", .{@ptrToInt(this.socket)}); + debug("us_socket_shutdown({d})", .{@intFromPtr(this.socket)}); return us_socket_shutdown( comptime ssl_int, this.socket, ); } pub fn shutdownRead(this: ThisSocket) void { - debug("us_socket_shutdown_read({d})", .{@ptrToInt(this.socket)}); + debug("us_socket_shutdown_read({d})", .{@intFromPtr(this.socket)}); return us_socket_shutdown_read( comptime ssl_int, this.socket, @@ -122,7 +247,7 @@ pub fn NewSocketHandler(comptime ssl: bool) type { ) > 0; } pub fn close(this: ThisSocket, code: i32, reason: ?*anyopaque) void { - debug("us_socket_close({d})", .{@ptrToInt(this.socket)}); + debug("us_socket_close({d})", .{@intFromPtr(this.socket)}); _ = us_socket_close( comptime ssl_int, this.socket, @@ -241,13 +366,126 @@ pub fn NewSocketHandler(comptime ssl: bool) type { return socket_; } + pub fn unsafeConfigure( + ctx: *SocketContext, + comptime ssl_type: bool, + comptime deref: bool, + comptime ContextType: type, + comptime Fields: anytype, + ) void { + const SocketHandlerType = NewSocketHandler(ssl_type); + const ssl_type_int: i32 = @intFromBool(ssl_type); + const Type = comptime if (@TypeOf(Fields) != type) @TypeOf(Fields) else Fields; + + const SocketHandler = struct { + const alignment = if (ContextType == anyopaque) + @sizeOf(usize) + else + std.meta.alignment(ContextType); + const deref_ = deref; + const ValueType = if (deref) ContextType else *ContextType; + fn getValue(socket: *Socket) ValueType { + if (comptime ContextType == anyopaque) { + return us_socket_ext(ssl_type_int, socket).?; + } + + if (comptime deref_) { + return (SocketHandlerType{ .socket = socket }).ext(ContextType).?.*; + } + + return (SocketHandlerType{ .socket = socket }).ext(ContextType).?; + } + + pub fn on_open(socket: *Socket, is_client: i32, _: [*c]u8, _: i32) callconv(.C) ?*Socket { + if (comptime @hasDecl(Fields, "onCreate")) { + if (is_client == 0) { + Fields.onCreate( + SocketHandlerType{ .socket = socket }, + ); + } + } + Fields.onOpen( + getValue(socket), + SocketHandlerType{ .socket = socket }, + ); + return socket; + } + pub fn on_close(socket: *Socket, code: i32, reason: ?*anyopaque) callconv(.C) ?*Socket { + Fields.onClose( + getValue(socket), + SocketHandlerType{ .socket = socket }, + code, + reason, + ); + return socket; + } + pub fn on_data(socket: *Socket, buf: ?[*]u8, len: i32) callconv(.C) ?*Socket { + Fields.onData( + getValue(socket), + SocketHandlerType{ .socket = socket }, + buf.?[0..@intCast(usize, len)], + ); + return socket; + } + pub fn on_writable(socket: *Socket) callconv(.C) ?*Socket { + Fields.onWritable( + getValue(socket), + SocketHandlerType{ .socket = socket }, + ); + return socket; + } + pub fn on_timeout(socket: *Socket) callconv(.C) ?*Socket { + Fields.onTimeout( + getValue(socket), + SocketHandlerType{ .socket = socket }, + ); + return socket; + } + pub fn on_connect_error(socket: *Socket, code: i32) callconv(.C) ?*Socket { + Fields.onConnectError( + getValue(socket), + SocketHandlerType{ .socket = socket }, + code, + ); + return socket; + } + pub fn on_end(socket: *Socket) callconv(.C) ?*Socket { + Fields.onEnd( + getValue(socket), + SocketHandlerType{ .socket = socket }, + ); + return socket; + } + pub fn on_handshake(socket: *Socket, success: i32, verify_error: us_bun_verify_error_t, _: ?*anyopaque) callconv(.C) void { + Fields.onHandshake(getValue(socket), SocketHandlerType{ .socket = socket }, success, verify_error); + } + }; + + if (comptime @hasDecl(Type, "onOpen") and @typeInfo(@TypeOf(Type.onOpen)) != .Null) + us_socket_context_on_open(ssl_int, ctx, SocketHandler.on_open); + if (comptime @hasDecl(Type, "onClose") and @typeInfo(@TypeOf(Type.onClose)) != .Null) + us_socket_context_on_close(ssl_int, ctx, SocketHandler.on_close); + if (comptime @hasDecl(Type, "onData") and @typeInfo(@TypeOf(Type.onData)) != .Null) + us_socket_context_on_data(ssl_int, ctx, SocketHandler.on_data); + if (comptime @hasDecl(Type, "onWritable") and @typeInfo(@TypeOf(Type.onWritable)) != .Null) + us_socket_context_on_writable(ssl_int, ctx, SocketHandler.on_writable); + if (comptime @hasDecl(Type, "onTimeout") and @typeInfo(@TypeOf(Type.onTimeout)) != .Null) + us_socket_context_on_timeout(ssl_int, ctx, SocketHandler.on_timeout); + if (comptime @hasDecl(Type, "onConnectError") and @typeInfo(@TypeOf(Type.onConnectError)) != .Null) + us_socket_context_on_connect_error(ssl_int, ctx, SocketHandler.on_connect_error); + if (comptime @hasDecl(Type, "onEnd") and @typeInfo(@TypeOf(Type.onEnd)) != .Null) + us_socket_context_on_end(ssl_int, ctx, SocketHandler.on_end); + if (comptime @hasDecl(Type, "onHandshake") and @typeInfo(@TypeOf(Type.onHandshake)) != .Null) + us_socket_context_on_handshake(ssl_int, ctx, SocketHandler.on_handshake, null); + } + pub fn configure( ctx: *SocketContext, comptime deref: bool, comptime ContextType: type, comptime Fields: anytype, ) void { - const @"type" = comptime if (@TypeOf(Fields) != type) @TypeOf(Fields) else Fields; + const Type = comptime if (@TypeOf(Fields) != type) @TypeOf(Fields) else Fields; const SocketHandler = struct { const alignment = if (ContextType == anyopaque) @@ -333,21 +571,21 @@ pub fn NewSocketHandler(comptime ssl: bool) type { } }; - if (comptime @hasDecl(@"type", "onOpen") and @typeInfo(@TypeOf(@"type".onOpen)) != .Null) + if (comptime @hasDecl(Type, "onOpen") and @typeInfo(@TypeOf(Type.onOpen)) != .Null) us_socket_context_on_open(ssl_int, ctx, SocketHandler.on_open); - if (comptime @hasDecl(@"type", "onClose") and @typeInfo(@TypeOf(@"type".onClose)) != .Null) + if (comptime @hasDecl(Type, "onClose") and @typeInfo(@TypeOf(Type.onClose)) != .Null) us_socket_context_on_close(ssl_int, ctx, SocketHandler.on_close); - if (comptime @hasDecl(@"type", "onData") and @typeInfo(@TypeOf(@"type".onData)) != .Null) + if (comptime @hasDecl(Type, "onData") and @typeInfo(@TypeOf(Type.onData)) != .Null) us_socket_context_on_data(ssl_int, ctx, SocketHandler.on_data); - if (comptime @hasDecl(@"type", "onWritable") and @typeInfo(@TypeOf(@"type".onWritable)) != .Null) + if (comptime @hasDecl(Type, "onWritable") and @typeInfo(@TypeOf(Type.onWritable)) != .Null) us_socket_context_on_writable(ssl_int, ctx, SocketHandler.on_writable); - if (comptime @hasDecl(@"type", "onTimeout") and @typeInfo(@TypeOf(@"type".onTimeout)) != .Null) + if (comptime @hasDecl(Type, "onTimeout") and @typeInfo(@TypeOf(Type.onTimeout)) != .Null) us_socket_context_on_timeout(ssl_int, ctx, SocketHandler.on_timeout); - if (comptime @hasDecl(@"type", "onConnectError") and @typeInfo(@TypeOf(@"type".onConnectError)) != .Null) + if (comptime @hasDecl(Type, "onConnectError") and @typeInfo(@TypeOf(Type.onConnectError)) != .Null) us_socket_context_on_connect_error(ssl_int, ctx, SocketHandler.on_connect_error); - if (comptime @hasDecl(@"type", "onEnd") and @typeInfo(@TypeOf(@"type".onEnd)) != .Null) + if (comptime @hasDecl(Type, "onEnd") and @typeInfo(@TypeOf(Type.onEnd)) != .Null) us_socket_context_on_end(ssl_int, ctx, SocketHandler.on_end); - if (comptime @hasDecl(@"type", "onHandshake") and @typeInfo(@TypeOf(@"type".onHandshake)) != .Null) + if (comptime @hasDecl(Type, "onHandshake") and @typeInfo(@TypeOf(Type.onHandshake)) != .Null) us_socket_context_on_handshake(ssl_int, ctx, SocketHandler.on_handshake, null); } @@ -421,7 +659,7 @@ pub const Timer = opaque { pub const SocketContext = opaque { pub fn getNativeHandle(this: *SocketContext, comptime ssl: bool) *anyopaque { - return us_socket_context_get_native_handle(comptime @as(i32, @boolToInt(ssl)), this).?; + return us_socket_context_get_native_handle(comptime @as(i32, @intFromBool(ssl)), this).?; } fn _deinit_ssl(this: *SocketContext) void { @@ -446,8 +684,8 @@ pub const SocketContext = opaque { } pub fn close(this: *SocketContext, ssl: bool) void { - debug("us_socket_context_close({d})", .{@ptrToInt(this)}); - us_socket_context_close(@as(i32, @boolToInt(ssl)), this); + debug("us_socket_context_close({d})", .{@intFromPtr(this)}); + us_socket_context_close(@as(i32, @intFromBool(ssl)), this); } pub fn ext(this: *SocketContext, ssl: bool, comptime ContextType: type) ?*ContextType { @@ -457,7 +695,7 @@ pub const SocketContext = opaque { std.meta.alignment(ContextType); var ptr = us_socket_context_ext( - @boolToInt(ssl), + @intFromBool(ssl), this, ) orelse return null; @@ -659,6 +897,20 @@ pub const us_bun_verify_error_t = extern struct { reason: [*c]const u8 = null, }; +pub const us_socket_events_t = extern struct { + on_open: ?*const fn (*Socket, i32, [*c]u8, i32) callconv(.C) ?*Socket = null, + on_data: ?*const fn (*Socket, [*c]u8, i32) callconv(.C) ?*Socket = null, + on_writable: ?*const fn (*Socket) callconv(.C) ?*Socket = null, + on_close: ?*const fn (*Socket, i32, ?*anyopaque) callconv(.C) ?*Socket = null, + + on_timeout: ?*const fn (*Socket) callconv(.C) ?*Socket = null, + on_long_timeout: ?*const fn (*Socket) callconv(.C) ?*Socket = null, + on_end: ?*const fn (*Socket) callconv(.C) ?*Socket = null, + on_connect_error: ?*const fn (*Socket, i32) callconv(.C) ?*Socket = null, + on_handshake: ?*const fn (*Socket, i32, us_bun_verify_error_t, ?*anyopaque) callconv(.C) void = null, +}; + +pub extern fn us_socket_wrap_with_tls(ssl: i32, s: *Socket, options: us_bun_socket_context_options_t, events: us_socket_events_t, socket_ext_size: i32) ?*Socket; extern fn us_socket_verify_error(ssl: i32, context: *Socket) us_bun_verify_error_t; extern fn SocketContextimestamp(ssl: i32, context: ?*SocketContext) c_ushort; pub extern fn us_socket_context_add_server_name(ssl: i32, context: ?*SocketContext, hostname_pattern: [*c]const u8, options: us_socket_context_options_t, ?*anyopaque) void; @@ -700,7 +952,7 @@ pub const Poll = opaque { fallthrough: bool, flags: Flags, ) ?*Poll { - var poll = us_create_poll(loop, @as(i32, @boolToInt(fallthrough)), @sizeOf(Data)); + var poll = us_create_poll(loop, @as(i32, @intFromBool(fallthrough)), @sizeOf(Data)); if (comptime Data != void) { poll.data(Data).* = val; } @@ -777,11 +1029,16 @@ extern fn us_socket_ext(ssl: i32, s: ?*Socket) ?*anyopaque; extern fn us_socket_context(ssl: i32, s: ?*Socket) ?*SocketContext; extern fn us_socket_flush(ssl: i32, s: ?*Socket) void; extern fn us_socket_write(ssl: i32, s: ?*Socket, data: [*c]const u8, length: i32, msg_more: i32) i32; +extern fn us_socket_raw_write(ssl: i32, s: ?*Socket, data: [*c]const u8, length: i32, msg_more: i32) i32; extern fn us_socket_shutdown(ssl: i32, s: ?*Socket) void; extern fn us_socket_shutdown_read(ssl: i32, s: ?*Socket) void; extern fn us_socket_is_shut_down(ssl: i32, s: ?*Socket) i32; extern fn us_socket_is_closed(ssl: i32, s: ?*Socket) i32; extern fn us_socket_close(ssl: i32, s: ?*Socket, code: i32, reason: ?*anyopaque) ?*Socket; +// if a TLS socket calls this, it will start SSL instance and call open event will also do TLS handshake if required +// will have no effect if the socket is closed or is not TLS +extern fn us_socket_open(ssl: i32, s: ?*Socket, is_client: i32, ip: [*c]const u8, ip_length: i32) ?*Socket; + extern fn us_socket_local_port(ssl: i32, s: ?*Socket) i32; extern fn us_socket_remote_address(ssl: i32, s: ?*Socket, buf: [*c]u8, length: [*c]i32) void; pub const uws_app_s = opaque {}; @@ -810,7 +1067,7 @@ pub const AnyWebSocket = union(enum) { } pub fn close(this: AnyWebSocket) void { - const ssl_flag = @boolToInt(this == .ssl); + const ssl_flag = @intFromBool(this == .ssl); return uws_ws_close(ssl_flag, this.raw()); } @@ -874,7 +1131,7 @@ pub const AnyWebSocket = union(enum) { } pub fn publishWithOptions(ssl: bool, app: *anyopaque, topic: []const u8, message: []const u8, opcode: Opcode, compress: bool) bool { return uws_publish( - @boolToInt(ssl), + @intFromBool(ssl), @ptrCast(*uws_app_t, app), topic.ptr, topic.len, @@ -1073,10 +1330,10 @@ pub const Request = opaque { pub const ListenSocket = opaque { pub fn close(this: *ListenSocket, ssl: bool) void { - us_listen_socket_close(@boolToInt(ssl), this); + us_listen_socket_close(@intFromBool(ssl), this); } pub fn getLocalPort(this: *ListenSocket, ssl: bool) i32 { - return us_socket_local_port(@boolToInt(ssl), @ptrCast(*uws.Socket, this)); + return us_socket_local_port(@intFromBool(ssl), @ptrCast(*uws.Socket, this)); } }; extern fn us_listen_socket_close(ssl: i32, ls: *ListenSocket) void; @@ -1085,7 +1342,7 @@ extern fn us_socket_context_close(ssl: i32, ctx: *anyopaque) void; pub fn NewApp(comptime ssl: bool) type { return opaque { - const ssl_flag = @as(i32, @boolToInt(ssl)); + const ssl_flag = @as(i32, @intFromBool(ssl)); const ThisApp = @This(); pub fn close(this: *ThisApp) void { @@ -1428,7 +1685,7 @@ pub fn NewApp(comptime ssl: bool) type { } pub fn getNativeHandle(res: *Response) i32 { - return @intCast(i32, @ptrToInt(uws_res_get_native_handle(ssl_flag, res.downcast()))); + return @intCast(i32, @intFromPtr(uws_res_get_native_handle(ssl_flag, res.downcast()))); } pub fn onWritable( res: *Response, @@ -1880,23 +2137,23 @@ pub const State = enum(i32) { _, pub inline fn isResponsePending(this: State) bool { - return @enumToInt(this) & @enumToInt(State.HTTP_RESPONSE_PENDING) != 0; + return @intFromEnum(this) & @intFromEnum(State.HTTP_RESPONSE_PENDING) != 0; } pub inline fn isHttpEndCalled(this: State) bool { - return @enumToInt(this) & @enumToInt(State.HTTP_END_CALLED) != 0; + return @intFromEnum(this) & @intFromEnum(State.HTTP_END_CALLED) != 0; } pub inline fn isHttpWriteCalled(this: State) bool { - return @enumToInt(this) & @enumToInt(State.HTTP_WRITE_CALLED) != 0; + return @intFromEnum(this) & @intFromEnum(State.HTTP_WRITE_CALLED) != 0; } pub inline fn isHttpStatusCalled(this: State) bool { - return @enumToInt(this) & @enumToInt(State.HTTP_STATUS_CALLED) != 0; + return @intFromEnum(this) & @intFromEnum(State.HTTP_STATUS_CALLED) != 0; } pub inline fn isHttpConnectionClose(this: State) bool { - return @enumToInt(this) & @enumToInt(State.HTTP_CONNECTION_CLOSE) != 0; + return @intFromEnum(this) & @intFromEnum(State.HTTP_CONNECTION_CLOSE) != 0; } }; diff --git a/src/deps/zig-clap/clap.zig b/src/deps/zig-clap/clap.zig index 16824e788..68cd2451c 100644 --- a/src/deps/zig-clap/clap.zig +++ b/src/deps/zig-clap/clap.zig @@ -111,7 +111,7 @@ fn parseParamRest(line: []const u8) Param(Help) { const len = mem.indexOfScalar(u8, line, '>') orelse break :blk; const takes_many = mem.startsWith(u8, line[len + 1 ..], "..."); const takes_one_optional = mem.startsWith(u8, line[len + 1 ..], "?"); - const help_start = len + 1 + @as(usize, 3) * @boolToInt(takes_many) + (@as(usize, 1) * @boolToInt(takes_one_optional)); + const help_start = len + 1 + @as(usize, 3) * @intFromBool(takes_many) + (@as(usize, 1) * @intFromBool(takes_one_optional)); return .{ .takes_value = if (takes_many) Values.many else if (takes_one_optional) Values.one_optional else Values.one, .id = .{ diff --git a/src/deps/zig-datetime/src/datetime.zig b/src/deps/zig-datetime/src/datetime.zig index 29a936630..1014863b8 100644 --- a/src/deps/zig-datetime/src/datetime.zig +++ b/src/deps/zig-datetime/src/datetime.zig @@ -47,7 +47,7 @@ pub const Month = enum(u4) { if (month.len == 3) { inline for (std.meta.fields(Month)) |f| { if (ascii.eqlIgnoreCase(f.name[0..3], month)) { - return @intToEnum(Month, f.value); + return @enumFromInt(Month, f.value); } } } @@ -57,7 +57,7 @@ pub const Month = enum(u4) { pub fn parseName(month: []const u8) !Month { inline for (std.meta.fields(Month)) |f| { if (ascii.eqlIgnoreCase(f.name, month)) { - return @intToEnum(Month, f.value); + return @enumFromInt(Month, f.value); } } return error.InvalidFormat; @@ -313,7 +313,7 @@ pub const Date = struct { // Create a date from the number of seconds since 1 Jan 1970 pub fn fromSeconds(seconds: f64) Date { const r = math.modf(seconds); - const timestamp = @floatToInt(i64, r.ipart); // Seconds + const timestamp = @intFromFloat(i64, r.ipart); // Seconds const days = @divFloor(timestamp, time.s_per_day) + @as(i64, EPOCH); assert(days >= 0 and days <= MAX_ORDINAL); return Date.fromOrdinal(@intCast(u32, days)); @@ -322,7 +322,7 @@ pub const Date = struct { // Return the number of seconds since 1 Jan 1970 pub fn toSeconds(self: Date) f64 { const days = @intCast(i64, self.toOrdinal()) - @as(i64, EPOCH); - return @intToFloat(f64, days * time.s_per_day); + return @floatFromInt(f64, days * time.s_per_day); } // Create a date from a UTC timestamp in milliseconds relative to Jan 1st 1970 @@ -445,7 +445,7 @@ pub const Date = struct { // Return day of week starting with Monday = 1 and Sunday = 7 pub fn dayOfWeek(self: Date) Weekday { const dow = @intCast(u3, self.toOrdinal() % 7); - return @intToEnum(Weekday, if (dow == 0) 7 else dow); + return @enumFromInt(Weekday, if (dow == 0) 7 else dow); } // Return the ISO calendar based week of year. With 1 being the first week. @@ -455,7 +455,7 @@ pub const Date = struct { // Return day of week starting with Monday = 0 and Sunday = 6 pub fn weekday(self: Date) u4 { - return @enumToInt(self.dayOfWeek()) - 1; + return @intFromEnum(self.dayOfWeek()) - 1; } // Return whether the date is a weekend (Saturday or Sunday) @@ -471,7 +471,7 @@ pub const Date = struct { // Return the name of the day of the month, eg "January" pub fn monthName(self: Date) []const u8 { assert(self.month >= 1 and self.month <= 12); - return @tagName(@intToEnum(Month, self.month)); + return @tagName(@enumFromInt(Month, self.month)); } // ------------------------------------------------------------------------ @@ -596,7 +596,7 @@ test "date-from-seconds" { // // Max check // var max_date = try Date.create(9999, 12, 31); - // const tmax: f64 = @intToFloat(f64, MAX_ORDINAL-1) * time.s_per_day; + // const tmax: f64 = @floatFromInt(f64, MAX_ORDINAL-1) * time.s_per_day; // date = Date.fromSeconds(tmax); // try testing.expect(date.eql(max_date)); // try testing.expectEqual(date.toSeconds(), tmax); @@ -859,7 +859,7 @@ pub const Time = struct { assert(seconds >= 0); // Convert to s and us const r = math.modf(seconds); - var s = @floatToInt(u32, @mod(r.ipart, time.s_per_day)); // s + var s = @intFromFloat(u32, @mod(r.ipart, time.s_per_day)); // s const h = @divFloor(s, time.s_per_hour); s -= h * time.s_per_hour; const m = @divFloor(s, time.s_per_min); @@ -875,15 +875,15 @@ pub const Time = struct { s -= 1; frac += time.ns_per_s; } - const ns = @floatToInt(u32, frac); + const ns = @intFromFloat(u32, frac); return Time.create(h, m, s, ns) catch unreachable; // If this fails it's a bug } // Convert to a time in seconds relative to the UTC timezones // including the nanosecond component pub fn toSeconds(self: Time) f64 { - const s = @intToFloat(f64, self.totalSeconds()); - const ns = @intToFloat(f64, self.nanosecond) / time.ns_per_s; + const s = @floatFromInt(f64, self.totalSeconds()); + const ns = @floatFromInt(f64, self.nanosecond) / time.ns_per_s; return s + ns; } @@ -1393,7 +1393,7 @@ pub const Datetime = struct { const value = std.mem.trim(u8, ims, " "); if (value.len < 29) return error.InvalidFormat; const day = std.fmt.parseInt(u8, value[5..7], 10) catch return error.InvalidFormat; - const month = @enumToInt(try Month.parseAbbr(value[8..11])); + const month = @intFromEnum(try Month.parseAbbr(value[8..11])); const year = std.fmt.parseInt(u16, value[12..16], 10) catch return error.InvalidFormat; const hour = std.fmt.parseInt(u8, value[17..19], 10) catch return error.InvalidFormat; const minute = std.fmt.parseInt(u8, value[20..22], 10) catch return error.InvalidFormat; |