Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions test/js/bun/ffi/ffi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,10 @@ uint32_t add_uint32_t(uint32_t a, uint32_t b) { return a + b; }
uint64_t add_uint64_t(uint64_t a, uint64_t b) { return a + b; }

FFI_EXPORT void *ptr_should_point_to_42_as_int32_t();
FFI_EXPORT void *getNoopDeallocatorCallback();

static int32_t ffi_static_42 = 42;
void *ptr_should_point_to_42_as_int32_t() { return &ffi_static_42; }

static void noop_deallocator(void *ptr, void *ctx) { (void)ptr; (void)ctx; }
void *getNoopDeallocatorCallback() { return &noop_deallocator; }

static uint8_t buffer_with_deallocator[128];
static int deallocatorCalled;
FFI_EXPORT void deallocator(void *ptr, void *userData) { deallocatorCalled++; }
Expand Down
12 changes: 4 additions & 8 deletions test/js/bun/ffi/ffi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,6 @@ function getTypes(fast) {
returns: "ptr",
args: [],
},
getNoopDeallocatorCallback: {
returns: "ptr",
args: [],
},
getDeallocatorBuffer: {
returns: "ptr",
args: [],
Expand Down Expand Up @@ -382,7 +378,6 @@ function ffiRunner(fast) {
is_null,
does_pointer_equal_42_as_int32_t,
ptr_should_point_to_42_as_int32_t,
getNoopDeallocatorCallback,
cb_identity_true,
cb_identity_false,
cb_identity_42_char,
Expand Down Expand Up @@ -493,11 +488,12 @@ function ffiRunner(fast) {
expect(cptr != 0).toBe(true);
expect(typeof cptr === "number").toBe(true);
expect(does_pointer_equal_42_as_int32_t(cptr)).toBe(true);
const noopDeallocator = getNoopDeallocatorCallback();
{
const buffer = toBuffer(cptr, 0, 4, noopDeallocator);
// No finalizer: both views borrow `cptr` (static storage in the fixture),
// so the GC below must not free it. See oven-sh/bun#35405.
const buffer = toBuffer(cptr, 0, 4);
expect(buffer.readInt32(0)).toBe(42);
expect(new DataView(toArrayBuffer(cptr, 0, 4, noopDeallocator), 0, 4).getInt32(0, true)).toBe(42);
expect(new DataView(toArrayBuffer(cptr, 0, 4), 0, 4).getInt32(0, true)).toBe(42);
expect(ptr(buffer)).toBe(cptr);
}
Bun.gc(true);
Expand Down
Loading