Skip to content

Commit

Permalink
fix(ext/ffi): return u64/i64 as bigints from nonblocking ffi calls (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
littledivy authored and bartlomieju committed Oct 25, 2024
1 parent 84195af commit bb3c8e2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ext/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ dynasmrt = "1.2.3"
libffi = "=3.2.0"
libffi-sys = "=2.3.0"
log.workspace = true
num-bigint.workspace = true
serde.workspace = true
serde-value = "0.7"
serde_json = "1.0"
Expand Down
27 changes: 15 additions & 12 deletions ext/ffi/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ use crate::FfiPermissions;
use crate::ForeignFunction;
use deno_core::op2;
use deno_core::serde_json::Value;
use deno_core::serde_v8::BigInt as V8BigInt;
use deno_core::serde_v8::ExternalPointer;
use deno_core::unsync::spawn_blocking;
use deno_core::v8;
use deno_core::OpState;
use deno_core::ResourceId;
use libffi::middle::Arg;
use num_bigint::BigInt;
use serde::Serialize;
use std::cell::RefCell;
use std::ffi::c_void;
Expand Down Expand Up @@ -202,6 +204,7 @@ where
#[serde(untagged)]
pub enum FfiValue {
Value(Value),
BigInt(V8BigInt),
External(ExternalPointer),
}

Expand Down Expand Up @@ -251,18 +254,18 @@ fn ffi_call(
NativeType::I32 => {
FfiValue::Value(Value::from(cif.call::<i32>(fun_ptr, &call_args)))
}
NativeType::U64 => {
FfiValue::Value(Value::from(cif.call::<u64>(fun_ptr, &call_args)))
}
NativeType::I64 => {
FfiValue::Value(Value::from(cif.call::<i64>(fun_ptr, &call_args)))
}
NativeType::USize => {
FfiValue::Value(Value::from(cif.call::<usize>(fun_ptr, &call_args)))
}
NativeType::ISize => {
FfiValue::Value(Value::from(cif.call::<isize>(fun_ptr, &call_args)))
}
NativeType::U64 => FfiValue::BigInt(V8BigInt::from(BigInt::from(
cif.call::<u64>(fun_ptr, &call_args),
))),
NativeType::I64 => FfiValue::BigInt(V8BigInt::from(BigInt::from(
cif.call::<i64>(fun_ptr, &call_args),
))),
NativeType::USize => FfiValue::BigInt(V8BigInt::from(BigInt::from(
cif.call::<usize>(fun_ptr, &call_args),
))),
NativeType::ISize => FfiValue::BigInt(V8BigInt::from(BigInt::from(
cif.call::<isize>(fun_ptr, &call_args),
))),
NativeType::F32 => {
FfiValue::Value(Value::from(cif.call::<f32>(fun_ptr, &call_args)))
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ffi/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ fn basic() {
579.912\n\
579.912\n\
579\n\
8589934590\n\
-8589934590\n\
8589934590\n\
-8589934590\n\
8589934590n\n\
-8589934590n\n\
8589934590n\n\
-8589934590n\n\
9007199254740992n\n\
9007199254740992n\n\
-9007199254740992n\n\
Expand Down

0 comments on commit bb3c8e2

Please sign in to comment.