Skip to content

Commit

Permalink
fix: Missing markObjDirty
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Aug 4, 2024
1 parent 36c35fc commit 4f2dc9c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Chunk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub const OpCode = enum(u8) {
/// A chunk of code to execute
const Self = @This();

pub const max_constants: u24 = std.math.maxInt(u24);
pub const max_constants = std.math.maxInt(u24);

allocator: std.mem.Allocator,
/// AST
Expand Down
1 change: 1 addition & 0 deletions src/builtin/list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub fn sort(ctx: *NativeCtx) c_int {
},
lessThan,
);
ctx.vm.gc.markObjDirty(self.toObj()) catch @panic("Out of memory");

ctx.vm.push(self.toValue());

Expand Down
1 change: 1 addition & 0 deletions src/builtin/map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ pub fn sort(ctx: *NativeCtx) c_int {
.map = self,
},
);
ctx.vm.gc.markObjDirty(self.toObj()) catch @panic("Out of memory");

ctx.vm.push(self.toValue());

Expand Down
42 changes: 32 additions & 10 deletions src/lib/buzz_os.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ pub export fn env(ctx: *api.NativeCtx) c_int {

// FIXME: don't use std.posix directly
if (std.posix.getenv(key_slice)) |value| {
ctx.vm.bz_pushString(api.ObjString.bz_string(ctx.vm, if (value.len > 0) @as([*]const u8, @ptrCast(value)) else null, value.len) orelse {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
unreachable;
});
ctx.vm.bz_pushString(
api.ObjString.bz_string(
ctx.vm,
if (value.len > 0) @as([*]const u8, @ptrCast(value)) else null,
value.len,
) orelse {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
unreachable;
},
);

return 1;
}
Expand All @@ -48,7 +54,11 @@ pub export fn env(ctx: *api.NativeCtx) c_int {
fn sysTempDir() []const u8 {
return switch (builtin.os.tag) {
.windows => unreachable, // TODO: GetTempPath
else => std.posix.getenv("TMPDIR") orelse std.posix.getenv("TMP") orelse std.posix.getenv("TEMP") orelse std.posix.getenv("TEMPDIR") orelse "/tmp",
else => std.posix.getenv("TMPDIR") orelse
std.posix.getenv("TMP") orelse
std.posix.getenv("TEMP") orelse
std.posix.getenv("TEMPDIR") orelse
"/tmp",
};
}

Expand Down Expand Up @@ -77,7 +87,10 @@ pub export fn tmpFilename(ctx: *api.NativeCtx) c_int {
unreachable;
};

var random_part_b64 = std.ArrayList(u8).initCapacity(api.VM.allocator, std.base64.standard.Encoder.calcSize(random_part.items.len)) catch {
var random_part_b64 = std.ArrayList(u8).initCapacity(
api.VM.allocator,
std.base64.standard.Encoder.calcSize(random_part.items.len),
) catch {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
unreachable;
};
Expand All @@ -94,10 +107,19 @@ pub export fn tmpFilename(ctx: *api.NativeCtx) c_int {
unreachable;
};

ctx.vm.bz_pushString(api.ObjString.bz_string(ctx.vm, if (final.items.len > 0) @as([*]const u8, @ptrCast(final.items)) else null, final.items.len) orelse {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
unreachable;
});
ctx.vm.bz_pushString(
api.ObjString.bz_string(
ctx.vm,
if (final.items.len > 0)
@as([*]const u8, @ptrCast(final.items))
else
null,
final.items.len,
) orelse {
ctx.vm.bz_panic("Out of memory", "Out of memory".len);
unreachable;
},
);

return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/errors.buzz
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ export object UnderflowError {
}
export object UnexpectedError {
str message = "UnexpectedError",
}
}

0 comments on commit 4f2dc9c

Please sign in to comment.