Open fzn0x opened 1 month ago
@fzn0x, the latest version of Bun is v1.1.18, but this crash was reported on Bun v1.1.8.
Are you able to reproduce this crash on the latest version of Bun?
bun upgrade
@fzn0x, the latest version of Bun is v1.1.18, but this crash was reported on Bun v1.1.8.
Are you able to reproduce this crash on the latest version of Bun?
bun upgrade
Yes
Alternative is using bun.ffi:
import { dlopen, FFIType } from "bun:ffi";
import { join } from "path";
// Define the path to the shared library
const libraryPath = join(process.cwd(), `libexample.so`);
console.log(`Loading library from: ${libraryPath}`);
// Define the interface for the C library
const lib = dlopen(libraryPath, {
add: {
args: [FFIType.i32, FFIType.i32],
returns: FFIType.i32,
},
});
// Use the C function
const result = lib.symbols.add(5, 3);
console.log(`Result of add(5, 3): ${result}`);
I hope we have cross-runtime solution to run ffi
I don't know why it so slow, compared with JS written functions
Loading library from: D:\node-gyp\libexample.so
cpu: 12th Gen Intel(R) Core(TM) i7-12700F
runtime: bun 1.1.19 (x64-win32)
benchmark time (avg) (min … max) p75 p99 p999
------------------------------------------------- -----------------------------
• group
------------------------------------------------- -----------------------------
C - add 13.8 ns/iter (12.3 ns … 430 ns) 12.99 ns 35.64 ns 181 ns
JS - add 257 ps/iter (244 ps … 25.05 ns) 244 ps 342 ps 439 ps
How can we reproduce the crash?
Step 1: Set Up the Project
bun init
Step 2: Create the C Code
Step 3: Compile the C Code
Step 4: Create the TypeScript Code
Step 5: Run the TypeScript Code
bun run index.ts
Relevant log output
Stack Trace (bun.report)
Bun v1.1.8 (
889ec13
) on windows x86_64_baseline [RunCommand]panic: napi: napi_create_reference Error::Error
debug.zig:373
:panicExtra
debug.zig:348
:panic
Global.zig:183
:panic
bun.zig:1341
:lenSliceTo
0x8bd8
in node.napi.node0xd5e8
in node.napi.node0x7503
in node.napi.node0xbf9d
in node.napi.node0x810f
in node.napi.node0x7141
in node.napi.node