aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/bun/subprocess.zig4
-rw-r--r--src/bun.js/api/filesystem_router.zig2
-rw-r--r--src/bun.js/api/server.zig2
-rw-r--r--src/bun.js/base.zig50
-rw-r--r--src/bun.js/bindings/bindings.zig15
-rw-r--r--src/bun.js/bindings/exports.zig15
-rw-r--r--src/bun.js/bindings/wtf-bindings.cpp42
7 files changed, 85 insertions, 45 deletions
diff --git a/src/bun.js/api/bun/subprocess.zig b/src/bun.js/api/bun/subprocess.zig
index 4fb02b8af..f1fbd242a 100644
--- a/src/bun.js/api/bun/subprocess.zig
+++ b/src/bun.js/api/bun/subprocess.zig
@@ -1372,8 +1372,8 @@ pub const Subprocess = struct {
return .zero;
},
// stdout and stderr only uses allocator and default_max_buffer_size if they are pipes and not a array buffer
- .stdout = Readable.init(stdio[std.os.STDOUT_FILENO], stdout_pipe[0], jsc_vm.allocator, default_max_buffer_size),
- .stderr = Readable.init(stdio[std.os.STDERR_FILENO], stderr_pipe[0], jsc_vm.allocator, default_max_buffer_size),
+ .stdout = Readable.init(stdio[std.os.STDOUT_FILENO], stdout_pipe[0], bun.default_allocator, default_max_buffer_size),
+ .stderr = Readable.init(stdio[std.os.STDERR_FILENO], stderr_pipe[0], bun.default_allocator, default_max_buffer_size),
.on_exit_callback = if (on_exit_callback != .zero) JSC.Strong.create(on_exit_callback, globalThis) else .{},
.is_sync = is_sync,
};
diff --git a/src/bun.js/api/filesystem_router.zig b/src/bun.js/api/filesystem_router.zig
index 216f66b7f..814f9c9b6 100644
--- a/src/bun.js/api/filesystem_router.zig
+++ b/src/bun.js/api/filesystem_router.zig
@@ -550,7 +550,7 @@ pub const MatchedRoute = struct {
}
if (this.needs_deinit) {
if (this.route.pathname.len > 0 and bun.Mimalloc.mi_is_in_heap_region(this.route.pathname.ptr)) {
- bun.Mimalloc.mi_free(bun.constStrToU8(this.route.pathname).ptr);
+ bun.default_allocator.free(bun.constStrToU8(this.route.pathname));
}
this.params_list_holder.deinit(bun.default_allocator);
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 801745aee..28bcb45a4 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -5104,7 +5104,7 @@ pub fn NewServer(comptime ssl_enabled_: bool, comptime debug_mode_: bool) type {
.config = config,
.base_url_string_for_joining = bun.default_allocator.dupe(u8, strings.trim(config.base_url.href, "/")) catch unreachable,
.vm = JSC.VirtualMachine.get(),
- .allocator = Arena.getThreadlocalDefault(),
+ .allocator = bun.default_allocator,
};
if (RequestContext.pool == null) {
diff --git a/src/bun.js/base.zig b/src/bun.js/base.zig
index 579a0975a..0528eb8d1 100644
--- a/src/bun.js/base.zig
+++ b/src/bun.js/base.zig
@@ -1824,31 +1824,31 @@ pub const ArrayBuffer = extern struct {
return this.value;
}
- // If it's not a mimalloc heap buffer, we're not going to call a deallocator
- if (this.len > 0 and !bun.Mimalloc.mi_is_in_heap_region(this.ptr)) {
- log("toJS but will never free: {d} bytes", .{this.len});
-
- if (this.typed_array_type == .ArrayBuffer) {
- return JSC.JSValue.fromRef(JSC.C.JSObjectMakeArrayBufferWithBytesNoCopy(
- ctx,
- this.ptr,
- this.byte_len,
- null,
- null,
- exception,
- ));
- }
-
- return JSC.JSValue.fromRef(JSC.C.JSObjectMakeTypedArrayWithBytesNoCopy(
- ctx,
- this.typed_array_type.toC(),
- this.ptr,
- this.byte_len,
- null,
- null,
- exception,
- ));
- }
+ // // If it's not a mimalloc heap buffer, we're not going to call a deallocator
+ // if (this.len > 0 and !bun.Mimalloc.mi_is_in_heap_region(this.ptr)) {
+ // log("toJS but will never free: {d} bytes", .{this.len});
+
+ // if (this.typed_array_type == .ArrayBuffer) {
+ // return JSC.JSValue.fromRef(JSC.C.JSObjectMakeArrayBufferWithBytesNoCopy(
+ // ctx,
+ // this.ptr,
+ // this.byte_len,
+ // null,
+ // null,
+ // exception,
+ // ));
+ // }
+
+ // return JSC.JSValue.fromRef(JSC.C.JSObjectMakeTypedArrayWithBytesNoCopy(
+ // ctx,
+ // this.typed_array_type.toC(),
+ // this.ptr,
+ // this.byte_len,
+ // null,
+ // null,
+ // exception,
+ // ));
+ // }
return this.toJSUnchecked(ctx, exception);
}
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 4f533b9d9..8be5d878f 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -727,6 +727,10 @@ pub const ZigString = extern struct {
return untagged(this._unsafe_ptr_do_not_use)[0..@min(this.len, std.math.maxInt(u32))];
}
+ pub fn untaggedPtr(this: *const ZigString) [*]const u8 {
+ return untagged(this._unsafe_ptr_do_not_use);
+ }
+
pub fn dupe(this: ZigString, allocator: std.mem.Allocator) ![]const u8 {
return try allocator.dupe(u8, this.slice());
}
@@ -837,11 +841,12 @@ pub const ZigString = extern struct {
}
inline fn assertGlobal(this: *const ZigString) void {
- if (comptime bun.Environment.allow_assert) {
- std.debug.assert(this.len == 0 or
- bun.Mimalloc.mi_is_in_heap_region(untagged(this._unsafe_ptr_do_not_use)) or
- bun.Mimalloc.mi_check_owned(untagged(this._unsafe_ptr_do_not_use)));
- }
+ _ = this;
+ // if (comptime bun.Environment.allow_assert) {
+ // std.debug.assert(this.len == 0 or
+ // bun.Mimalloc.mi_is_in_heap_region(untagged(this._unsafe_ptr_do_not_use)) or
+ // bun.Mimalloc.mi_check_owned(untagged(this._unsafe_ptr_do_not_use)));
+ // }
}
pub fn toValue(this: *const ZigString, global: *JSGlobalObject) JSValue {
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 20c110d52..ca70aa5ba 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -243,22 +243,17 @@ const Mimalloc = @import("../../allocators/mimalloc.zig");
export fn ZigString__free(raw: [*]const u8, len: usize, allocator_: ?*anyopaque) void {
var allocator: std.mem.Allocator = @as(*std.mem.Allocator, @ptrCast(@alignCast(allocator_ orelse return))).*;
- var ptr = ZigString.init(raw[0..len]).slice().ptr;
- if (comptime Environment.allow_assert) {
- std.debug.assert(Mimalloc.mi_is_in_heap_region(ptr));
- }
+ var ptr = ZigString.init(raw[0..len]).untaggedPtr();
+ // if (comptime Environment.allow_assert) {
+ // std.debug.assert(Mimalloc.mi_is_in_heap_region(ptr));
+ // }
var str = ptr[0..len];
allocator.free(str);
}
export fn ZigString__free_global(ptr: [*]const u8, len: usize) void {
- var untagged = @as(*anyopaque, @ptrFromInt(@intFromPtr(ZigString.init(ptr[0..len]).slice().ptr)));
- if (comptime Environment.allow_assert) {
- std.debug.assert(Mimalloc.mi_is_in_heap_region(ptr));
- }
- // we must untag the string pointer
- Mimalloc.mi_free(untagged);
+ bun.free(@constCast(ZigString.init(ptr[0..len]).untaggedPtr()));
}
export fn Zig__getAPIGlobals(count: *usize) [*]JSC.C.JSClassRef {
diff --git a/src/bun.js/bindings/wtf-bindings.cpp b/src/bun.js/bindings/wtf-bindings.cpp
index 5c0e593d7..5bc37467a 100644
--- a/src/bun.js/bindings/wtf-bindings.cpp
+++ b/src/bun.js/bindings/wtf-bindings.cpp
@@ -2,7 +2,47 @@
#include "wtf/text/Base64.h"
#include "wtf/StackTrace.h"
-#include "wtf/dtoa.h"
+#include "bmalloc/bmalloc.h"
+
+extern "C" void bun__bmalloc__init()
+{
+ WTF::initializeMainThread();
+}
+
+extern "C" void* bun__bmalloc__memalign(size_t alignment, size_t size)
+{
+ return bmalloc::api::tryMemalign(alignment, size);
+}
+
+extern "C" void bun__bmalloc__free(void* ptr)
+{
+ bmalloc::api::free(ptr);
+}
+
+extern "C" void* bun__bmalloc__realloc(void* ptr, size_t size)
+{
+ if (bmalloc_get_allocation_size(ptr) >= size)
+ return (void*)ptr;
+
+ return nullptr;
+}
+
+extern "C" size_t bun__bmalloc__size(void* ptr)
+{
+ return bmalloc_get_allocationpub fn isHeapMemory(memory
+ : anytype) bool
+ {
+ if (comptime use_mimalloc) {
+ const Memory = @TypeOf(memory);
+ if (comptime std.meta.trait.isSingleItemPtr(Memory)) {
+ return Mimalloc.mi_is_in_heap_region(memory);
+ }
+ return Mimalloc.mi_is_in_heap_region(std.mem.sliceAsBytes(memory).ptr);
+ }
+ return false;
+ }
+ _size(ptr);
+}
extern "C" double WTF__parseDouble(const LChar* string, size_t length, size_t* position)
{