From 007e1b4bd595b99f5d7b8df08e91354d6e4f0bf2 Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Tue, 12 Jul 2022 13:44:54 +0300 Subject: [PATCH] fix(ext/ffi): i64 arg to C mapping was wrong (#15162) --- ext/ffi/jit_trampoline.rs | 54 ++++++++++++++++++++++++++++++--------- ext/ffi/lib.rs | 6 ++--- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/ext/ffi/jit_trampoline.rs b/ext/ffi/jit_trampoline.rs index 2c3c519c05..2fd078d607 100644 --- a/ext/ffi/jit_trampoline.rs +++ b/ext/ffi/jit_trampoline.rs @@ -22,10 +22,8 @@ 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::U64 | NativeType::USize => "uint64_t", + NativeType::I64 | NativeType::ISize => "int64_t", NativeType::Void => "void", NativeType::F32 => "float", NativeType::F64 => "double", @@ -129,23 +127,43 @@ mod tests { fn test_gen_trampoline() { assert_eq!( codegen(vec![], NativeType::Void), - "#include \n\nextern void func();\n\nvoid func_trampoline(void* recv) {\n return func();\n}\n\n" + "#include \n\n\ + extern void func();\n\n\ + void func_trampoline(void* recv) {\ + \n return func();\n\ + }\n\n" ); assert_eq!( codegen(vec![NativeType::U32, NativeType::U32], NativeType::U32), - "#include \n\nextern uint32_t func(uint32_t p0, uint32_t p1);\n\nuint32_t func_trampoline(void* recv, uint32_t p0, uint32_t p1) {\n return func(p0, p1);\n}\n\n" + "#include \n\n\ + extern uint32_t func(uint32_t p0, uint32_t p1);\n\n\ + uint32_t func_trampoline(void* recv, uint32_t p0, uint32_t p1) {\ + \n return func(p0, p1);\n\ + }\n\n" ); assert_eq!( codegen(vec![NativeType::I32, NativeType::I32], NativeType::I32), - "#include \n\nextern int32_t func(int32_t p0, int32_t p1);\n\nint32_t func_trampoline(void* recv, int32_t p0, int32_t p1) {\n return func(p0, p1);\n}\n\n" + "#include \n\n\ + extern int32_t func(int32_t p0, int32_t p1);\n\n\ + int32_t func_trampoline(void* recv, int32_t p0, int32_t p1) {\ + \n return func(p0, p1);\n\ + }\n\n" ); assert_eq!( codegen(vec![NativeType::F32, NativeType::F32], NativeType::F32), - "#include \n\nextern float func(float p0, float p1);\n\nfloat func_trampoline(void* recv, float p0, float p1) {\n return func(p0, p1);\n}\n\n" + "#include \n\n\ + extern float func(float p0, float p1);\n\n\ + float func_trampoline(void* recv, float p0, float p1) {\ + \n return func(p0, p1);\n\ + }\n\n" ); assert_eq!( codegen(vec![NativeType::F64, NativeType::F64], NativeType::F64), - "#include \n\nextern double func(double p0, double p1);\n\ndouble func_trampoline(void* recv, double p0, double p1) {\n return func(p0, p1);\n}\n\n" + "#include \n\n\ + extern double func(double p0, double p1);\n\n\ + double func_trampoline(void* recv, double p0, double p1) {\ + \n return func(p0, p1);\n\ + }\n\n" ); } @@ -153,15 +171,27 @@ mod tests { fn test_gen_trampoline_implicit_cast() { assert_eq!( codegen(vec![NativeType::I8, NativeType::U8], NativeType::I8), - "#include \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" + "#include \n\n\ + extern int8_t func(int8_t p0, uint8_t p1);\n\n\ + int8_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 \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" + "#include \n\n\ + extern void func(int64_t p0, uint64_t p1);\n\n\ + void func_trampoline(void* recv, int64_t p0, uint64_t p1) {\ + \n return func(p0, p1);\n\ + }\n\n" ); assert_eq!( codegen(vec![NativeType::USize, NativeType::USize], NativeType::U32), - "#include \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" + "#include \n\n\ + extern uint32_t func(uint64_t p0, uint64_t p1);\n\n\ + uint32_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 eddfed0393..737ea9db2c 100644 --- a/ext/ffi/lib.rs +++ b/ext/ffi/lib.rs @@ -673,10 +673,8 @@ 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::I64 - | NativeType::ISize - | NativeType::U64 - | NativeType::USize => fast_api::Type::Uint64, + NativeType::I64 | NativeType::ISize => fast_api::Type::Int64, + NativeType::U64 | NativeType::USize => fast_api::Type::Uint64, NativeType::Function | NativeType::Pointer => { panic!("Cannot be fast api") }