aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/webcore
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/webcore')
-rw-r--r--src/bun.js/webcore/blob.zig20
-rw-r--r--src/bun.js/webcore/encoding.zig57
-rw-r--r--src/bun.js/webcore/request.zig6
-rw-r--r--src/bun.js/webcore/response.zig14
-rw-r--r--src/bun.js/webcore/streams.zig43
5 files changed, 72 insertions, 68 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig
index 9b3ddb8df..d19a2da26 100644
--- a/src/bun.js/webcore/blob.zig
+++ b/src/bun.js/webcore/blob.zig
@@ -546,7 +546,7 @@ pub const Blob = struct {
return JSPromise.resolvedPromiseValue(ctx.ptr(), cloned.toJS(ctx)).asObjectRef();
} else if (destination_type == .bytes and source_type == .file) {
var fake_call_frame: [8]JSC.JSValue = undefined;
- @memset(@ptrCast([*]u8, &fake_call_frame), 0, @sizeOf(@TypeOf(fake_call_frame)));
+ @memset(@ptrCast([*]u8, &fake_call_frame)[0..@sizeOf(@TypeOf(fake_call_frame))], 0);
const blob_value =
source_blob.getSlice(ctx, @ptrCast(*JSC.CallFrame, &fake_call_frame));
@@ -1232,7 +1232,7 @@ pub const Blob = struct {
}).toSystemError();
// assert we never end up reusing the memory
- std.debug.assert(@ptrToInt(this.system_error.?.path.slice().ptr) != @ptrToInt(path_buffer));
+ std.debug.assert(@intFromPtr(this.system_error.?.path.slice().ptr) != @intFromPtr(path_buffer));
callback(this, null_fd);
return;
@@ -1739,12 +1739,12 @@ pub const Blob = struct {
};
const unsupported_directory_error = SystemError{
- .errno = @intCast(c_int, @enumToInt(bun.C.SystemErrno.EISDIR)),
+ .errno = @intCast(c_int, @intFromEnum(bun.C.SystemErrno.EISDIR)),
.message = ZigString.init("That doesn't work on folders"),
.syscall = ZigString.init("fstat"),
};
const unsupported_non_regular_file_error = SystemError{
- .errno = @intCast(c_int, @enumToInt(bun.C.SystemErrno.ENOTSUP)),
+ .errno = @intCast(c_int, @intFromEnum(bun.C.SystemErrno.ENOTSUP)),
.message = ZigString.init("Non-regular files aren't supported yet"),
.syscall = ZigString.init("fstat"),
};
@@ -1978,14 +1978,14 @@ pub const Blob = struct {
}
this.system_error = (JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, @enumToInt(linux.E.INVAL)),
+ .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(linux.E.INVAL)),
.syscall = TryWith.tag.get(use).?,
}).toSystemError();
return AsyncIO.asError(linux.E.INVAL);
},
else => |errno| {
this.system_error = (JSC.Node.Syscall.Error{
- .errno = @intCast(JSC.Node.Syscall.Error.Int, @enumToInt(errno)),
+ .errno = @intCast(JSC.Node.Syscall.Error.Int, @intFromEnum(errno)),
.syscall = TryWith.tag.get(use).?,
}).toSystemError();
return AsyncIO.asError(errno);
@@ -2000,7 +2000,7 @@ pub const Blob = struct {
}
pub fn doFCopyFile(this: *CopyFile) anyerror!void {
- switch (JSC.Node.Syscall.fcopyfile(this.source_fd, this.destination_fd, os.system.COPYFILE_DATA)) {
+ switch (JSC.Node.Syscall.fcopyfile(this.source_fd, this.destination_fd, os.system.COPYFILE.DATA)) {
.err => |errno| {
this.system_error = errno.toSystemError();
@@ -3816,10 +3816,10 @@ pub const InlineBlob = extern struct {
var bytes_slice = inline_blob.bytes[0..total];
if (first.len > 0)
- @memcpy(bytes_slice.ptr, first.ptr, first.len);
+ @memcpy(bytes_slice[0..first.len], first);
if (second.len > 0)
- @memcpy(bytes_slice.ptr + first.len, second.ptr, second.len);
+ @memcpy(bytes_slice[first.len..][0..second.len], second);
inline_blob.len = @truncate(@TypeOf(inline_blob.len), total);
return inline_blob;
@@ -3834,7 +3834,7 @@ pub const InlineBlob = extern struct {
};
if (data.len > 0)
- @memcpy(&blob.bytes, data.ptr, data.len);
+ @memcpy(blob.bytes[0..data.len], data);
return blob;
}
diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig
index e4b8a4b95..5c8221128 100644
--- a/src/bun.js/webcore/encoding.zig
+++ b/src/bun.js/webcore/encoding.zig
@@ -68,7 +68,7 @@ pub const TextEncoder = struct {
std.debug.assert(result.read == slice.len);
const array_buffer = uint8array.asArrayBuffer(globalThis).?;
std.debug.assert(result.written == array_buffer.len);
- @memcpy(array_buffer.byteSlice().ptr, &buf, result.written);
+ @memcpy(array_buffer.byteSlice()[0..result.written], buf[0..result.written]);
return uint8array;
} else {
const bytes = strings.allocateLatin1IntoUTF8(globalThis.bunVM().allocator, []const u8, slice) catch {
@@ -103,7 +103,7 @@ pub const TextEncoder = struct {
const uint8array = JSC.JSValue.createUninitializedUint8Array(globalThis, 3);
const array_buffer = uint8array.asArrayBuffer(globalThis).?;
const replacement_char = [_]u8{ 239, 191, 189 };
- @memcpy(array_buffer.slice().ptr, &replacement_char, replacement_char.len);
+ @memcpy(array_buffer.slice()[0..replacement_char.len], &replacement_char);
return uint8array;
}
const uint8array = JSC.JSValue.createUninitializedUint8Array(globalThis, result.written);
@@ -111,7 +111,7 @@ pub const TextEncoder = struct {
std.debug.assert(result.read == slice.len);
const array_buffer = uint8array.asArrayBuffer(globalThis).?;
std.debug.assert(result.written == array_buffer.len);
- @memcpy(array_buffer.slice().ptr, &buf, result.written);
+ @memcpy(array_buffer.slice()[0..result.written], buf[0..result.written]);
return uint8array;
} else {
var bytes = strings.toUTF8AllocWithType(
@@ -207,7 +207,7 @@ pub const TextEncoder = struct {
if (array.isEmpty()) {
array = JSC.JSValue.createUninitializedUint8Array(globalThis, length);
array.ensureStillAlive();
- @memcpy(array.asArrayBuffer(globalThis).?.ptr, buf_to_use.ptr, length);
+ @memcpy(array.asArrayBuffer(globalThis).?.ptr[0..length], buf_to_use[0..length]);
}
return array;
@@ -224,7 +224,7 @@ pub const TextEncoder = struct {
var result: strings.EncodeIntoResult = strings.copyUTF16IntoUTF8(output, []const u16, input, false);
if (output.len >= 3 and (result.read == 0 or result.written == 0)) {
const replacement_char = [_]u8{ 239, 191, 189 };
- @memcpy(buf_ptr, &replacement_char, replacement_char.len);
+ @memcpy(buf_ptr[0..replacement_char.len], &replacement_char);
result.read = 1;
result.written = 3;
}
@@ -515,10 +515,10 @@ pub const TextDecoder = struct {
buffer.ensureTotalCapacity(allocator, slice.len) catch unreachable;
buffer.items.len = i;
+ var len = std.mem.sliceAsBytes(slice[0..i]).len;
@memcpy(
- std.mem.sliceAsBytes(buffer.items).ptr,
- std.mem.sliceAsBytes(slice).ptr,
- std.mem.sliceAsBytes(slice[0..i]).len,
+ std.mem.sliceAsBytes(buffer.items)[0..len],
+ std.mem.sliceAsBytes(slice)[0..len],
);
const first_high_surrogate = 0xD800;
@@ -537,10 +537,10 @@ pub const TextDecoder = struct {
const prev = buffer.items.len;
buffer.items.len += count;
// Since this string is freshly allocated, we know it's not going to overlap
+ len = std.mem.sliceAsBytes(remainder[0..count]).len;
@memcpy(
- std.mem.sliceAsBytes(buffer.items[prev..]).ptr,
- std.mem.sliceAsBytes(remainder).ptr,
- std.mem.sliceAsBytes(remainder[0..count]).len,
+ std.mem.sliceAsBytes(buffer.items[prev..])[0..len],
+ std.mem.sliceAsBytes(remainder)[0..len],
);
remainder = remainder[count..];
},
@@ -659,7 +659,7 @@ pub const TextDecoder = struct {
},
EncodingLabel.@"UTF-16LE" => {
- if (std.mem.isAligned(@ptrToInt(buffer_slice.ptr), @alignOf([*]const u16))) {
+ if (std.mem.isAligned(@intFromPtr(buffer_slice.ptr), @alignOf([*]const u16))) {
return this.decodeUTF16WithAlignment([]const u16, @alignCast(2, std.mem.bytesAsSlice(u16, buffer_slice)), globalThis);
}
@@ -701,7 +701,7 @@ pub const TextDecoder = struct {
pub const Encoder = struct {
export fn Bun__encoding__writeLatin1(input: [*]const u8, len: usize, to: [*]u8, to_len: usize, encoding: u8) usize {
- return switch (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.utf8 => writeU8(input, len, to, to_len, .utf8),
.latin1 => writeU8(input, len, to, to_len, .ascii),
.ascii => writeU8(input, len, to, to_len, .ascii),
@@ -714,7 +714,7 @@ pub const Encoder = struct {
} catch 0;
}
export fn Bun__encoding__writeUTF16(input: [*]const u16, len: usize, to: [*]u8, to_len: usize, encoding: u8) usize {
- return switch (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.utf8 => writeU16(input, len, to, to_len, .utf8, false),
.latin1 => writeU16(input, len, to, to_len, .ascii, false),
.ascii => writeU16(input, len, to, to_len, .ascii, false),
@@ -727,7 +727,7 @@ pub const Encoder = struct {
} catch 0;
}
export fn Bun__encoding__byteLengthLatin1(input: [*]const u8, len: usize, encoding: u8) usize {
- return switch (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.utf8 => byteLengthU8(input, len, .utf8),
.latin1 => byteLengthU8(input, len, .ascii),
.ascii => byteLengthU8(input, len, .ascii),
@@ -740,7 +740,7 @@ pub const Encoder = struct {
};
}
export fn Bun__encoding__byteLengthUTF16(input: [*]const u16, len: usize, encoding: u8) usize {
- return switch (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.utf8 => byteLengthU16(input, len, .utf8),
.latin1 => byteLengthU16(input, len, .ascii),
.ascii => byteLengthU16(input, len, .ascii),
@@ -753,7 +753,7 @@ pub const Encoder = struct {
};
}
export fn Bun__encoding__constructFromLatin1(globalObject: *JSGlobalObject, input: [*]const u8, len: usize, encoding: u8) JSValue {
- var slice = switch (@intToEnum(JSC.Node.Encoding, encoding)) {
+ var slice = switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.hex => constructFromU8(input, len, .hex),
.ascii => constructFromU8(input, len, .ascii),
.base64url => constructFromU8(input, len, .base64url),
@@ -766,7 +766,7 @@ pub const Encoder = struct {
return JSC.JSValue.createBuffer(globalObject, slice, globalObject.bunVM().allocator);
}
export fn Bun__encoding__constructFromUTF16(globalObject: *JSGlobalObject, input: [*]const u16, len: usize, encoding: u8) JSValue {
- var slice = switch (@intToEnum(JSC.Node.Encoding, encoding)) {
+ var slice = switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.base64 => constructFromU16(input, len, .base64),
.hex => constructFromU16(input, len, .hex),
.base64url => constructFromU16(input, len, .base64url),
@@ -785,7 +785,7 @@ pub const Encoder = struct {
}
export fn Bun__encoding__toString(input: [*]const u8, len: usize, globalObject: *JSC.JSGlobalObject, encoding: u8) JSValue {
- return switch (@intToEnum(JSC.Node.Encoding, encoding)) {
+ return switch (@enumFromInt(JSC.Node.Encoding, encoding)) {
.ucs2 => toString(input, len, globalObject, .utf16le),
.utf16le => toString(input, len, globalObject, .utf16le),
.utf8 => toString(input, len, globalObject, .utf8),
@@ -830,7 +830,7 @@ pub const Encoder = struct {
.latin1 => {
var to = allocator.alloc(u8, len) catch return ZigString.init("Out of memory").toErrorInstance(global);
- @memcpy(to.ptr, input_ptr, to.len);
+ @memcpy(to, input_ptr[0..to.len]);
return ZigString.init(to).toExternalValue(global);
},
@@ -852,7 +852,7 @@ pub const Encoder = struct {
var output_bytes = std.mem.sliceAsBytes(output);
output_bytes[output_bytes.len - 1] = 0;
- @memcpy(output_bytes.ptr, input_ptr, output_bytes.len);
+ @memcpy(output_bytes, input_ptr[0..output_bytes.len]);
return ZigString.toExternalU16(output.ptr, output.len, global);
},
@@ -892,7 +892,7 @@ pub const Encoder = struct {
switch (comptime encoding) {
.buffer => {
const written = @min(len, to_len);
- @memcpy(to_ptr, input, written);
+ @memcpy(to_ptr[0..written], input[0..written]);
return written;
},
@@ -903,7 +903,7 @@ pub const Encoder = struct {
var remain = input[0..written];
if (bun.simdutf.validate.ascii(remain)) {
- @memcpy(to.ptr, remain.ptr, written);
+ @memcpy(to_ptr[0..written], remain[0..written]);
} else {
strings.copyLatin1IntoASCII(to, remain);
}
@@ -919,7 +919,7 @@ pub const Encoder = struct {
if (to_len < 2)
return 0;
- if (std.mem.isAligned(@ptrToInt(to_ptr), @alignOf([*]u16))) {
+ if (std.mem.isAligned(@intFromPtr(to_ptr), @alignOf([*]u16))) {
var buf = input[0..len];
var output = @ptrCast([*]u16, @alignCast(@alignOf(u16), to_ptr))[0 .. to_len / 2];
@@ -1065,14 +1065,14 @@ pub const Encoder = struct {
switch (comptime encoding) {
.buffer => {
var to = allocator.alloc(u8, len) catch return &[_]u8{};
- @memcpy(to.ptr, input, len);
+ @memcpy(to[0..len], input[0..len]);
return to;
},
.latin1, .ascii => {
var to = allocator.alloc(u8, len) catch return &[_]u8{};
- @memcpy(to.ptr, input, len);
+ @memcpy(to[0..len], input[0..len]);
return to;
},
@@ -1121,7 +1121,7 @@ pub const Encoder = struct {
.latin1, .buffer, .ascii => {
var to = allocator.alloc(u8, len) catch return &[_]u8{};
var input_bytes = std.mem.sliceAsBytes(input[0..len]);
- @memcpy(to.ptr, input_bytes.ptr, input_bytes.len);
+ @memcpy(to[0..input_bytes.len], input_bytes);
for (to[0..len], 0..) |c, i| {
to[i] = @as(u8, @truncate(u7, c));
}
@@ -1131,7 +1131,8 @@ pub const Encoder = struct {
// string is already encoded, just need to copy the data
.ucs2, .utf16le => {
var to = std.mem.sliceAsBytes(allocator.alloc(u16, len * 2) catch return &[_]u8{});
- @memcpy(to.ptr, std.mem.sliceAsBytes(input[0..len]).ptr, std.mem.sliceAsBytes(input[0..len]).len);
+ const bytes = std.mem.sliceAsBytes(input[0..len]);
+ @memcpy(to[0..bytes.len], bytes);
return to;
},
diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig
index a8c648212..231f0deed 100644
--- a/src/bun.js/webcore/request.zig
+++ b/src/bun.js/webcore/request.zig
@@ -472,8 +472,8 @@ pub const Request = struct {
url_or_object,
if (is_first_argument_a_url) JSValue.undefined else url_or_object,
};
- const values_to_try = values_to_try_[0 .. @as(usize, @boolToInt(!is_first_argument_a_url)) +
- @as(usize, @boolToInt(arguments.len > 1 and arguments[1].isObject()))];
+ const values_to_try = values_to_try_[0 .. @as(usize, @intFromBool(!is_first_argument_a_url)) +
+ @as(usize, @intFromBool(arguments.len > 1 and arguments[1].isObject()))];
for (values_to_try) |value| {
const value_type = value.jsType();
@@ -564,7 +564,7 @@ pub const Request = struct {
fields.insert(.url);
// first value
- } else if (@enumToInt(value) == @enumToInt(values_to_try[values_to_try.len - 1]) and !is_first_argument_a_url and
+ } else if (@intFromEnum(value) == @intFromEnum(values_to_try[values_to_try.len - 1]) and !is_first_argument_a_url and
value.implementsToString(globalThis))
{
const slice = value.toSliceOrNull(globalThis) orelse {
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index beae4d182..b4ea08579 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -386,7 +386,7 @@ pub const Response = struct {
const json_value = args.nextEat() orelse JSC.JSValue.zero;
- if (@enumToInt(json_value) != 0) {
+ if (@intFromEnum(json_value) != 0) {
var zig_str = JSC.ZigString.init("");
// calling JSON.stringify on an empty string adds extra quotes
// so this is correct
@@ -448,7 +448,7 @@ pub const Response = struct {
const url_string_value = args.nextEat() orelse JSC.JSValue.zero;
var url_string = ZigString.init("");
- if (@enumToInt(url_string_value) != 0) {
+ if (@intFromEnum(url_string_value) != 0) {
url_string = url_string_value.getZigString(globalThis.ptr());
}
var url_string_slice = url_string.toSlice(getAllocator(globalThis));
@@ -1147,9 +1147,9 @@ pub const Fetch = struct {
JSC.JSError(bun.default_allocator, "Out of memory", .{}, ctx, exception);
return .zero;
};
- @memcpy(buffer.ptr, url_slice.ptr, url_slice.len);
+ @memcpy(buffer[0..url_slice.len], url_slice);
var proxy_url_slice = buffer[url_slice.len..];
- @memcpy(proxy_url_slice.ptr, proxy_url_zig.ptr, proxy_url_zig.len);
+ @memcpy(proxy_url_slice[0..proxy_url_zig.len], proxy_url_zig.ptr[0..proxy_url_zig.len]);
url = ZigURL.parse(buffer[0..url_slice.len]);
proxy = ZigURL.parse(proxy_url_slice);
@@ -1283,9 +1283,9 @@ pub const Fetch = struct {
JSC.JSError(bun.default_allocator, "Out of memory", .{}, ctx, exception);
return .zero;
};
- @memcpy(buffer.ptr, url_slice.ptr, url_slice.len);
+ @memcpy(buffer[0..url_slice.len], url_slice.ptr[0..url_slice.len]);
var proxy_url_slice = buffer[url_slice.len..];
- @memcpy(proxy_url_slice.ptr, proxy_url_zig.ptr, proxy_url_zig.len);
+ @memcpy(proxy_url_slice[0..proxy_url_zig.len], proxy_url_zig.ptr[0..proxy_url_zig.len]);
url = ZigURL.parse(buffer[0..url_slice.len]);
proxy = ZigURL.parse(proxy_url_slice);
@@ -1695,7 +1695,7 @@ pub const FetchEvent = struct {
defer {
if (!VirtualMachine.get().had_errors) {
- Output.printElapsed(@intToFloat(f64, (request_context.timer.lap())) / std.time.ns_per_ms);
+ Output.printElapsed(@floatFromInt(f64, (request_context.timer.lap())) / std.time.ns_per_ms);
Output.prettyError(
" <b>{s}<r><d> - <b>{d}<r> <d>transpiled, <d><b>{d}<r> <d>imports<r>\n",
diff --git a/src/bun.js/webcore/streams.zig b/src/bun.js/webcore/streams.zig
index dddfcbaf5..5986afac7 100644
--- a/src/bun.js/webcore/streams.zig
+++ b/src/bun.js/webcore/streams.zig
@@ -247,7 +247,7 @@ pub const ReadableStream = struct {
pub fn fromNative(globalThis: *JSGlobalObject, id: Tag, ptr: *anyopaque) JSC.JSValue {
JSC.markBinding(@src());
- return ZigGlobalObject__createNativeReadableStream(globalThis, JSValue.fromPtr(ptr), JSValue.jsNumber(@enumToInt(id)));
+ return ZigGlobalObject__createNativeReadableStream(globalThis, JSValue.fromPtr(ptr), JSValue.jsNumber(@intFromEnum(id)));
}
pub fn fromBlob(globalThis: *JSGlobalObject, blob: *const Blob, recommended_chunk_size: Blob.SizeType) JSC.JSValue {
@@ -329,11 +329,11 @@ pub const ReadableStream = struct {
const filedes_ = @bitCast([8]u8, @as(usize, @truncate(u56, @intCast(usize, filedes))));
bytes[1..8].* = filedes_[0..7].*;
- return @intToEnum(StreamTag, @bitCast(u64, bytes));
+ return @enumFromInt(StreamTag, @bitCast(u64, bytes));
}
pub fn fd(this: StreamTag) bun.FileDescriptor {
- var bytes = @bitCast([8]u8, @enumToInt(this));
+ var bytes = @bitCast([8]u8, @intFromEnum(this));
if (bytes[0] != 1) {
return bun.invalid_fd;
}
@@ -780,13 +780,15 @@ pub const StreamResult = union(Tag) {
.temporary => |temp| {
var array = JSC.JSValue.createUninitializedUint8Array(globalThis, temp.len);
var slice_ = array.asArrayBuffer(globalThis).?.slice();
- @memcpy(slice_.ptr, temp.ptr, temp.len);
+ const temp_slice = temp.slice();
+ @memcpy(slice_[0..temp_slice.len], temp_slice);
return array;
},
.temporary_and_done => |temp| {
var array = JSC.JSValue.createUninitializedUint8Array(globalThis, temp.len);
var slice_ = array.asArrayBuffer(globalThis).?.slice();
- @memcpy(slice_.ptr, temp.ptr, temp.len);
+ const temp_slice = temp.slice();
+ @memcpy(slice_[0..temp_slice.len], temp_slice);
return array;
},
.into_array => |array| {
@@ -818,7 +820,7 @@ pub const Signal = struct {
ptr: *anyopaque = dead,
vtable: VTable = VTable.Dead,
- pub const dead = @intToPtr(*anyopaque, 0xaaaaaaaa);
+ pub const dead = @ptrFromInt(*anyopaque, 0xaaaaaaaa);
pub fn clear(this: *Signal) void {
this.ptr = dead;
@@ -920,7 +922,7 @@ pub const Sink = struct {
used: bool = false,
pub const pending = Sink{
- .ptr = @intToPtr(*anyopaque, 0xaaaaaaaa),
+ .ptr = @ptrFromInt(*anyopaque, 0xaaaaaaaa),
.vtable = undefined,
};
@@ -961,7 +963,8 @@ pub const Sink = struct {
if (stack_size >= str.len) {
var buf: [stack_size]u8 = undefined;
- @memcpy(&buf, str.ptr, str.len);
+ @memcpy(buf[0..str.len], str);
+
strings.replaceLatin1WithUTF8(buf[0..str.len]);
if (input.isDone()) {
const result = writeFn(ctx, .{ .temporary_and_done = bun.ByteList.init(buf[0..str.len]) });
@@ -974,7 +977,8 @@ pub const Sink = struct {
{
var slice = bun.default_allocator.alloc(u8, str.len) catch return .{ .err = Syscall.Error.oom };
- @memcpy(slice.ptr, str.ptr, str.len);
+ @memcpy(slice[0..str.len], str);
+
strings.replaceLatin1WithUTF8(slice[0..str.len]);
if (input.isDone()) {
return writeFn(ctx, .{ .owned_and_done = bun.ByteList.init(slice) });
@@ -1262,7 +1266,7 @@ pub const FileSink = struct {
const initial_remain = remain;
defer {
- std.debug.assert(total - initial == @ptrToInt(remain.ptr) - @ptrToInt(initial_remain.ptr));
+ std.debug.assert(total - initial == @intFromPtr(remain.ptr) - @intFromPtr(initial_remain.ptr));
if (remain.len == 0) {
this.head = 0;
@@ -1908,15 +1912,15 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
pub fn init(cpp: JSValue) Signal {
// this one can be null
@setRuntimeSafety(false);
- return Signal.initWithType(SinkSignal, @intToPtr(*SinkSignal, @bitCast(usize, @enumToInt(cpp))));
+ return Signal.initWithType(SinkSignal, @ptrFromInt(*SinkSignal, @bitCast(usize, @intFromEnum(cpp))));
}
pub fn close(this: *@This(), _: ?Syscall.Error) void {
- onClose(@bitCast(SinkSignal, @ptrToInt(this)).cpp, JSValue.jsUndefined());
+ onClose(@bitCast(SinkSignal, @intFromPtr(this)).cpp, JSValue.jsUndefined());
}
pub fn ready(this: *@This(), _: ?Blob.SizeType, _: ?Blob.SizeType) void {
- onReady(@bitCast(SinkSignal, @ptrToInt(this)).cpp, JSValue.jsUndefined(), JSValue.jsUndefined());
+ onReady(@bitCast(SinkSignal, @intFromPtr(this)).cpp, JSValue.jsUndefined(), JSValue.jsUndefined());
}
pub fn start(_: *@This()) void {}
@@ -1992,7 +1996,7 @@ pub fn NewJSSink(comptime SinkType: type, comptime name_: []const u8) type {
if (this.sink.signal.isDead())
return;
this.sink.signal.clear();
- const value = @intToEnum(JSValue, @bitCast(JSC.JSValueReprInt, @ptrToInt(ptr)));
+ const value = @enumFromInt(JSValue, @bitCast(JSC.JSValueReprInt, @intFromPtr(ptr)));
value.unprotect();
detachPtr(value);
}
@@ -3127,7 +3131,7 @@ pub const ByteBlobLoader = struct {
this.remain -|= copied;
this.offset +|= copied;
std.debug.assert(buffer.ptr != temporary.ptr);
- @memcpy(buffer.ptr, temporary.ptr, temporary.len);
+ @memcpy(buffer[0..temporary.len], temporary);
if (this.remain == 0) {
return .{ .into_array_and_done = .{ .value = array, .len = copied } };
}
@@ -3231,7 +3235,7 @@ pub const ByteStream = struct {
}
if (this.has_received_last_chunk) {
- return .{ .chunk_size = @truncate(Blob.SizeType, @min(1024 * 1024 * 2, this.buffer.items.len)) };
+ return .{ .chunk_size = @min(1024 * 1024 * 2, this.buffer.items.len) };
}
if (this.highWaterMark == 0) {
@@ -3292,7 +3296,7 @@ pub const ByteStream = struct {
var to_copy = this.pending_buffer[0..@min(chunk.len, this.pending_buffer.len)];
const pending_buffer_len = this.pending_buffer.len;
std.debug.assert(to_copy.ptr != chunk.ptr);
- @memcpy(to_copy.ptr, chunk.ptr, to_copy.len);
+ @memcpy(to_copy, chunk[0..to_copy.len]);
this.pending_buffer = &.{};
const is_really_done = this.has_received_last_chunk and to_copy.len <= pending_buffer_len;
@@ -3382,7 +3386,7 @@ pub const ByteStream = struct {
);
var remaining_in_buffer = this.buffer.items[this.offset..][0..to_write];
- @memcpy(buffer.ptr, this.buffer.items.ptr + this.offset, to_write);
+ @memcpy(buffer[0..to_write], this.buffer.items[this.offset..][0..to_write]);
if (this.offset + to_write == this.buffer.items.len) {
this.offset = 0;
@@ -4071,7 +4075,7 @@ pub const File = struct {
this.pending.result = .{
.err = Syscall.Error{
// this is too hacky
- .errno = @truncate(Syscall.Error.Int, @intCast(u16, @max(1, @errorToInt(err)))),
+ .errno = @truncate(Syscall.Error.Int, @intCast(u16, @max(1, @intFromError(err)))),
.syscall = .read,
},
};
@@ -4655,4 +4659,3 @@ pub fn NewReadyWatcher(
// pub fn onError(this: *Streamer): anytype,
// };
// }
-