Skip to content

Commit

Permalink
replace [bun.MAX_PATH_BYTES]u8 with bun.PathBuffer (#11162)
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro authored May 21, 2024
1 parent 6c77d5e commit ecb6c81
Show file tree
Hide file tree
Showing 56 changed files with 246 additions and 246 deletions.
4 changes: 2 additions & 2 deletions misctools/readlink-getfd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ pub fn main() anyerror!void {
const to_resolve = args[args.len - 1];
const cwd = try bun.getcwdAlloc(allocator);
var path: []u8 = undefined;
var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
var out_buffer: bun.PathBuffer = undefined;

var j: usize = 0;
while (j < 1000) : (j += 1) {
var parts = [1][]const u8{to_resolve};
var joined_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var joined_buf: bun.PathBuffer = undefined;
var joined = path_handler.joinAbsStringBuf(
cwd,
&joined_buf,
Expand Down
2 changes: 1 addition & 1 deletion misctools/readlink-realpath.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn main() anyerror!void {
var args = std.mem.bytesAsSlice([]u8, try std.process.argsAlloc(allocator));

const to_resolve = args[args.len - 1];
var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
var out_buffer: bun.PathBuffer = undefined;
var path: []u8 = undefined;

var j: usize = 0;
Expand Down
2 changes: 1 addition & 1 deletion misctools/tgz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn main() anyerror!void {
Global.exit(1);
}

var tarball_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var tarball_path_buf: bun.PathBuffer = undefined;
var basename = std.fs.path.basename(bun.asByteSlice(args[args.len - 1]));
while (RecognizedExtensions.has(std.fs.path.extension(basename))) {
basename = basename[0 .. basename.len - std.fs.path.extension(basename).len];
Expand Down
8 changes: 4 additions & 4 deletions src/StandaloneModuleGraph.zig
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub const StandaloneModuleGraph = struct {
return null;
}
if (Environment.isWindows) {
var normalized_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var normalized_buf: bun.PathBuffer = undefined;
const normalized = bun.path.platformToPosixBuf(u8, name, &normalized_buf);
return this.files.getPtr(normalized);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ pub const StandaloneModuleGraph = struct {
std.mem.page_size;

pub fn inject(bytes: []const u8, self_exe: [:0]const u8) bun.FileDescriptor {
var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var buf: bun.PathBuffer = undefined;
var zname: [:0]const u8 = bun.span(bun.fs.FileSystem.instance.tmpname("bun-build", &buf, @as(u64, @bitCast(std.time.milliTimestamp()))) catch |err| {
Output.prettyErrorln("<r><red>error<r><d>:<r> failed to get temporary file name: {s}", .{@errorName(err)});
Global.exit(1);
Expand Down Expand Up @@ -532,7 +532,7 @@ pub const StandaloneModuleGraph = struct {
return;
}

var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var buf: bun.PathBuffer = undefined;
const temp_location = bun.getFdPath(fd, &buf) catch |err| {
Output.prettyErrorln("<r><red>error<r><d>:<r> failed to get path for fd: {s}", .{@errorName(err)});
Global.exit(1);
Expand Down Expand Up @@ -727,7 +727,7 @@ pub const StandaloneModuleGraph = struct {
} else |_| {
if (bun.argv.len > 0) {
// The user doesn't have /proc/ mounted, so now we just guess and hope for the best.
var whichbuf: [bun.MAX_PATH_BYTES]u8 = undefined;
var whichbuf: bun.PathBuffer = undefined;
if (bun.which(
&whichbuf,
bun.getenvZ("PATH") orelse return error.FileNotFound,
Expand Down
2 changes: 1 addition & 1 deletion src/allocators.zig
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ pub fn BSSStringList(comptime _count: usize, comptime _item_length: usize) type
return try self.doAppend(AppendType, _value);
}

threadlocal var lowercase_append_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
threadlocal var lowercase_append_buf: bun.PathBuffer = undefined;
pub fn appendLowerCase(self: *Self, comptime AppendType: type, _value: AppendType) ![]const u8 {
self.mutex.lock();
defer self.mutex.unlock();
Expand Down
14 changes: 7 additions & 7 deletions src/bun.js/RuntimeTranspilerCache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub const RuntimeTranspilerCache = struct {
defer tracer.end();

// atomically write to a tmpfile and then move it to the final destination
var tmpname_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var tmpname_buf: bun.PathBuffer = undefined;
const tmpfilename = bun.sliceTo(try bun.fs.FileSystem.instance.tmpname(std.fs.path.extension(destination_path.slice()), &tmpname_buf, input_hash), 0);

const output_bytes = output_code.byteSlice();
Expand Down Expand Up @@ -365,7 +365,7 @@ pub const RuntimeTranspilerCache = struct {
}

pub fn getCacheFilePath(
buf: *[bun.MAX_PATH_BYTES]u8,
buf: *bun.PathBuffer,
input_hash: u64,
) ![:0]const u8 {
const cache_dir = try getCacheDir(buf);
Expand All @@ -376,7 +376,7 @@ pub const RuntimeTranspilerCache = struct {
return buf[0 .. cache_dir.len + 1 + cache_filename_len :0];
}

fn reallyGetCacheDir(buf: *[bun.MAX_PATH_BYTES]u8) [:0]const u8 {
fn reallyGetCacheDir(buf: *bun.PathBuffer) [:0]const u8 {
if (comptime bun.Environment.isDebug) {
bun_debug_restore_from_cache = bun.getenvZ("BUN_DEBUG_ENABLE_RESTORE_FROM_TRANSPILER_CACHE") != null;
}
Expand Down Expand Up @@ -424,11 +424,11 @@ pub const RuntimeTranspilerCache = struct {
}

// Only do this at most once per-thread.
threadlocal var runtime_transpiler_cache_static_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
threadlocal var runtime_transpiler_cache_static_buffer: bun.PathBuffer = undefined;
threadlocal var runtime_transpiler_cache: ?[:0]const u8 = null;
pub var is_disabled = false;

fn getCacheDir(buf: *[bun.MAX_PATH_BYTES]u8) ![:0]const u8 {
fn getCacheDir(buf: *bun.PathBuffer) ![:0]const u8 {
if (is_disabled) return error.CacheDisabled;
const path = runtime_transpiler_cache orelse path: {
const path = reallyGetCacheDir(&runtime_transpiler_cache_static_buffer);
Expand All @@ -454,7 +454,7 @@ pub const RuntimeTranspilerCache = struct {
var tracer = bun.tracy.traceNamed(@src(), "RuntimeTranspilerCache.fromFile");
defer tracer.end();

var cache_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var cache_file_path_buf: bun.PathBuffer = undefined;
const cache_file_path = try getCacheFilePath(&cache_file_path_buf, input_hash);
bun.assert(cache_file_path.len > 0);
return fromFileWithCacheFilePath(
Expand Down Expand Up @@ -528,7 +528,7 @@ pub const RuntimeTranspilerCache = struct {
var tracer = bun.tracy.traceNamed(@src(), "RuntimeTranspilerCache.toFile");
defer tracer.end();

var cache_file_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var cache_file_path_buf: bun.PathBuffer = undefined;
const output_code: Entry.OutputCode = switch (source_code.encoding()) {
.utf8 => .{ .utf8 = source_code.byteSlice() },
else => .{ .string = source_code },
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/api/BunObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ pub fn which(
callframe: *JSC.CallFrame,
) callconv(.C) JSC.JSValue {
const arguments_ = callframe.arguments(2);
var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var path_buf: bun.PathBuffer = undefined;
var arguments = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), arguments_.slice());
defer arguments.deinit();
const path_arg = arguments.nextEat() orelse {
Expand Down Expand Up @@ -1247,7 +1247,7 @@ pub fn getPublicPathJS(globalObject: *JSC.JSGlobalObject, callframe: *JSC.CallFr
if (arguments.len < 1) {
return bun.String.empty.toJS(globalObject);
}
var public_path_temp_str: [bun.MAX_PATH_BYTES]u8 = undefined;
var public_path_temp_str: bun.PathBuffer = undefined;

const to = arguments[0].toSlice(globalObject, bun.default_allocator);
defer to.deinit();
Expand Down Expand Up @@ -3269,7 +3269,7 @@ pub fn mmapFile(
var args = JSC.Node.ArgumentsSlice.init(globalThis.bunVM(), arguments_.slice());
defer args.deinit();

var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var buf: bun.PathBuffer = undefined;
const path = brk: {
if (args.nextEat()) |path| {
if (path.isString()) {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/JSBundler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ pub const JSBundler = struct {
};
defer dir.close();

var rootdir_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var rootdir_buf: bun.PathBuffer = undefined;
this.rootdir.appendSliceExact(try bun.getFdPath(bun.toFD(dir.fd), &rootdir_buf)) catch unreachable;
}

Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/bun/dns_resolver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ const LibUVBackend = struct {
const port = std.fmt.bufPrintIntToSlice(&port_buf, query.port, 10, .lower, .{});
port_buf[port.len] = 0;
const portZ = port_buf[0..port.len :0];
var hostname: [bun.MAX_PATH_BYTES]u8 = undefined;
var hostname: bun.PathBuffer = undefined;
_ = strings.copy(hostname[0..], query.name);
hostname[query.name.len] = 0;
const host = hostname[0..query.name.len :0];
Expand Down Expand Up @@ -758,7 +758,7 @@ pub const GetAddrInfoRequest = struct {
const port = std.fmt.bufPrintIntToSlice(&port_buf, query.port, 10, .lower, .{});
port_buf[port.len] = 0;
const portZ = port_buf[0..port.len :0];
var hostname: [bun.MAX_PATH_BYTES]u8 = undefined;
var hostname: bun.PathBuffer = undefined;
_ = strings.copy(hostname[0..], query.name);
hostname[query.name.len] = 0;
var addrinfo: ?*std.c.addrinfo = null;
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/bun/subprocess.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1714,7 +1714,7 @@ pub const Subprocess = struct {
defer arg0.deinit();

if (argv0 == null) {
var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var path_buf: bun.PathBuffer = undefined;
const resolved = Which.which(&path_buf, PATH, cwd, arg0.slice()) orelse {
globalThis.throwInvalidArguments("Executable not found in $PATH: \"{s}\"", .{arg0.slice()});
return .zero;
Expand All @@ -1724,7 +1724,7 @@ pub const Subprocess = struct {
return .zero;
};
} else {
var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var path_buf: bun.PathBuffer = undefined;
const resolved = Which.which(&path_buf, PATH, cwd, bun.sliceTo(argv0.?, 0)) orelse {
globalThis.throwInvalidArguments("Executable not found in $PATH: \"{s}\"", .{arg0.slice()});
return .zero;
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/ffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub const FFI = struct {
return JSC.toInvalidArguments("Expected an options object with symbol names", .{}, global);
}

var filepath_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var filepath_buf: bun.PathBuffer = undefined;
const name = brk: {
if (JSC.ModuleLoader.resolveEmbeddedFile(
vm,
Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/api/filesystem_router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ pub const MatchedRoute = struct {
file_path: string,
client_framework_enabled: bool,
) void {
var entry_point_tempbuf: [bun.MAX_PATH_BYTES]u8 = undefined;
var entry_point_tempbuf: bun.PathBuffer = undefined;
// We don't store the framework config including the client parts in the server
// instead, we just store a boolean saying whether we should generate this whenever the script is requested
// this is kind of bad. we should consider instead a way to inline the contents of the script.
Expand All @@ -578,7 +578,7 @@ pub const MatchedRoute = struct {
this: *MatchedRoute,
globalThis: *JSC.JSGlobalObject,
) callconv(.C) JSC.JSValue {
var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var buf: bun.PathBuffer = undefined;
var stream = std.io.fixedBufferStream(&buf);
var writer = stream.writer();
JSC.API.Bun.getPublicPathWithAssetPrefix(
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/glob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const ScanOpts = struct {
}

// Convert to an absolute path
var path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var path_buf: bun.PathBuffer = undefined;
const cwd = switch (bun.sys.getcwd((&path_buf))) {
.result => |cwd| cwd,
.err => |err| {
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2097,7 +2097,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp

this.blob = .{ .Blob = blob };
const file = &this.blob.store().?.data.file;
var file_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
var file_buf: bun.PathBuffer = undefined;
const auto_close = file.pathlike != .fd;
const fd = if (!auto_close)
file.pathlike.fd
Expand Down
2 changes: 1 addition & 1 deletion src/bun.js/bindings/bindings.zig
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ pub const ZigString = extern struct {
};
}

pub fn sliceZBuf(this: ZigString, buf: *[bun.MAX_PATH_BYTES]u8) ![:0]const u8 {
pub fn sliceZBuf(this: ZigString, buf: *bun.PathBuffer) ![:0]const u8 {
return try std.fmt.bufPrintZ(buf, "{}", .{this});
}

Expand Down
4 changes: 2 additions & 2 deletions src/bun.js/javascript.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ pub const VirtualMachine = struct {
return specifier;
}

threadlocal var specifier_cache_resolver_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
threadlocal var specifier_cache_resolver_buf: bun.PathBuffer = undefined;
fn _resolve(
ret: *ResolveFunctionResult,
specifier: string,
Expand Down Expand Up @@ -3806,7 +3806,7 @@ pub fn NewHotReloader(comptime Ctx: type, comptime EventLoopType: type, comptime
var fs: *Fs.FileSystem = bundler.fs;
var rfs: *Fs.FileSystem.RealFS = &fs.fs;
var resolver = &bundler.resolver;
var _on_file_update_path_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var _on_file_update_path_buf: bun.PathBuffer = undefined;

var current_task: HotReloadTask = .{
.reloader = this,
Expand Down
6 changes: 3 additions & 3 deletions src/bun.js/module_loader.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn jsModuleFromFile(from_path: string, comptime input: string) string {
};
} else {
var parts = [_]string{ from_path, "src/js/out/" ++ moduleFolder ++ "/" ++ input };
var buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var buf: bun.PathBuffer = undefined;
var absolute_path_to_use = Fs.FileSystem.instance.absBuf(&parts, &buf);
buf[absolute_path_to_use.len] = 0;
file = std.fs.openFileAbsoluteZ(absolute_path_to_use[0..absolute_path_to_use.len :0], .{ .mode = .read_only }) catch {
Expand Down Expand Up @@ -174,7 +174,7 @@ fn dumpSourceString(specifier: string, written: []const u8) void {
else => "/tmp/bun-debug-src/",
.windows => brk: {
const temp = bun.fs.FileSystem.RealFS.platformTempDir();
var win_temp_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;
var win_temp_buffer: bun.PathBuffer = undefined;
@memcpy(win_temp_buffer[0..temp.len], temp);
const suffix = "\\bun-debug-src";
@memcpy(win_temp_buffer[temp.len .. temp.len + suffix.len], suffix);
Expand Down Expand Up @@ -732,7 +732,7 @@ pub const ModuleLoader = struct {
}

// atomically write to a tmpfile and then move it to the final destination
var tmpname_buf: [bun.MAX_PATH_BYTES]u8 = undefined;
var tmpname_buf: bun.PathBuffer = undefined;
const tmpfilename = bun.sliceTo(bun.fs.FileSystem.instance.tmpname(extname, &tmpname_buf, bun.hash(file.name)) catch return null, 0);

const tmpdir = bun.fs.FileSystem.instance.tmpdir() catch return null;
Expand Down
Loading

0 comments on commit ecb6c81

Please sign in to comment.