From 1add5a9a757b3e48eba9d1b1c98affc46042f7dd Mon Sep 17 00:00:00 2001 From: Skgland Date: Sun, 28 Sep 2025 18:17:35 +0200 Subject: [PATCH] add ffi types for non-fixed-sized integers --- src/ffi.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/ffi.rs b/src/ffi.rs index b780e7b3..8fd90c95 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -399,9 +399,49 @@ enum FfiType { Struct(Atom), } +trait ToFfiType { + const TYPE: FfiType; +} + +macro_rules! impl_to_ffi_type { + ($($t:ty => $v:ident);*$(;)?) => { + $( + impl ToFfiType for $t { + const TYPE: FfiType = FfiType::$v; + } + )* + }; +} + +impl_to_ffi_type!( + u8 => U8; + i8 => I8; + u16 => U16; + i16 => I16; + u32 => U32; + i32 => I32; + u64 => U64; + i64 => I64; + f32 => F32; + f64 => F64; +); + impl FfiType { fn from_atom(atom: &Atom) -> Self { match atom { + atom!("char") => ::TYPE, + atom!("uchar") => ::TYPE, + atom!("schar") => ::TYPE, + atom!("short") => ::TYPE, + atom!("ushort") => ::TYPE, + atom!("int") => ::TYPE, + atom!("uint") => ::TYPE, + atom!("long") => ::TYPE, + atom!("ulong") => ::TYPE, + atom!("longlong") => ::TYPE, + atom!("ulonglong") => ::TYPE, + atom!("float") => ::TYPE, + atom!("double") => ::TYPE, atom!("sint64") | atom!("i64") => Self::I64, atom!("sint32") | atom!("i32") => Self::I32, atom!("sint16") | atom!("i16") => Self::I16, -- 2.54.0