[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [XEN PATCH for-4.13 v2 3/4] libxl: gentypes.py: Break out libxl_C_type_do_init


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
  • Date: Tue, 29 Oct 2019 15:54:35 +0000
  • Authentication-results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=ian.jackson@xxxxxxxxxxxxx; spf=Pass smtp.mailfrom=Ian.Jackson@xxxxxxxxxx; spf=None smtp.helo=postmaster@xxxxxxxxxxxxxxx
  • Cc: Jürgen Groß <jgross@xxxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
  • Delivery-date: Tue, 29 Oct 2019 15:54:52 +0000
  • Ironport-sdr: 2P9tjs7prv3z/+RJgQ1M26wA1mi2u1dv0SqOZxvl1pCZUg6JSrfT2Z/HsTK43J/V+PAjVfG+cJ TRy3NeSQA88m/iPoNFdJgGW5qPk/+yVd2IThfJm1fuphY0MOvxVJHs5a42Ms4UoluqSjJ0VAjK UzgDI1g/2FAnDTctOm3Ds+ozCuii2qpSbpcAinK8RcffbmiPabjR22+pBaahKtS+BJO0krI6cf WpfXKKkoC7n9kaRR893EhxVj8saPFVEPZzwt4kkq68XNmIaG9oddc5ej8NW7hXydhO9LJQI3fS 8DM=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

This is going to be the common way to initialise things.
_libxl_C_type_init remains the thing for generating the body of the
init function, and for some special cases.

No functional change with existing types: C output is identical.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/gentypes.py | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
index 62883acb2e..124285cd66 100644
--- a/tools/libxl/gentypes.py
+++ b/tools/libxl/gentypes.py
@@ -165,6 +165,19 @@ def libxl_init_members(ty, nesting = 0):
     else:
         return []
     
+def libxl_C_type_do_init(ty, pass_arg, need_zero=True, indent="    "):
+    s=indent
+    if ty.init_val is not None:
+        s+= "%s = %s;\n" % (pass_arg(idl.PASS_BY_VALUE), ty.init_val)
+    elif ty.init_fn is not None:
+        s+= "%s(%s);\n" % (ty.init_fn, pass_arg(idl.PASS_BY_REFERENCE))
+    elif need_zero:
+        ptr = pass_arg(idl.PASS_BY_REFERENCE)
+        s+= "memset(%s, 0, sizeof(*%s));\n" % (ptr, ptr)
+    else:
+        s=""
+    return s
+
 def _libxl_C_type_init(ty, v, indent = "    ", parent = None, subinit=False):
     s = ""
     if isinstance(ty, idl.KeyedUnion):
@@ -309,15 +322,7 @@ def libxl_C_type_copy_deprecated(field, v, indent = "    
", vparent = None):
         if field.type.dispose_fn is not None:
             s+= "    %s(%s);\n" % (field.type.dispose_fn,
                                    field.type.pass_arg(v, vparent is None))
-
-        s+= "    "
-        if field.type.init_val is not None:
-            s+= "%s = %s;\n" % (field_val, field.type.init_val)
-        elif field.type.init_fn is not None:
-            s+= "%s(%s);\n" % (field.type.init_fn, field_ptr)
-        else:
-            s+= "memset(%s, 0, sizeof(*%s));\n" % (field_ptr, field_ptr)
-
+        s+=libxl_C_type_do_init(field.type, field_pass)
         s+= "}\n"
 
     if s != "":
-- 
2.11.0


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.