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

Re: [XEN PATCH 07/11] libxl: libxl__object_to_json() to json-c


  • To: Anthony PERARD <anthony@xxxxxxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jason Andryuk <jason.andryuk@xxxxxxx>
  • Date: Wed, 27 Aug 2025 13:51:25 -0400
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=xenproject.org 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=stB7/Muskj3g62ltWLB8R0YUq3th1wmrseeiuYbxT2E=; b=sE54pUpmw0i64ia2nfkEcnio7q4aXY9T8zZrVYa4QOCUOVCCh69KF3Db42ewVvbihsetRjfjHPrB71CMLrj4oL4oJad63pIrQaegTFBrM48MUYWozhhCY+EollBg4qQE0MHNaGWgJNS4RBHb6a1CeQszKGZSrA3o4Yk2m1CQj7Os8jhCN4Py4gC/TLByeSNjil5knEix0EPjJNY+dIcCoucbQ4sCbE1Jy3d8T7Jwo0GFJPBNdY9LSGezEW3mLeWfKGbJ8+6N6sSQtnb5kkULxM31b2DaqHTjSqUndGD69rNClWd+leZ3WuaaKQ58V6ECWdpcF+Ziiiiaze5HQ2CHsw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SJyu1M/TZ95mwRjFJlwnz/tGDir5tByXWtqge7hAMpIzFjgxZfbdm+9it0eDuJO36MkF+pFPanIeAS2tnhNxRh57+Y338CA9nA1bo0lQssTBDzsoIC3D518GJlTG9nt4i3mX9dQlCAkfF5l5Zq6qXk3IGh2Y18waoCzn9SDrlQt6MsN4+j2QsGXPSkP7WUP2BXTieZuO51Z09UHQ/rp3kpM5BEblaTTlKyDrqgn9q3n0hgoZZHisyl7BqGXyRENlKXBOy/nK5QFTRAdvgazMcyZpCokhnvdXeiqnSL9jricA3Ge0q9f/EA/xtJ8ZXh5Xr4xx7NpReQL+5rGZNAKzKQ==
  • Cc: Anthony PERARD <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>
  • Delivery-date: Wed, 27 Aug 2025 17:51:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2025-08-08 10:55, Anthony PERARD wrote:
From: Anthony PERARD <anthony.perard@xxxxxxxxxx>

- libxl changes:

While doing so, we rename all "*_gen_json" function to "*_gen_jso" as
they have different prototype. All the function pointer are been cast
to (libxl__gen_json_callback) by "gentypes.py" when generating
"*_to_json()" functions.

We also introduce a few more "*_gen_jso" functions for "int" and
"bool" because we can't use json_object_*() functions from json-c
directly like it's done with yajl.

To make the generation of _libxl_types*json.[ch] with both YAJL and
json-c we add "--libjsonc" to gentypes.py so it can generate
functions/types for both.

Also introducing "jsonc_json_gen_fn" in the IDL, to be able to point
to a different function when using json-c.

Also, don't export any of the new *_gen_jso() function, at the cost of
having "_hidden" macro in semi-public headers.

- xl changes:

Also, rework the implementation of printf_info() in `xl` to avoid
using libxl_domain_config_gen_json() which isn't available without
YAJL. The implementation using "json_object" call
libxl_domain_config_to_json() which generate a plain string of JSON,
which we parse to add it to our own json; this avoid a dependency on
the json library used by libxl.

Signed-off-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>

@@ -358,6 +535,36 @@ int libxl__mac_parse_json(libxl__gc *gc, const 
libxl__json_object *o,
      return libxl__parse_mac(libxl__json_object_get_string(o), *p);
  }
+#ifdef HAVE_LIBJSONC
+int libxl_hwcap_gen_jso(json_object **jso_r, libxl_hwcap *p)
+{
+    json_object *jso;
+    int i;
+    int rc = ERROR_FAIL;
+
+    jso = json_object_new_array();
+    if (!jso) goto out;
+
+    for(i=0; i<4; i++) {

typedef uint32_t libxl_hwcap[8];

I see this is the same as the yajl implementation, but should this be 8?

The remainder looks good:

Reviewed-by: Jason Andryuk <jason.andryuk@xxxxxxx>

Thanks,
Jason

+        json_object *jso_value = json_object_new_int((*p)[i]);
+        if (!jso_value)
+            goto out;
+        int r = json_object_array_add(jso, jso_value);
+        if (r) {
+            json_object_put(jso_value);
+            goto out;
+        }
+    }
+    *jso_r = jso;
+    jso = NULL;
+    rc = 0;
+out:
+    json_object_put(jso);
+    return rc;
+}
+#endif
+
+#ifdef HAVE_LIBYAJL
  yajl_gen_status libxl_hwcap_gen_json(yajl_gen hand,
                                       libxl_hwcap *p)
  {



 


Rackspace

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