All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony@xenproject.org>
To: Jason Andryuk <jason.andryuk@amd.com>
Cc: jbeulich@suse.com, andrew.cooper3@citrix.com,
	anthony.perard@vates.tech, jgross@suse.com,
	oleksii.kurochko@gmail.com, xen-devel@lists.xenproject.org
Subject: Re: [PATCH] tools/libxl: Make gentypes.py compatible with older Python
Date: Tue, 21 Oct 2025 18:23:30 +0200	[thread overview]
Message-ID: <aPezgmtiRHlDqFLE@l14> (raw)
In-Reply-To: <20251017020613.79855-1-jason.andryuk@amd.com>

On Thu, Oct 16, 2025 at 10:06:13PM -0400, Jason Andryuk wrote:
> removeprefix is only added in Python 3.9.
> 
> Instead of the prefix removal, switch to passing in a "depth" parameter,
> and incrementing it for each level.
> 
> There is a slight change in the generated _libxl_types.c.  instances of
> KeyedUnion increment depth without outputing any code.  The net result
> is some cases where jso_sub_1 is followed by jso_sub_3.  As an example:
> 
> _libxl_types.c
> _libxl_types.c
> @@ -5535,12 +5535,12 @@
>                  if (!jso_sub_1)
>                      goto out;
>                  if (!libxl__string_is_default(&p->u.pty.path)) {
> -                    json_object *jso_sub_2 = NULL;
> -                    rc = libxl__string_gen_jso(&jso_sub_2, p->u.pty.path);
> +                    json_object *jso_sub_3 = NULL;
> +                    rc = libxl__string_gen_jso(&jso_sub_3, p->u.pty.path);
>                      if (rc)
>                          goto out;
> -                    if (json_object_object_add(jso_sub_1, "path", jso_sub_2)) {
> -                        json_object_put(jso_sub_2);
> +                    if (json_object_object_add(jso_sub_1, "path", jso_sub_3)) {
> +                        json_object_put(jso_sub_3);
>                          goto out;
>                      }
>                  }
> 
> Signed-off-by: Jason Andryuk <jason.andryuk@amd.com>
> ---
> Here's an alternative approach to workaround removeprefix.

Yeah, this version is less obscure about what's going on. Let's go for
it.

Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>

>  tools/libs/light/gentypes.py | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/libs/light/gentypes.py b/tools/libs/light/gentypes.py
> index 006bea170a..0e45c04f49 100644
> --- a/tools/libs/light/gentypes.py
> +++ b/tools/libs/light/gentypes.py
> @@ -377,15 +377,16 @@ def get_default_expr(f, nparent, fexpr):
>      return "%s" % fexpr
>  
>  # For json-c gen_json functions
> -def libxl_C_type_gen_jso(ty, v, indent = "    ", parent = None, scope_object = "jso"):
> +def libxl_C_type_gen_jso(ty, v, indent = "    ", parent = None, scope_object = "jso", depth = 0):
>      s = ""
>      if parent is None:
>          s += "json_object *jso;\n"
>          s += "int rc;\n"
> -        sub_scope_object = "jso_sub_1"
> +        depth = 1
>      else:
> -        sub_scope_object = "jso_sub_%d" % (1+int(scope_object.removeprefix("jso_sub_")))
> +        depth += 1

We could simply do `depth += 1` regardless of the value of parent, it
would have the same effect, since depth start at 0. We just need to
create a new variable name that is different from the one created by the
callers (`depth=random.randrange(9999, 99999999)` actually works :-D,
but no guaranty of having different values). Anyway, the code is fine as
is, no need to make last minute edit.

Cheers,

-- 
Anthony PERARD


  parent reply	other threads:[~2025-10-21 16:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-16 11:22 [PATCH for-4.21] libxl: make gentypes.py compatible with Python older than 3.9 Jan Beulich
2025-10-16 11:45 ` Andrew Cooper
2025-10-16 11:51   ` Jan Beulich
2025-10-17  2:06     ` [PATCH] tools/libxl: Make gentypes.py compatible with older Python Jason Andryuk
2025-10-17  6:02       ` Jan Beulich
2025-10-21 16:23       ` Anthony PERARD [this message]
2025-10-21 16:31         ` Andrew Cooper
2025-10-21 17:20           ` Jason Andryuk
     [not found]     ` <0a78d0993fc44d6cae0a363cc875b6da@DM4PR03MB7015.namprd03.prod.outlook.com>
2025-10-21 16:00       ` Andrew Cooper
2025-10-16 15:28 ` [PATCH for-4.21] libxl: make gentypes.py compatible with Python older than 3.9 Oleksii Kurochko
2025-10-21 14:51 ` Anthony PERARD
2025-10-21 15:21   ` Jan Beulich

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=aPezgmtiRHlDqFLE@l14 \
    --to=anthony@xenproject.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=jason.andryuk@amd.com \
    --cc=jbeulich@suse.com \
    --cc=jgross@suse.com \
    --cc=oleksii.kurochko@gmail.com \
    --cc=xen-devel@lists.xenproject.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.