summaryrefslogtreecommitdiff
path: root/ext/ffi
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-07-09 18:41:07 +0530
committerGitHub <noreply@github.com>2022-07-09 18:41:07 +0530
commit132c761e87679aec52b9ed8324ee2a4b00705620 (patch)
tree19c83a4e474c1e860bdee5e77d12395e1307f402 /ext/ffi
parent3da182b0b86d93000d4473188f361ffa2de9fb73 (diff)
fix(ext/ffi): allow opting out of fast ffi calls (#15131)
Diffstat (limited to 'ext/ffi')
-rw-r--r--ext/ffi/lib.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs
index d998c8138..a5a156727 100644
--- a/ext/ffi/lib.rs
+++ b/ext/ffi/lib.rs
@@ -72,6 +72,7 @@ struct Symbol {
ptr: libffi::middle::CodePtr,
parameter_types: Vec<NativeType>,
result_type: NativeType,
+ can_callback: bool,
}
#[allow(clippy::non_send_fields_in_send_ty)]
@@ -433,6 +434,13 @@ struct ForeignFunction {
result: NativeType,
#[serde(rename = "nonblocking")]
non_blocking: Option<bool>,
+ #[serde(rename = "callback")]
+ #[serde(default = "default_callback")]
+ callback: bool,
+}
+
+fn default_callback() -> bool {
+ false
}
// ForeignStatic's name and type fields are read and used by
@@ -599,6 +607,7 @@ where
ptr,
parameter_types: foreign_fn.parameters,
result_type: foreign_fn.result,
+ can_callback: foreign_fn.callback,
});
resource.symbols.insert(symbol_key, sym.clone());
@@ -689,7 +698,8 @@ fn make_sync_fn<'s>(
) -> v8::Local<'s, v8::Function> {
let mut fast_ffi_templ = None;
- if !sym.parameter_types.iter().any(|t| !is_fast_api(*t))
+ if !sym.can_callback
+ && !sym.parameter_types.iter().any(|t| !is_fast_api(*t))
&& is_fast_api(sym.result_type)
{
let mut args = sym
@@ -941,6 +951,7 @@ where
result_type,
cif,
ptr: fun_ptr,
+ ..
} = symbol;
let mut ffi_args: Vec<NativeValue> =
Vec::with_capacity(parameter_types.len());
@@ -1814,6 +1825,7 @@ fn op_ffi_call_nonblocking<'scope>(
ptr,
parameter_types,
result_type,
+ ..
} = symbol.clone();
ffi_call(call_args, &cif, ptr, &parameter_types, result_type)
});