Skip to content

Commit

Permalink
fix(jit): Don't erase in_native_call flag if was already on
Browse files Browse the repository at this point in the history
  • Loading branch information
giann committed Oct 10, 2023
1 parent d813297 commit a514302
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/buzz_api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,7 @@ pub export fn bz_invoke(
self.push(arguments.?[i].*);
}

const was_in_native_call = self.currentFrame().?.in_native_call;
self.currentFrame().?.in_native_call = true;

// TODO: catch properly
Expand All @@ -711,7 +712,7 @@ pub export fn bz_invoke(
self.run();
}

self.currentFrame().?.in_native_call = false;
self.currentFrame().?.in_native_call = was_in_native_call;
}

pub export fn bz_call(
Expand Down
6 changes: 4 additions & 2 deletions src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3873,6 +3873,7 @@ pub const VM = struct {
}

fn callNative(self: *Self, closure: ?*ObjClosure, native: NativeFn, arg_count: u8, catch_value: ?Value) !void {
const was_in_native_call = self.currentFrame().?.in_native_call;
self.currentFrame().?.in_native_call = true;
self.currentFrame().?.native_call_error_value = catch_value;

Expand All @@ -3886,7 +3887,7 @@ pub const VM = struct {
};
const native_return = native(&ctx);

self.currentFrame().?.in_native_call = false;
self.currentFrame().?.in_native_call = was_in_native_call;
self.currentFrame().?.native_call_error_value = null;

if (native_return == 1 or native_return == 0) {
Expand Down Expand Up @@ -3926,6 +3927,7 @@ pub const VM = struct {

// A JIT compiled function pops its stack on its own
fn callCompiled(self: *Self, closure: ?*ObjClosure, native: NativeFn, arg_count: u8, catch_value: ?Value) !void {
const was_in_native_call = self.currentFrame() != null and self.currentFrame().?.in_native_call;
if (self.currentFrame()) |frame| {
frame.in_native_call = true;
frame.native_call_error_value = catch_value;
Expand All @@ -3941,7 +3943,7 @@ pub const VM = struct {
const native_return = native(&ctx);

if (self.currentFrame()) |frame| {
frame.in_native_call = false;
frame.in_native_call = was_in_native_call;
frame.native_call_error_value = null;
}

Expand Down

0 comments on commit a514302

Please sign in to comment.