libnm-glib: fix initialization of NMObject type

Ensure that the @type_funcs and @type_async_funcs
hashes are initialized before running the class
init function.

libnm-glib-scan hits the following assertion:
  GLib-CRITICAL **: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed
  #0  0x0000003370c504e9 in g_logv (log_domain=0x3370cb2f4e "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffd1578f70) at gmessages.c:989
  #1  0x0000003370c5063f in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at gmessages.c:1025
  #2  0x00007f2169f42545 in _nm_object_register_type_func (base_type=base_type@entry=13597296, type_func=type_func@entry=0x7f2169f47ae9 <_nm_device_type_for_path>, type_async_func=type_async_func@entry=
      0x7f2169f47880 <_nm_device_type_for_path_async>) at nm-object.c:551
  #3  0x00007f2169f48664 in nm_device_get_type () at nm-device.c:62
  #4  0x0000000000402577 in get_object_types () at libnm-glib-scan.c:46
  #5  0x0000000000404b0b in main (argc=<optimized out>, argv=<optimized out>) at libnm-glib-scan.c:135

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller 2014-07-14 14:06:24 +02:00
parent 66d1f2f53c
commit 568742ed41

View file

@ -41,15 +41,17 @@ static gboolean debug = FALSE;
static void nm_object_initable_iface_init (GInitableIface *iface);
static void nm_object_async_initable_iface_init (GAsyncInitableIface *iface);
static GHashTable *type_funcs, *type_async_funcs;
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMObject, nm_object, G_TYPE_OBJECT,
type_funcs = g_hash_table_new (NULL, NULL);
type_async_funcs = g_hash_table_new (NULL, NULL);
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_object_initable_iface_init);
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_object_async_initable_iface_init);
)
#define NM_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_OBJECT, NMObjectPrivate))
static GHashTable *type_funcs, *type_async_funcs;
typedef struct {
PropertyMarshalFunc func;
GType object_type;
@ -383,11 +385,6 @@ nm_object_class_init (NMObjectClass *nm_object_class)
g_type_class_add_private (nm_object_class, sizeof (NMObjectPrivate));
if (!type_funcs) {
type_funcs = g_hash_table_new (NULL, NULL);
type_async_funcs = g_hash_table_new (NULL, NULL);
}
/* virtual methods */
object_class->constructor = constructor;
object_class->constructed = constructed;