public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Max R. Carrara" <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH perlmod v2 3/5] macro: function: explicitly pass identifier for generated arg iter
Date: Fri, 24 Jul 2026 16:49:05 +0200	[thread overview]
Message-ID: <20260724144914.658730-4-m.carrara@proxmox.com> (raw)
In-Reply-To: <20260724144914.658730-1-m.carrara@proxmox.com>

The `args` variable that we define in generated code is used in
multiple places, making them implicitly depend on each other.

Make this explicit instead by defining the identifier as a
`syn::Ident` and passing it to / interpolating it into the respective
places.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
 perlmod-macro/src/function.rs | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/perlmod-macro/src/function.rs b/perlmod-macro/src/function.rs
index 3ce0a17..3ca7bd0 100644
--- a/perlmod-macro/src/function.rs
+++ b/perlmod-macro/src/function.rs
@@ -136,18 +136,19 @@ impl<'s> ArgumentAttr<'s> {
 fn extract_argument_code(
     arg_attr: &ArgumentAttr,
     span: Span,
+    arguments_name: &Ident,
     extracted_name: &Ident,
     none_handling: TokenStream,
 ) -> TokenStream {
     match arg_attr.attr_type {
         Some(ArgumentAttrType::TrailingList(_)) => {
             quote_spanned! { span=>
-                let #extracted_name = args.map(::perlmod::Value::from);
+                let #extracted_name = #arguments_name.map(::perlmod::Value::from);
             }
         }
         _ => {
             quote_spanned! { span=>
-                let #extracted_name: ::perlmod::Value = match args.next() {
+                let #extracted_name: ::perlmod::Value = match #arguments_name.next() {
                     Some(arg) => ::perlmod::Value::from(arg),
                     None => #none_handling
                 };
@@ -252,6 +253,8 @@ pub fn handle_function(
         });
     let impl_xs_name = Ident::new(&format!("impl_xs_{name}"), name.span());
 
+    let arguments_name = syn::Ident::new("args", name.span());
+
     let mut trailing_options = 0;
     let mut extract_arguments = TokenStream::new();
     let mut deserialized_arguments = TokenStream::new();
@@ -326,6 +329,7 @@ pub fn handle_function(
         extract_arguments.extend(extract_argument_code(
             &arg_attr,
             span,
+            &arguments_name,
             &extracted_name,
             none_handling,
         ));
@@ -377,7 +381,7 @@ pub fn handle_function(
         );
 
         quote_spanned! { span=>
-            if args.next().is_some() {
+            if #arguments_name.next().is_some() {
                 return Err(::perlmod::Value::new_string(#too_many_args_error)
                     .into_mortal()
                     .into_raw());
@@ -417,8 +421,8 @@ pub fn handle_function(
             #visibility_action
 
             let argmark = unsafe { ::perlmod::ffi::pop_arg_mark() };
-            let mut args = argmark.iter();
-            { let _ = &mut args; }
+            let mut #arguments_name = argmark.iter();
+            { let _ = &mut #arguments_name; }
 
             #extract_arguments
 
-- 
2.47.3





  parent reply	other threads:[~2026-07-24 14:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 14:49 [PATCH perlmod v2 0/5] perlmod: add #[hash] parameter attribute Max R. Carrara
2026-07-24 14:49 ` [PATCH perlmod v2 1/5] macro: function: make argument code generation helpers standalone fns Max R. Carrara
2026-07-24 14:49 ` [PATCH perlmod v2 2/5] macro: function: make argument attribute handling more extendable Max R. Carrara
2026-07-24 14:49 ` Max R. Carrara [this message]
2026-07-24 14:49 ` [PATCH perlmod v2 4/5] macro: function: move signature inputs handling into helper struct Max R. Carrara
2026-07-24 14:49 ` [PATCH perlmod v2 5/5] perlmod, macro: add #[hash] parameter attribute Max R. Carrara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724144914.658730-4-m.carrara@proxmox.com \
    --to=m.carrara@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal