Slight FFI tweaks to make deno less crashy on macos

This commit is contained in:
Timothy Warren 2024-01-11 11:08:48 -05:00
parent 15496646d6
commit f19fc1d2e0
3 changed files with 20 additions and 9 deletions

View File

@ -37,12 +37,20 @@ try {
}
const { tcgetattr, tcsetattr, cfmakeraw } = cStdLib.symbols;
let closed = false;
const BunFFI: IFFI = {
tcgetattr,
tcsetattr,
cfmakeraw,
getPointer: ptr,
close: cStdLib.close,
close: () => {
if (!closed) {
cStdLib.close();
closed = true;
}
// Do nothing if FFI library was already closed
},
};
export default BunFFI;

View File

@ -43,7 +43,7 @@ class Termios {
* The pointer to the termios struct
* @private
*/
#ptr: unknown;
readonly #ptr: unknown;
constructor(ffi: IFFI) {
this.#ffi = ffi;

View File

@ -1,20 +1,20 @@
// Deno-specific ffi code
import { IFFI } from '../common/runtime.ts';
let libSuffix = '';
let suffix = '';
switch (Deno.build.os) {
case 'windows':
libSuffix = 'dll';
suffix = 'dll';
break;
case 'darwin':
libSuffix = 'dylib';
suffix = 'dylib';
break;
default:
libSuffix = 'so.6';
suffix = 'so.6';
break;
}
const cSharedLib = `libc.${libSuffix}`;
const cSharedLib = `libc.${suffix}`;
const cStdLib = Deno.dlopen(
cSharedLib,
{
@ -41,8 +41,11 @@ const DenoFFI: IFFI = {
cfmakeraw,
getPointer: Deno.UnsafePointer.of,
close: () => {
if (closed === false) {
cStdLib.close();
if (!closed) {
// Closing appears to do bad things on macOS
if (Deno.build.os !== 'darwin') {
cStdLib.close();
}
closed = true;
}