On 01/28/22 18:04, Richard W.M. Jones wrote:
On Fri, Jan 28, 2022 at 05:12:14PM +0100, Laszlo Ersek wrote:
Move the guts of v2v_osinfo_os_get_all_devices() to a new static function called v2v_osinfo_device_list_to_value_list().
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2043333 Signed-off-by: Laszlo Ersek <lersek@redhat.com> --- convert/libosinfo-c.c | 126 +++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 58 deletions(-)
diff --git a/convert/libosinfo-c.c b/convert/libosinfo-c.c index ec7c06d379e3..bc5816f6dacb 100644 --- a/convert/libosinfo-c.c +++ b/convert/libosinfo-c.c @@ -207,65 +207,12 @@ glist_to_value_list (GList *list) rv = v; }
CAMLreturn (rv); }
-value -v2v_osinfo_os_get_device_drivers (value osv) -{ - CAMLparam1 (osv); - CAMLlocal4 (rv, v, vi, copyv); - OsinfoDeviceDriverList *list; - gint i, len; - - list = osinfo_os_get_device_drivers (OsinfoOs_t_val (osv)); - len = osinfo_list_get_length (OSINFO_LIST(list)); - - rv = Val_emptylist; - for (i = len - 1; i >= 0; --i) { - OsinfoDeviceDriver *driver; - const gchar *str; - gboolean b; - GList *l; - gint64 i64; - - driver = OSINFO_DEVICE_DRIVER(osinfo_list_get_nth (OSINFO_LIST(list), i)); - - vi = caml_alloc (6, 0); - str = osinfo_device_driver_get_architecture (driver); - copyv = caml_copy_string (str); - Store_field (vi, 0, copyv); - str = osinfo_device_driver_get_location (driver); - copyv = caml_copy_string (str); - Store_field (vi, 1, copyv); - b = osinfo_device_driver_get_pre_installable (driver); - Store_field (vi, 2, Val_bool (b)); - b = osinfo_device_driver_get_signed (driver); - Store_field (vi, 3, Val_bool (b)); -#if IS_LIBOSINFO_VERSION(1, 7, 0) - i64 = osinfo_device_driver_get_priority (driver); -#else - /* Same as OSINFO_DEVICE_DRIVER_DEFAULT_PRIORITY in libosinfo 1.7.0+. */ - i64 = 50; -#endif - copyv = caml_copy_int64 (i64); - Store_field (vi, 4, copyv); - l = osinfo_device_driver_get_files (driver); - Store_field (vi, 5, glist_to_value_list (l)); - g_list_free (l); - - v = caml_alloc (2, 0); - Store_field (v, 0, vi); - Store_field (v, 1, rv); - rv = v; - } - - CAMLreturn (rv); -} - /* Collect OsinfoDevice properties from two levels: * * - The OSINFO_ENTITY_PROP_ID property, originating from the OsinfoEntity base * class. This is a unique URI, identifying the device. * * - All currently known OSINFO_DEVICE_PROP_* properties, originating from the @@ -285,23 +232,21 @@ static const char * const device_prop[] = { OSINFO_DEVICE_PROP_CLASS, OSINFO_DEVICE_PROP_BUS_TYPE, OSINFO_DEVICE_PROP_SUBSYSTEM, }; #define NUM_DEVICE_PROPS (sizeof device_prop / sizeof device_prop[0])
-value -v2v_osinfo_os_get_all_devices (value osv) +static value +v2v_osinfo_device_list_to_value_list (OsinfoDeviceList *dev_list) { - CAMLparam1 (osv); + CAMLparam0 (); CAMLlocal4 (retvalv, linkv, propsv, copyv); - g_autoptr (OsinfoDeviceList) dev_list = NULL; OsinfoList *ent_list; gint ent_nr;
retvalv = Val_emptylist; - dev_list = osinfo_os_get_all_devices (OsinfoOs_t_val (osv), NULL); ent_list = OSINFO_LIST (dev_list); ent_nr = osinfo_list_get_length (ent_list);
while (ent_nr > 0) { OsinfoEntity *ent; size_t prop_nr; @@ -325,6 +270,71 @@ v2v_osinfo_os_get_all_devices (value osv) Store_field (linkv, 1, retvalv); retvalv = linkv; }
CAMLreturn (retvalv); } + +value +v2v_osinfo_os_get_device_drivers (value osv) +{ + CAMLparam1 (osv); + CAMLlocal4 (rv, v, vi, copyv); + OsinfoDeviceDriverList *list; + gint i, len; + + list = osinfo_os_get_device_drivers (OsinfoOs_t_val (osv)); + len = osinfo_list_get_length (OSINFO_LIST(list)); + + rv = Val_emptylist; + for (i = len - 1; i >= 0; --i) { + OsinfoDeviceDriver *driver; + const gchar *str; + gboolean b; + GList *l; + gint64 i64; + + driver = OSINFO_DEVICE_DRIVER(osinfo_list_get_nth (OSINFO_LIST(list), i)); + + vi = caml_alloc (6, 0); + str = osinfo_device_driver_get_architecture (driver); + copyv = caml_copy_string (str); + Store_field (vi, 0, copyv); + str = osinfo_device_driver_get_location (driver); + copyv = caml_copy_string (str); + Store_field (vi, 1, copyv); + b = osinfo_device_driver_get_pre_installable (driver); + Store_field (vi, 2, Val_bool (b)); + b = osinfo_device_driver_get_signed (driver); + Store_field (vi, 3, Val_bool (b)); +#if IS_LIBOSINFO_VERSION(1, 7, 0) + i64 = osinfo_device_driver_get_priority (driver); +#else + /* Same as OSINFO_DEVICE_DRIVER_DEFAULT_PRIORITY in libosinfo 1.7.0+. */ + i64 = 50; +#endif + copyv = caml_copy_int64 (i64); + Store_field (vi, 4, copyv); + l = osinfo_device_driver_get_files (driver); + Store_field (vi, 5, glist_to_value_list (l)); + g_list_free (l); + + v = caml_alloc (2, 0); + Store_field (v, 0, vi); + Store_field (v, 1, rv); + rv = v; + } + + CAMLreturn (rv); +} + +value +v2v_osinfo_os_get_all_devices (value osv) +{ + CAMLparam1 (osv); + CAMLlocal1 (retvalv); + g_autoptr (OsinfoDeviceList) dev_list = NULL; + + dev_list = osinfo_os_get_all_devices (OsinfoOs_t_val (osv), NULL); + retvalv = v2v_osinfo_device_list_to_value_list (dev_list); + CAMLreturn (retvalv); +}
Patch is a bit confusing because of the necessary reordering of functions,
I was surprised myself, but this is what the "patience" diff algorithm generates, which I've grown to prefer (in general) very much to the default "myers" diff algorithm.
but looks good.
Thanks! Laszlo
ACK
Rich.