From 79b4bad41928bce96ee66d849be1ddbcf5e3b276 Mon Sep 17 00:00:00 2001 From: maciektr Date: Wed, 13 Mar 2024 11:51:19 +0100 Subject: [PATCH] Remove macro_commons commit-id:6c362eae --- .../cairo-lang-macro-attributes/src/lib.rs | 10 ---------- plugins/cairo-lang-macro/src/lib.rs | 15 ++++++++++++++ scarb/tests/build_cairo_plugin.rs | 20 +++++-------------- 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/plugins/cairo-lang-macro-attributes/src/lib.rs b/plugins/cairo-lang-macro-attributes/src/lib.rs index 1347361b7..63e3d8463 100644 --- a/plugins/cairo-lang-macro-attributes/src/lib.rs +++ b/plugins/cairo-lang-macro-attributes/src/lib.rs @@ -28,13 +28,3 @@ pub fn attribute_macro(_args: TokenStream, input: TokenStream) -> TokenStream { }; TokenStream::from(expanded) } - -#[proc_macro] -pub fn macro_commons(_input: TokenStream) -> TokenStream { - TokenStream::from(quote! { - #[no_mangle] - pub unsafe extern "C" fn free_result(result: cairo_lang_macro_stable::StableProcMacroResult) { - cairo_lang_macro::ProcMacroResult::from_owned_stable(result); - } - }) -} diff --git a/plugins/cairo-lang-macro/src/lib.rs b/plugins/cairo-lang-macro/src/lib.rs index 6613c7892..acd3d27e0 100644 --- a/plugins/cairo-lang-macro/src/lib.rs +++ b/plugins/cairo-lang-macro/src/lib.rs @@ -9,6 +9,21 @@ use std::num::NonZeroU8; use std::slice; use std::vec::IntoIter; +/// Free the memory allocated for the [`StableProcMacroResult`]. +/// +/// This function needs to be accessible through the FFI interface, +/// of the dynamic library re-exporting it. +/// The name of this function will not be mangled by the Rust compiler (through the `no_mangle` attribute). +/// This means that the name will not be extended with neither additional prefixes nor suffixes +/// by the Rust compiler and the corresponding symbol will be available by the name of the function as id. +/// +/// # Safety +#[no_mangle] +#[doc(hidden)] +pub unsafe extern "C" fn free_result(result: StableProcMacroResult) { + ProcMacroResult::from_owned_stable(result); +} + #[derive(Debug)] pub enum ProcMacroResult { /// Plugin has not taken any action. diff --git a/scarb/tests/build_cairo_plugin.rs b/scarb/tests/build_cairo_plugin.rs index f49cf0b14..ca6f2c214 100644 --- a/scarb/tests/build_cairo_plugin.rs +++ b/scarb/tests/build_cairo_plugin.rs @@ -91,9 +91,7 @@ fn simple_project_with_code(t: &impl PathChild, code: impl ToString) { fn simple_project(t: &impl PathChild) { let code = indoc! {r#" - use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons}; - - macro_commons!(); + use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro}; #[attribute_macro] pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult { @@ -268,9 +266,7 @@ fn can_emit_plugin_warning() { simple_project_with_code( &t, indoc! {r#" - use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons, Diagnostic}; - - macro_commons!(); + use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, Diagnostic}; #[attribute_macro] pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult { @@ -317,10 +313,8 @@ fn can_emit_plugin_error() { simple_project_with_code( &t, indoc! {r#" - use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons, Diagnostic}; + use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, Diagnostic}; - macro_commons!(); - #[attribute_macro] pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult { let _code = token_stream.to_string(); @@ -366,9 +360,7 @@ fn can_remove_original_node() { simple_project_with_code( &t, indoc! {r#" - use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons}; - - macro_commons!(); + use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro}; #[attribute_macro] pub fn some_macro(_: TokenStream) -> ProcMacroResult { @@ -415,9 +407,7 @@ fn can_replace_original_node() { simple_project_with_code( &t, indoc! {r##" - use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro, macro_commons}; - - macro_commons!(); + use cairo_lang_macro::{ProcMacroResult, TokenStream, attribute_macro}; #[attribute_macro] pub fn some_macro(token_stream: TokenStream) -> ProcMacroResult {