Skip to content

Commit

Permalink
Fix: expand with actual expansion name instead of package name
Browse files Browse the repository at this point in the history
commit-id:2136619c
  • Loading branch information
maciektr committed Mar 22, 2024
1 parent bea137c commit 52f9b40
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugins/cairo-lang-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub unsafe extern "C" fn expand(
None
}
})
.expect("proc macro not found");
.expect("procedural macro not found");
let result = fun(token_stream);
let result: StableProcMacroResult = result.into_stable();
cairo_lang_macro_stable::StableResultWrapper {
Expand Down
10 changes: 6 additions & 4 deletions scarb/src/compiler/plugin/proc_macro/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,15 @@ impl ProcMacroInstance {
///
/// Please be aware that the memory management of values passing the FFI-barrier is tricky.
/// The memory must be freed on the same side of the barrier, where the allocation was made.
pub(crate) fn generate_code(&self, token_stream: TokenStream) -> ProcMacroResult {
pub(crate) fn generate_code(
&self,
item_name: SmolStr,
token_stream: TokenStream,
) -> ProcMacroResult {
// This must be manually freed with call to from_owned_stable.
let stable_token_stream = token_stream.into_stable();
// Allocate proc macro name.
let item_name = CString::new(self.package_id.name.to_string())
.unwrap()
.into_raw();
let item_name = CString::new(item_name.to_string()).unwrap().into_raw();
// Call FFI interface for code expansion.
// Note that `stable_result` has been allocated by the dynamic library.
let stable_result = (self.plugin.vtable.expand)(item_name, stable_token_stream);
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/compiler/plugin/proc_macro/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl MacroPlugin for ProcMacroHostPlugin {
.iter()
.find(|m| m.package_id() == input.package_id)
.expect("procedural macro must be registered in proc macro host");
match instance.generate_code(token_stream.clone()) {
match instance.generate_code(input.expansion.name.clone(), token_stream.clone()) {
ProcMacroResult::Replace {
token_stream: new_token_stream,
aux_data: new_aux_data,
Expand Down

0 comments on commit 52f9b40

Please sign in to comment.