From 645b8d58f60de35d134b48da170b268223bdf009 Mon Sep 17 00:00:00 2001 From: Soispha Date: Wed, 27 Mar 2024 22:11:12 +0100 Subject: [PATCH] fix(macros/generate/host/c/function): Actually call the callback function Previously, the generated c wrapper function did not call the callback correctly. --- src/macros/generate/convert/host/c/function/mod.rs | 9 ++++----- src/macros/generate/convert/host/c/namespace/mod.rs | 9 +++++++-- src/macros/generate/convert/host/c/type/named_type.rs | 9 +-------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/macros/generate/convert/host/c/function/mod.rs b/src/macros/generate/convert/host/c/function/mod.rs index ecbfb43..3d5040e 100644 --- a/src/macros/generate/convert/host/c/function/mod.rs +++ b/src/macros/generate/convert/host/c/function/mod.rs @@ -34,13 +34,12 @@ impl Function { let inputs: Vec = self .inputs .iter() - // FIXME(@soispha): This was `named_type_to_rust_trixy` <2024-03-25> - .map(NamedType::to_rust) + .map(NamedType::to_c) .collect(); let callback_function = format_ident!("{}", config.callback_function); - let command_value: TokenStream2 = self.identifier.to_c_with_path(&namespaces); + let command_value: TokenStream2 = self.to_rust_path(&namespaces); if let Some(r#type) = &self.output { let output_ident = r#type.to_c(); @@ -63,7 +62,7 @@ impl Function { quote! { #[no_mangle] pub extern "C" fn #ident(#(#inputs),*) -> core::ffi::c_int { - #callback_function (#command_value); + #callback_function (crate :: #command_value); return 1; } } @@ -109,7 +108,7 @@ impl Function { if namespaces.is_empty() { quote! { - Commands:: #function_ident + Commands :: #function_ident } } else { let nasp_pascal_ident = namespaces.last().expect("We checked").to_rust_pascalized(); diff --git a/src/macros/generate/convert/host/c/namespace/mod.rs b/src/macros/generate/convert/host/c/namespace/mod.rs index ae795b3..0413d0e 100644 --- a/src/macros/generate/convert/host/c/namespace/mod.rs +++ b/src/macros/generate/convert/host/c/namespace/mod.rs @@ -21,7 +21,7 @@ */ use proc_macro2::TokenStream as TokenStream2; -use quote::quote; +use quote::{format_ident, quote}; use crate::{ macros::config::trixy::TrixyConfig, @@ -46,13 +46,18 @@ impl Namespace { .collect(); let structures: TokenStream2 = self.structures.iter().map(Structure::to_c).collect(); let enumerations: TokenStream2 = self.enumerations.iter().map(Enumeration::to_c).collect(); + + let callback_function = format_ident!("{}", config.callback_function); quote! { pub mod #ident { + #[allow(unused_imports)] + use crate :: #callback_function; + #enumerations #structures + #additional_functions } #functions - #additional_functions } } } diff --git a/src/macros/generate/convert/host/c/type/named_type.rs b/src/macros/generate/convert/host/c/type/named_type.rs index 593e4cc..a8f2e7a 100644 --- a/src/macros/generate/convert/host/c/type/named_type.rs +++ b/src/macros/generate/convert/host/c/type/named_type.rs @@ -33,20 +33,13 @@ impl NamedType { #ident : #r#type } } - pub fn to_rust_c_assignment(&self) -> TokenStream2 { - let ident = self.name.to_rust(); - let type_ident = self.r#type.to_c(); - quote! { - #ident : #type_ident - } - } pub fn to_rust_assignment(&self) -> TokenStream2 { let ident = self.name.to_rust(); quote! { #ident : match #ident.try_into() { Ok(ok) => ok, Err(err) => { - trixy::types::traits::errno::set(err); + trixy::types::traits::errno::set(err.into()); return 0; } }