[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] tools/libxl: Make gentypes.py compatible with older Python
- To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony@xxxxxxxxxxxxxx>
- From: Jason Andryuk <jason.andryuk@xxxxxxx>
- Date: Tue, 21 Oct 2025 13:20:58 -0400
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=citrix.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C1a9B53zZi20Oa49So7sdfTfj5Oao41vAW32lubUwIE=; b=HXWx9u8w/7GCguc0TEGEPxOx1t4d9A7WNFEWUX2lRMq9hUAK29Yahz9Dmalkj4MiRZBqrRzeHQnDthW0RyCEfYmunHUDNc+IfsnfmIhwiWMVQjjSGvwHzmCuE0yyUd6/L0FGfdBOA7aLmcBSRWmLGTJsq7VwpftHoWumUuSaFf0O90OyvkE42hkL1BcwTgl4s7XQPFdGwNVrLQbfwiImJTNB3blfbz8Ij2kCJda7qAcB8krOAlterIINtdWI7WPJOer37B4/+ailEJ4vA/NRjZGmNqNdqObWuRLEutBwTeri6XepVSkjIst90dcIFRMGJ/9dADkwI9Bxz74BnShbhA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=G9aXNOYmBxx3nGLRU5qzwJhhPvIk15wsC7GNJUnG4r6FaPn1BorYoKbH7TqMvQVAZGd0Psi1ojnav2TZJJnienKrc9BEveQ3yGn35fsBHZfWEshFzfyt6zv9NY84hJV5DYvJkvIvqWTsTZiT/jdLXCzk5Q1YF8WFvffHyv25MLo2qtLpEWTjSfy57lnANHgvbiEwLX52Sn32/+k7OEXd2tAVY37tIHwuSpLgVE6llr4YcBN19Js0Pa37zGc9zODDHzTHCWgM3AJH6AuPW52N8+3oE4R3lAw/e3hcO/R5O/MefLtAe9SDKMY8RyOv95craBUAMF/7XaQsSuSU4x4hGA==
- Cc: <jbeulich@xxxxxxxx>, <anthony.perard@xxxxxxxxxx>, <jgross@xxxxxxxx>, <oleksii.kurochko@xxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- Delivery-date: Tue, 21 Oct 2025 17:21:31 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 2025-10-21 12:31, Andrew Cooper wrote:
On 21/10/2025 5:23 pm, Anthony PERARD wrote:
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@xxxxxxx>
---
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@xxxxxxxxxx>
Thanks. I'll take this version, and take the liberty of assuming that
the Release Ack is transferable to whichever solution the maintainers
prefer in the end.
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.
That makes the code even more simple, because it takes out the else.
The net hunk is:
@@ -377,15 +377,14 @@ 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"
- else:
- sub_scope_object = "jso_sub_%d" %
(1+int(scope_object.removeprefix("jso_sub_")))
+ depth += 1
+ sub_scope_object = "jso_sub_%d" % depth
if isinstance(ty, idl.Array):
if parent is None:
raise Exception("Array type must have a parent")
This works for me, thanks - I even tried it at some point while tracking
down the jso_sub_2/3 difference from KeyedUnion. I should have gone
back to it :)
Regards,
Jason
|