From 9fb75e8f9fa024bfc389bd7b76d7e217e607328f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sat, 14 Dec 2019 16:56:15 +0100 Subject: [PATCH 112/181] fpi-context: Make fpi_get_driver_types to return an array No need to create one all the times and the fill it with what we need. --- libfprint/fp-context.c | 3 +-- libfprint/fpi-context.h | 5 +++-- libfprint/fprint-list-supported-devices.c | 4 +--- libfprint/fprint-list-udev-rules.c | 4 +--- meson.build | 11 +++++------ 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/libfprint/fp-context.c b/libfprint/fp-context.c index eed7847..3e47f03 100644 --- a/libfprint/fp-context.c +++ b/libfprint/fp-context.c @@ -243,8 +243,7 @@ fp_context_init (FpContext *self) g_autoptr(GError) error = NULL; FpContextPrivate *priv = fp_context_get_instance_private (self); - priv->drivers = g_array_new (TRUE, FALSE, sizeof (GType)); - fpi_get_driver_types (priv->drivers); + priv->drivers = fpi_get_driver_types (); priv->devices = g_ptr_array_new_with_free_func (g_object_unref); diff --git a/libfprint/fpi-context.h b/libfprint/fpi-context.h index c5a1075..48fecb4 100644 --- a/libfprint/fpi-context.h +++ b/libfprint/fpi-context.h @@ -23,11 +23,12 @@ /** * fpi_get_driver_types: - * @drivers: #GArray to be filled with all driver types * * This function is purely for private used. It is solely part of the public * API as it is useful during build time. * * Stability: private + * Returns: (element-type GType) (transfer container): a #GArray filled with + * all driver types */ -void fpi_get_driver_types (GArray *drivers); +GArray *fpi_get_driver_types (void); diff --git a/libfprint/fprint-list-supported-devices.c b/libfprint/fprint-list-supported-devices.c index 124e9d9..55da252 100644 --- a/libfprint/fprint-list-supported-devices.c +++ b/libfprint/fprint-list-supported-devices.c @@ -31,11 +31,9 @@ GHashTable *printed = NULL; static GList * insert_drivers (GList *list) { - g_autoptr(GArray) drivers = g_array_new (FALSE, FALSE, sizeof (GType)); + g_autoptr(GArray) drivers = fpi_get_driver_types (); gint i; - fpi_get_driver_types (drivers); - /* Find the best driver to handle this USB device. */ for (i = 0; i < drivers->len; i++) { diff --git a/libfprint/fprint-list-udev-rules.c b/libfprint/fprint-list-udev-rules.c index c0a3337..335c37b 100644 --- a/libfprint/fprint-list-udev-rules.c +++ b/libfprint/fprint-list-udev-rules.c @@ -96,11 +96,9 @@ print_driver (const FpDeviceClass *cls) int main (int argc, char **argv) { - g_autoptr(GArray) drivers = g_array_new (FALSE, FALSE, sizeof (GType)); + g_autoptr(GArray) drivers = fpi_get_driver_types (); guint i; - fpi_get_driver_types (drivers); - printed = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); for (i = 0; i < drivers->len; i++) diff --git a/meson.build b/meson.build index b7ba901..3f72118 100644 --- a/meson.build +++ b/meson.build @@ -151,21 +151,20 @@ drivers_type_func = [] drivers_type_list += '#include ' drivers_type_list += '#include "fpi-context.h"' drivers_type_list += '' -drivers_type_func += 'void fpi_get_driver_types (GArray *drivers)' +drivers_type_func += 'GArray *' +drivers_type_func += 'fpi_get_driver_types (void)' drivers_type_func += '{' +drivers_type_func += ' GArray *drivers = g_array_new (TRUE, FALSE, sizeof (GType));' drivers_type_func += ' GType t;' drivers_type_func += '' -idx = 0 foreach driver: drivers drivers_type_list += 'extern GType (fpi_device_' + driver + '_get_type) (void);' drivers_type_func += ' t = fpi_device_' + driver + '_get_type ();' drivers_type_func += ' g_array_append_val (drivers, t);' - if idx != drivers.length() - 1 - drivers_type_func += '' - idx += 1 - endif + drivers_type_func += '' endforeach drivers_type_list += '' +drivers_type_func += ' return drivers;' drivers_type_func += '}' root_inc = include_directories('.') -- 2.24.1