fix build

This commit is contained in:
dave caruso
2024-03-07 15:53:15 -08:00
parent f11ff138fe
commit 071771e94d
3 changed files with 8 additions and 7 deletions

View File

@@ -5,16 +5,14 @@ const Environment = @import("./env.zig");
const FixedBufferAllocator = std.heap.FixedBufferAllocator;
const bun = @import("root").bun;
inline fn isSliceInBufferT(comptime T: type, slice: []const T, buffer: []const T) bool {
pub fn isSliceInBufferT(comptime T: type, slice: []const T, buffer: []const T) bool {
return (@intFromPtr(buffer.ptr) <= @intFromPtr(slice.ptr) and
(@intFromPtr(slice.ptr) + slice.len) <= (@intFromPtr(buffer.ptr) + buffer.len));
}
/// LMLJLSDKFjlsdkjflsdkjf
/// Checks if a slice's pointer is contained within another slice.
///
/// If you need to make this generic, use isSliceInBufferT.
pub inline fn isSliceInBuffer(slice: []const u8, buffer: []const u8) bool {
pub fn isSliceInBuffer(slice: []const u8, buffer: []const u8) bool {
return isSliceInBufferT(u8, slice, buffer);
}

View File

@@ -613,6 +613,7 @@ pub fn isHeapMemory(memory: anytype) bool {
pub const Mimalloc = @import("./allocators/mimalloc.zig");
pub const isSliceInBuffer = allocators.isSliceInBuffer;
pub const isSliceInBufferT = allocators.isSliceInBufferT;
pub inline fn sliceInBuffer(stable: string, value: string) string {
if (allocators.sliceRange(stable, value)) |_| {

View File

@@ -431,9 +431,11 @@ pub const RunCommand = struct {
if (Environment.isWindows and bun.strings.hasSuffixComptime(executable, ".exe")) {
std.debug.assert(std.fs.path.isAbsolute(executable));
// Using @constCast is safe because we know that `direct_launch_buffer` is the data destination
// Using @constCast is safe because we know that
// `direct_launch_buffer` is the data destination that assumption is
// backed by the immediate assertion.
var wpath = @constCast(bun.strings.toNTPath(&BunXFastPath.direct_launch_buffer, executable));
std.debug.assert(bun.isSliceInBuffer(u16, wpath, &BunXFastPath.direct_launch_buffer));
std.debug.assert(bun.isSliceInBufferT(u16, wpath, &BunXFastPath.direct_launch_buffer));
std.debug.assert(wpath.len > bun.windows.nt_object_prefix.len + ".exe".len);
wpath.len += ".bunx".len - ".exe".len;
@@ -1562,7 +1564,7 @@ pub const BunXFastPath = struct {
/// If this returns, it implies the fast path cannot be taken
fn tryLaunch(ctx: Command.Context, path_to_use: [:0]u16, env: *DotEnv.Loader, passthrough: []const []const u8) void {
std.debug.assert(bun.isSliceInBuffer(u16, path_to_use, &BunXFastPath.direct_launch_buffer));
std.debug.assert(bun.isSliceInBufferT(u16, path_to_use, &BunXFastPath.direct_launch_buffer));
var command_line = BunXFastPath.direct_launch_buffer[path_to_use.len..];
debug("Attempting to find and load bunx file: '{}'", .{bun.fmt.utf16(path_to_use)});