From b2dbe23458da4cd097f264ba6bd40940550213c6 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Thu, 7 Aug 2025 04:24:16 -0700 Subject: [PATCH] small fixes --- scripts/runner.node.mjs | 2 +- src/boringssl.zig | 8 +------- src/bun.js/api/bun/dns.zig | 8 ++++---- src/bun.js/api/filesystem_router.zig | 2 +- src/bun.js/bindings/bindings.cpp | 4 ++++ src/bun.js/bindings/helpers.h | 2 ++ src/bun.js/bindings/root.h | 2 +- src/bun.js/modules/BunJSCModule.h | 5 ++++- src/bun.js/webcore/TextDecoder.zig | 4 ++-- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/scripts/runner.node.mjs b/scripts/runner.node.mjs index 2edc514b6c..1033f834d4 100755 --- a/scripts/runner.node.mjs +++ b/scripts/runner.node.mjs @@ -142,7 +142,7 @@ const { values: options, positionals: filters } = parseArgs({ }, ["retries"]: { type: "string", - default: isCI ? "1" : "0", // N retries = N+1 attempts + default: isCI ? "0" : "0", // N retries = N+1 attempts }, ["junit"]: { type: "boolean", diff --git a/src/boringssl.zig b/src/boringssl.zig index ca1181c167..7f0d2c7123 100644 --- a/src/boringssl.zig +++ b/src/boringssl.zig @@ -70,13 +70,7 @@ export fn OPENSSL_memory_free(ptr: *anyopaque) void { } export fn OPENSSL_memory_get_size(ptr: ?*const anyopaque) usize { - if (!bun.use_mimalloc) return switch (bun.Environment.os) { - .mac => std.c.malloc_size(ptr), - .linux => std.c.malloc_usable_size(ptr), - .windows => std.c._msize(@constCast(ptr)), // https://github.com/ziglang/zig/pull/24725 - .wasm => @compileError("unreachable"), - }; - return bun.mimalloc.mi_usable_size(ptr); + return bun.default_malloc_usable_size(ptr); } const INET6_ADDRSTRLEN = if (bun.Environment.isWindows) 65 else 46; diff --git a/src/bun.js/api/bun/dns.zig b/src/bun.js/api/bun/dns.zig index c3117f480d..c8eb4c99a9 100644 --- a/src/bun.js/api/bun/dns.zig +++ b/src/bun.js/api/bun/dns.zig @@ -282,7 +282,7 @@ pub fn ResolveInfoRequest(comptime cares_type: type, comptime type_name: []const globalThis: *jsc.JSGlobalObject, comptime cache_field: []const u8, ) !*@This() { - var request = try globalThis.allocator().create(@This()); + var request = try bun.default_allocator.create(@This()); var hasher = std.hash.Wyhash.init(0); hasher.update(name); const hash = hasher.final(); @@ -388,7 +388,7 @@ pub const GetHostByAddrInfoRequest = struct { globalThis: *jsc.JSGlobalObject, comptime cache_field: []const u8, ) !*@This() { - var request = try globalThis.allocator().create(@This()); + var request = try bun.default_allocator.create(@This()); var hasher = std.hash.Wyhash.init(0); hasher.update(name); const hash = hasher.final(); @@ -549,7 +549,7 @@ pub const GetNameInfoRequest = struct { globalThis: *jsc.JSGlobalObject, comptime cache_field: []const u8, ) !*@This() { - var request = try globalThis.allocator().create(@This()); + var request = try bun.default_allocator.create(@This()); var hasher = std.hash.Wyhash.init(0); hasher.update(name); const hash = hasher.final(); @@ -645,7 +645,7 @@ pub const GetAddrInfoRequest = struct { comptime cache_field: []const u8, ) !*GetAddrInfoRequest { log("init", .{}); - var request = try globalThis.allocator().create(GetAddrInfoRequest); + var request = try bun.default_allocator.create(GetAddrInfoRequest); var poll_ref = Async.KeepAlive.init(); poll_ref.ref(globalThis.bunVM()); if (resolver) |resolver_| resolver_.ref(); diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig index 4c9003c4fc..7df804b99e 100644 --- a/src/bun.js/api/filesystem_router.zig +++ b/src/bun.js/api/filesystem_router.zig @@ -440,7 +440,7 @@ pub const MatchedRoute = struct { } if (this.needs_deinit) { if (this.route.pathname.len > 0 and bun.use_mimalloc and bun.mimalloc.mi_is_in_heap_region(this.route.pathname.ptr)) { - bun.default_free(@constCast(this.route.pathname.ptr)); + bun.mimalloc.mi_free(@constCast(this.route.pathname.ptr)); } this.params_list_holder.deinit(bun.default_allocator); diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index d9be051db0..4dabb313df 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -3116,7 +3116,9 @@ JSC::EncodedJSValue ZigString__toExternalU16(const uint16_t* arg0, size_t len, J return JSC::JSValue::encode(JSC::jsEmptyString(global->vm())); } +#if !ENABLE_MIMALLOC ASSERT(!mi_is_in_heap_region(arg0)); +#endif auto ref = String(ExternalStringImpl::create({ reinterpret_cast(arg0), len }, reinterpret_cast(const_cast(arg0)), free_global_string)); return JSC::JSValue::encode(JSC::jsString(global->vm(), WTFMove(ref))); } @@ -3129,8 +3131,10 @@ JSC::EncodedJSValue ZigString__toExternalValue(const ZigString* arg0, JSC::JSGlo return JSC::JSValue::encode(JSC::jsEmptyString(arg1->vm())); } +#if !ENABLE_MIMALLOC ASSERT(!mi_is_in_heap_region(str.ptr)); ASSERT(!mi_is_in_heap_region(Zig::untag(str.ptr))); +#endif if (Zig::isTaggedUTF16Ptr(str.ptr)) { auto ref = String(ExternalStringImpl::create({ reinterpret_cast(Zig::untag(str.ptr)), str.len }, Zig::untagVoid(str.ptr), free_global_string)); return JSC::JSValue::encode(JSC::jsString(arg1->vm(), WTFMove(ref))); diff --git a/src/bun.js/bindings/helpers.h b/src/bun.js/bindings/helpers.h index 91f9955a01..81c0e1544a 100644 --- a/src/bun.js/bindings/helpers.h +++ b/src/bun.js/bindings/helpers.h @@ -84,8 +84,10 @@ static const WTF::String toString(ZigString str) } if (isTaggedExternalPtr(str.ptr)) [[unlikely]] { +#if !ENABLE_MIMALLOC ASSERT(!mi_is_in_heap_region(str.ptr)); ASSERT(!mi_is_in_heap_region(untag(str.ptr))); +#endif // This will fail if the string is too long. Let's make it explicit instead of an ASSERT. if (str.len > Bun__stringSyntheticAllocationLimit) [[unlikely]] { free_global_string(nullptr, reinterpret_cast(const_cast(untag(str.ptr))), static_cast(str.len)); diff --git a/src/bun.js/bindings/root.h b/src/bun.js/bindings/root.h index 8d798a5514..5f6a6ad58d 100644 --- a/src/bun.js/bindings/root.h +++ b/src/bun.js/bindings/root.h @@ -102,7 +102,7 @@ #define ZIG_EXPORT(...) #define ZIG_NONNULL -#if ENABLE_ASAN +#if ASAN_ENABLED #define ENABLE_MIMALLOC 0 #else #define ENABLE_MIMALLOC 1 diff --git a/src/bun.js/modules/BunJSCModule.h b/src/bun.js/modules/BunJSCModule.h index c009656d67..953e6d83c3 100644 --- a/src/bun.js/modules/BunJSCModule.h +++ b/src/bun.js/modules/BunJSCModule.h @@ -359,7 +359,6 @@ JSC_DECLARE_HOST_FUNCTION(functionCreateMemoryFootprint); JSC_DEFINE_HOST_FUNCTION(functionCreateMemoryFootprint, (JSGlobalObject * globalObject, CallFrame*)) { - size_t elapsed_msecs = 0; size_t user_msecs = 0; size_t system_msecs = 0; @@ -372,6 +371,10 @@ JSC_DEFINE_HOST_FUNCTION(functionCreateMemoryFootprint, #if ENABLE_MIMALLOC mi_process_info(&elapsed_msecs, &user_msecs, &system_msecs, ¤t_rss, &peak_rss, ¤t_commit, &peak_commit, &page_faults); +#else + (void)elapsed_msecs; + (void)user_msecs; + (void)system_msecs; #endif // mi_process_info produces incorrect rss size on linux. diff --git a/src/bun.js/webcore/TextDecoder.zig b/src/bun.js/webcore/TextDecoder.zig index 402f5d793c..420db9705a 100644 --- a/src/bun.js/webcore/TextDecoder.zig +++ b/src/bun.js/webcore/TextDecoder.zig @@ -199,9 +199,9 @@ fn decodeSlice(this: *TextDecoder, globalThis: *jsc.JSGlobalObject, buffer_slice // It's unintuitive that we encode Latin1 as UTF16 even though the engine natively supports Latin1 strings... // However, this is also what WebKit seems to do. // - // It's not clear why we couldn't jusst use Latin1 here, but tests failures proved it necessary. + // It's not clear why we couldn't just use Latin1 here, but tests failures proved it necessary. const out_length = strings.elementLengthLatin1IntoUTF16([]const u8, buffer_slice); - const bytes = try globalThis.allocator().alloc(u16, out_length); + const bytes = try bun.default_allocator.alloc(u16, out_length); const out = strings.copyLatin1IntoUTF16([]u16, bytes, []const u8, buffer_slice); return ZigString.toExternalU16(bytes.ptr, out.written, globalThis);