diff options
| author | 2022-04-03 16:35:09 -0700 | |
|---|---|---|
| committer | 2022-04-03 16:35:09 -0700 | |
| commit | 27ad502119c15f41d3248733b9d778d5a72a55d6 (patch) | |
| tree | d13d338f6341b39b0c18c47d107e59e7655f809e /src | |
| parent | e8b2af1eaeabe4919bb239217e1c4b634929eade (diff) | |
| download | bun-27ad502119c15f41d3248733b9d778d5a72a55d6.tar.gz bun-27ad502119c15f41d3248733b9d778d5a72a55d6.tar.zst bun-27ad502119c15f41d3248733b9d778d5a72a55d6.zip | |
cleanup a few things
Diffstat (limited to 'src')
| -rw-r--r-- | src/javascript/jsc/node/syscall.zig | 8 | ||||
| -rw-r--r-- | src/javascript/jsc/node/types.zig | 1 | ||||
| -rw-r--r-- | src/mimalloc_arena.zig | 8 | ||||
| -rw-r--r-- | src/yield.zig | 17 |
4 files changed, 26 insertions, 8 deletions
diff --git a/src/javascript/jsc/node/syscall.zig b/src/javascript/jsc/node/syscall.zig index 736e5b809..397ecdb29 100644 --- a/src/javascript/jsc/node/syscall.zig +++ b/src/javascript/jsc/node/syscall.zig @@ -210,7 +210,6 @@ else pub fn pread(fd: os.fd_t, buf: []u8, offset: i64) Maybe(usize) { const adjusted_len = @minimum(buf.len, max_count); - const ioffset = @bitCast(i64, offset); // the OS treats this as unsigned while (true) { const rc = pread_sym(fd, buf.ptr, adjusted_len, ioffset); @@ -378,6 +377,7 @@ pub fn getFdPath(fd: fd_t, out_buffer: *[MAX_PATH_BYTES]u8) Maybe([]u8) { return .{ .result = out_buffer[0..len] }; }, .linux => { + // TODO: alpine linux may not have /proc/self var procfs_buf: ["/proc/self/fd/-2147483648".len:0]u8 = undefined; const proc_path = std.fmt.bufPrintZ(procfs_buf[0..], "/proc/self/fd/{d}\x00", .{fd}) catch unreachable; @@ -423,9 +423,9 @@ fn mmap( return Maybe([]align(mem.page_size) u8){ .err = .{ .errno = @truncate(Syscall.Error.Int, @enumToInt(std.c.getErrno(@bitCast(i64, @ptrToInt(std.c.MAP.FAILED))))), .syscall = .mmap }, }; - } - - return Maybe([]align(mem.page_size) u8){.result = @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length] }; + } + + return Maybe([]align(mem.page_size) u8){ .result = @ptrCast([*]align(mem.page_size) u8, @alignCast(mem.page_size, rc))[0..length] }; } pub fn mmapFile(path: [:0]const u8, flags: u32) Maybe([]align(mem.page_size) u8) { diff --git a/src/javascript/jsc/node/types.zig b/src/javascript/jsc/node/types.zig index f7c8ac967..f3beeef8d 100644 --- a/src/javascript/jsc/node/types.zig +++ b/src/javascript/jsc/node/types.zig @@ -232,7 +232,6 @@ pub fn CallbackTask(comptime Result: type) type { callback: JSC.C.JSObjectRef, option: Option, success: bool = false, - completion: AsyncIO.Completion, pub const Option = union { err: JSC.SystemError, diff --git a/src/mimalloc_arena.zig b/src/mimalloc_arena.zig index 2c2f493ce..70ce813a4 100644 --- a/src/mimalloc_arena.zig +++ b/src/mimalloc_arena.zig @@ -9,19 +9,21 @@ const Allocator = mem.Allocator; const assert = std.debug.assert; pub const Arena = struct { - heap: *mimalloc.mi_heap_t = undefined, + heap: ?*mimalloc.mi_heap_t = null, pub fn backingAllocator(this: Arena) Allocator { - var arena = Arena{ .heap = this.heap.backing() }; + var arena = Arena{ .heap = this.heap.?.backing() }; return arena.allocator(); } pub fn allocator(this: Arena) Allocator { - return Allocator{ .ptr = this.heap, .vtable = &c_allocator_vtable }; + @setRuntimeSafety(false); + return Allocator{ .ptr = this.heap.?, .vtable = &c_allocator_vtable }; } pub fn deinit(this: *Arena) void { mimalloc.mi_heap_destroy(this.heap); + this.heap = null; } pub fn reset(this: *Arena) void { diff --git a/src/yield.zig b/src/yield.zig new file mode 100644 index 000000000..135bd7e52 --- /dev/null +++ b/src/yield.zig @@ -0,0 +1,17 @@ +pub fn Yield(comptime Type: anytype) type { + return struct { + frame: @Frame(Type) = undefined, + wait: bool = false, + + pub fn set(this: *@This(), frame: anytype) void { + this.wait = true; + this.frame = frame.*; + } + + pub fn maybeResume(this: *@This()) void { + if (!this.wait) return; + this.wait = false; + resume this.frame; + } + }; +} |
