From 19716df23ddfd3047b64620c389fa336e4427c69 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 7 Sep 2017 17:56:38 +0200 Subject: [PATCH] shared: add nm_g_object_class_find_property_from_gtype() util And relax the type for nm_auto_unref_gtypeclass macro. Like g_type_class_unref() itself, you usually don't use it with a GTypeClass base class, but some subtype like GObjectClass. --- shared/nm-utils/nm-macros-internal.h | 6 +++--- shared/nm-utils/nm-shared-utils.c | 10 ++++++++++ shared/nm-utils/nm-shared-utils.h | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 66b4aa8d60..d11766f915 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -56,10 +56,10 @@ _nm_auto_unset_gvalue_impl (GValue *v) #define nm_auto_unset_gvalue nm_auto(_nm_auto_unset_gvalue_impl) static inline void -_nm_auto_unref_gtypeclass (GTypeClass **v) +_nm_auto_unref_gtypeclass (gpointer v) { - if (v && *v) - g_type_class_unref (*v); + if (v && *((gpointer *) v)) + g_type_class_unref (*((gpointer *) v)); } #define nm_auto_unref_gtypeclass nm_auto(_nm_auto_unref_gtypeclass) diff --git a/shared/nm-utils/nm-shared-utils.c b/shared/nm-utils/nm-shared-utils.c index b512e52a57..0109818a19 100644 --- a/shared/nm-utils/nm-shared-utils.c +++ b/shared/nm-utils/nm-shared-utils.c @@ -528,6 +528,16 @@ nm_g_object_set_property (GObject *object, return TRUE; } +GParamSpec * +nm_g_object_class_find_property_from_gtype (GType gtype, + const char *property_name) +{ + nm_auto_unref_gtypeclass GObjectClass *gclass = NULL; + + gclass = g_type_class_ref (gtype); + return g_object_class_find_property (gclass, property_name); +} + /*****************************************************************************/ static void diff --git a/shared/nm-utils/nm-shared-utils.h b/shared/nm-utils/nm-shared-utils.h index dc17fb269f..8d1085f6a5 100644 --- a/shared/nm-utils/nm-shared-utils.h +++ b/shared/nm-utils/nm-shared-utils.h @@ -246,6 +246,9 @@ gboolean nm_g_object_set_property (GObject *object, const GValue *value, GError **error); +GParamSpec *nm_g_object_class_find_property_from_gtype (GType gtype, + const char *property_name); + /*****************************************************************************/ typedef enum {