diff options
author | 2022-11-08 00:28:14 -0800 | |
---|---|---|
committer | 2022-11-08 00:28:14 -0800 | |
commit | 3e9bb6859b5bd832da73ba48ede24eaf9cc1cbee (patch) | |
tree | 7747f8dadd1ab8a85c8b142fe605301ef0580f1b | |
parent | 86f0b08b8d37389ab488bc413fd450c403d58dea (diff) | |
download | bun-3e9bb6859b5bd832da73ba48ede24eaf9cc1cbee.tar.gz bun-3e9bb6859b5bd832da73ba48ede24eaf9cc1cbee.tar.zst bun-3e9bb6859b5bd832da73ba48ede24eaf9cc1cbee.zip |
Stack allocate arguments to make it actually threadsafe
-rw-r--r-- | src/bun.js/api/FFI.h | 2 | ||||
-rw-r--r-- | src/bun.js/api/ffi.zig | 2 | ||||
-rw-r--r-- | test/bun.js/ffi.test.fixture.callback.c | 3 | ||||
-rw-r--r-- | test/bun.js/ffi.test.fixture.receiver.c | 2 |
4 files changed, 3 insertions, 6 deletions
diff --git a/src/bun.js/api/FFI.h b/src/bun.js/api/FFI.h index 4763c90a3..c218dc69a 100644 --- a/src/bun.js/api/FFI.h +++ b/src/bun.js/api/FFI.h @@ -109,8 +109,6 @@ static EncodedJSValue _FFI_Callback_call(void* ctx, size_t argCount, ZIG_REPR_TY return_value.asZigRepr = FFI_Callback_call(ctx, argCount, args); return return_value; } -static ZIG_REPR_TYPE arguments[100]; - #endif static bool JSVALUE_IS_CELL(EncodedJSValue val) __attribute__((__always_inline__)); diff --git a/src/bun.js/api/ffi.zig b/src/bun.js/api/ffi.zig index e8deffd3d..269557bcc 100644 --- a/src/bun.js/api/ffi.zig +++ b/src/bun.js/api/ffi.zig @@ -1262,6 +1262,8 @@ pub const FFI = struct { if (this.arg_types.items.len > 0) { var arg_buf: [512]u8 = undefined; + try writer.print(" ZIG_REPR_TYPE arguments[{d}];\n", .{this.arg_types.items.len}); + arg_buf[0.."arg".len].* = "arg".*; for (this.arg_types.items) |arg, i| { const printed = std.fmt.bufPrintIntToSlice(arg_buf["arg".len..], i, 10, .lower, .{}); diff --git a/test/bun.js/ffi.test.fixture.callback.c b/test/bun.js/ffi.test.fixture.callback.c index 58e6c482e..9c3c088ce 100644 --- a/test/bun.js/ffi.test.fixture.callback.c +++ b/test/bun.js/ffi.test.fixture.callback.c @@ -111,8 +111,6 @@ static EncodedJSValue _FFI_Callback_call(void* ctx, size_t argCount, ZIG_REPR_TY return_value.asZigRepr = FFI_Callback_call(ctx, argCount, args); return return_value; } -static ZIG_REPR_TYPE arguments[100]; - #endif static bool JSVALUE_IS_CELL(EncodedJSValue val) __attribute__((__always_inline__)); @@ -290,6 +288,7 @@ bool my_callback_function(void* arg0) { #ifdef INJECT_BEFORE INJECT_BEFORE; #endif + ZIG_REPR_TYPE arguments[1]; arguments[0] = PTR_TO_JSVALUE(arg0).asZigRepr; return (bool)JSVALUE_TO_BOOL(_FFI_Callback_call((void*)0x0UL, 1, arguments)); } diff --git a/test/bun.js/ffi.test.fixture.receiver.c b/test/bun.js/ffi.test.fixture.receiver.c index c972c2df1..a507ab3a5 100644 --- a/test/bun.js/ffi.test.fixture.receiver.c +++ b/test/bun.js/ffi.test.fixture.receiver.c @@ -111,8 +111,6 @@ static EncodedJSValue _FFI_Callback_call(void* ctx, size_t argCount, ZIG_REPR_TY return_value.asZigRepr = FFI_Callback_call(ctx, argCount, args); return return_value; } -static ZIG_REPR_TYPE arguments[100]; - #endif static bool JSVALUE_IS_CELL(EncodedJSValue val) __attribute__((__always_inline__)); |