aboutsummaryrefslogtreecommitdiff
path: root/src/options.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2023-04-22 19:44:23 -0700
committerGravatar GitHub <noreply@github.com> 2023-04-22 19:44:23 -0700
commit4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4 (patch)
tree7983dd2d5ba18f9a6111be2e7e6d17f69d170bba /src/options.zig
parent7d6b5f5358617f92ace6f3103dd835ddff73f92a (diff)
downloadbun-4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4.tar.gz
bun-4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4.tar.zst
bun-4b24bb464c5a54c728bee8c9b4aa30a60c3fb7d4.zip
Make `Bun.build` more reliable (#2718)
* One possible implementation to make `Bun.build` work better * Pass allocator in * Make our temporary buffers a little safer * rename * Fix memory corruption in symbol table * Add support for deferred idle events in ThreadPool * Free more memory * Use a global allocator FS cache * more `inline` * Make duping keys optional in StringMap * Close file handles more often * Update router.zig * wip possibly delete this commit * Fix memory issues and reduce memory usage * > 0.8 * Switch to AsyncIO.Waker and fix memory leak in JSBundleCompletionTask * We don't need to clone this actually * Fix error * Format * Fixup * Fixup --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to '')
-rw-r--r--src/options.zig26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/options.zig b/src/options.zig
index 59b814894..26485eb70 100644
--- a/src/options.zig
+++ b/src/options.zig
@@ -1974,6 +1974,7 @@ pub const OutputFile = struct {
var blob = globalObject.allocator().create(JSC.WebCore.Blob) catch unreachable;
blob.* = JSC.WebCore.Blob.initWithStore(file_blob, globalObject);
blob.allocator = globalObject.allocator();
+ blob.globalThis = globalObject;
blob.content_type = loader.toMimeType().value;
return blob.toJS(globalObject);
@@ -1996,7 +1997,11 @@ pub const OutputFile = struct {
};
pub const Value = union(Kind) {
- buffer: []const u8,
+ buffer: struct {
+ allocator: std.mem.Allocator,
+ bytes: []const u8,
+ },
+
move: FileOperation,
copy: FileOperation,
noop: u0,
@@ -2029,12 +2034,17 @@ pub const OutputFile = struct {
return res;
}
- pub fn initBuf(buf: []const u8, pathname: string, loader: Loader) OutputFile {
+ pub fn initBuf(buf: []const u8, allocator: std.mem.Allocator, pathname: string, loader: Loader) OutputFile {
return .{
.loader = loader,
.input = Fs.Path.init(pathname),
.size = buf.len,
- .value = .{ .buffer = buf },
+ .value = .{
+ .buffer = .{
+ .bytes = buf,
+ .allocator = allocator,
+ },
+ },
};
}
@@ -2077,12 +2087,14 @@ pub const OutputFile = struct {
.move => this.value.move.toJS(globalObject, this.loader),
.copy => this.value.copy.toJS(globalObject, this.loader),
.buffer => |buffer| brk: {
- var blob = globalObject.allocator().create(JSC.WebCore.Blob) catch unreachable;
- blob.* = JSC.WebCore.Blob.init(@constCast(buffer), bun.default_allocator, globalObject);
+ var blob = bun.default_allocator.create(JSC.WebCore.Blob) catch unreachable;
+ blob.* = JSC.WebCore.Blob.init(@constCast(buffer.bytes), buffer.allocator, globalObject);
blob.store.?.mime_type = this.loader.toMimeType();
blob.content_type = blob.store.?.mime_type.value;
- blob.allocator = globalObject.allocator();
- break :brk blob.toJS(globalObject);
+ blob.allocator = bun.default_allocator;
+ const blob_jsvalue = blob.toJS(globalObject);
+ blob_jsvalue.ensureStillAlive();
+ break :brk blob_jsvalue;
},
};
}