summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/ffi/jit_trampoline.rs16
-rw-r--r--ext/ffi/lib.rs18
2 files changed, 26 insertions, 8 deletions
diff --git a/ext/ffi/jit_trampoline.rs b/ext/ffi/jit_trampoline.rs
index 40c14dfb0..2c3c519c0 100644
--- a/ext/ffi/jit_trampoline.rs
+++ b/ext/ffi/jit_trampoline.rs
@@ -22,6 +22,10 @@ fn native_arg_to_c(ty: &NativeType) -> &'static str {
match ty {
NativeType::U8 | NativeType::U16 | NativeType::U32 => "uint32_t",
NativeType::I8 | NativeType::I16 | NativeType::I32 => "int32_t",
+ NativeType::U64
+ | NativeType::I64
+ | NativeType::USize
+ | NativeType::ISize => "uint64_t",
NativeType::Void => "void",
NativeType::F32 => "float",
NativeType::F64 => "double",
@@ -40,6 +44,8 @@ fn native_to_c(ty: &NativeType) -> &'static str {
NativeType::Void => "void",
NativeType::F32 => "float",
NativeType::F64 => "double",
+ NativeType::U64 | NativeType::USize => "uint64_t",
+ NativeType::I64 | NativeType::ISize => "int64_t",
_ => unimplemented!(),
}
}
@@ -148,6 +154,14 @@ mod tests {
assert_eq!(
codegen(vec![NativeType::I8, NativeType::U8], NativeType::I8),
"#include <stdint.h>\n\nextern int8_t func(int8_t p0, uint8_t p1);\n\nint8_t func_trampoline(void* recv, int32_t p0, uint32_t p1) {\n return func(p0, p1);\n}\n\n"
- )
+ );
+ assert_eq!(
+ codegen(vec![NativeType::ISize, NativeType::U64], NativeType::Void),
+ "#include <stdint.h>\n\nextern void func(int64_t p0, uint64_t p1);\n\nvoid func_trampoline(void* recv, uint64_t p0, uint64_t p1) {\n return func(p0, p1);\n}\n\n"
+ );
+ assert_eq!(
+ codegen(vec![NativeType::USize, NativeType::USize], NativeType::U32),
+ "#include <stdint.h>\n\nextern uint32_t func(uint64_t p0, uint64_t p1);\n\nuint32_t func_trampoline(void* recv, uint64_t p0, uint64_t p1) {\n return func(p0, p1);\n}\n\n"
+ );
}
}
diff --git a/ext/ffi/lib.rs b/ext/ffi/lib.rs
index feb879aba..eddfed039 100644
--- a/ext/ffi/lib.rs
+++ b/ext/ffi/lib.rs
@@ -673,12 +673,11 @@ impl From<&NativeType> for fast_api::Type {
NativeType::F32 => fast_api::Type::Float32,
NativeType::F64 => fast_api::Type::Float64,
NativeType::Void => fast_api::Type::Void,
- NativeType::Function
- | NativeType::Pointer
- | NativeType::I64
+ NativeType::I64
| NativeType::ISize
| NativeType::U64
- | NativeType::USize => {
+ | NativeType::USize => fast_api::Type::Uint64,
+ NativeType::Function | NativeType::Pointer => {
panic!("Cannot be fast api")
}
}
@@ -686,7 +685,7 @@ impl From<&NativeType> for fast_api::Type {
}
#[cfg(not(target_os = "windows"))]
-fn is_fast_api(rv: NativeType) -> bool {
+fn is_fast_api_rv(rv: NativeType) -> bool {
!matches!(
rv,
NativeType::Function
@@ -698,6 +697,11 @@ fn is_fast_api(rv: NativeType) -> bool {
)
}
+#[cfg(not(target_os = "windows"))]
+fn is_fast_api_arg(rv: NativeType) -> bool {
+ !matches!(rv, NativeType::Function | NativeType::Pointer)
+}
+
// Create a JavaScript function for synchronous FFI call to
// the given symbol.
fn make_sync_fn<'s>(
@@ -714,8 +718,8 @@ fn make_sync_fn<'s>(
let mut fast_allocations: Option<*mut ()> = None;
#[cfg(not(target_os = "windows"))]
if !sym.can_callback
- && !sym.parameter_types.iter().any(|t| !is_fast_api(*t))
- && is_fast_api(sym.result_type)
+ && !sym.parameter_types.iter().any(|t| !is_fast_api_arg(*t))
+ && is_fast_api_rv(sym.result_type)
{
let ret = fast_api::Type::from(&sym.result_type);