Slight FFI tweaks to make deno less crashy on macos
This commit is contained in:
parent
15496646d6
commit
f19fc1d2e0
@ -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;
|
||||
|
@ -43,7 +43,7 @@ class Termios {
|
||||
* The pointer to the termios struct
|
||||
* @private
|
||||
*/
|
||||
#ptr: unknown;
|
||||
readonly #ptr: unknown;
|
||||
|
||||
constructor(ffi: IFFI) {
|
||||
this.#ffi = ffi;
|
||||
|
@ -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) {
|
||||
if (!closed) {
|
||||
// Closing appears to do bad things on macOS
|
||||
if (Deno.build.os !== 'darwin') {
|
||||
cStdLib.close();
|
||||
}
|
||||
closed = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user