From 87b88fd38c7aecb55184444ca1d032870221b352 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Sat, 6 Aug 2011 19:59:32 +0100 Subject: [PATCH 1/3] libnm-glib: allow NMRemoteSettings constructor with NULL bus NMRemoteSettings's constructor requires a DBusGConnection, but there currently aren't any usable gobject-introspection bindings for that class. This means that NMRemoteSettings can't be used over gobject-introspection. Move the default fallback to the system bus into the constructor path, so that introspection bindings are usable. Python test case: from gi.repository import NMClient NMClient.RemoteSettings() Before, this produced a segfault. Now it returns a usable RemoteSettings object. --- libnm-glib/nm-remote-settings.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libnm-glib/nm-remote-settings.c b/libnm-glib/nm-remote-settings.c index 70befd9e4e..b6aaabb06d 100644 --- a/libnm-glib/nm-remote-settings.c +++ b/libnm-glib/nm-remote-settings.c @@ -736,9 +736,6 @@ get_all_cb (DBusGProxy *proxy, NMRemoteSettings * nm_remote_settings_new (DBusGConnection *bus) { - if (bus == NULL) - bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); - return (NMRemoteSettings *) g_object_new (NM_TYPE_REMOTE_SETTINGS, NM_REMOTE_SETTINGS_BUS, bus, NULL); @@ -887,11 +884,15 @@ set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); + DBusGConnection *connection; switch (prop_id) { case PROP_BUS: /* Construct only */ - priv->bus = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value)); + connection = (DBusGConnection *) g_value_get_boxed (value); + if (!connection) + connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); + priv->bus = dbus_g_connection_ref (connection); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); From dd175e3bf7bd44c6cc305b0b815fad80e6cb1b9d Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Tue, 9 Aug 2011 16:31:19 +0200 Subject: [PATCH 2/3] libnm-glib: warn early if an object is tried to be instantiated without a path --- libnm-glib/nm-object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c index 614f6afcc8..c1f679dc28 100644 --- a/libnm-glib/nm-object.c +++ b/libnm-glib/nm-object.c @@ -79,8 +79,6 @@ constructor (GType type, if (!object) return NULL; - _nm_object_cache_add (NM_OBJECT (object)); - priv = NM_OBJECT_GET_PRIVATE (object); if (priv->connection == NULL || priv->path == NULL) { @@ -94,6 +92,8 @@ constructor (GType type, priv->path, "org.freedesktop.DBus.Properties"); + _nm_object_cache_add (NM_OBJECT (object)); + return object; } From 77e9cd53a8ed18247d070d28a958eb67b727c019 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Tue, 9 Aug 2011 16:31:20 +0200 Subject: [PATCH 3/3] libnm-glib: allow to constuct NMObject with NULL bus --- libnm-glib/nm-object.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c index c1f679dc28..cbcf29190d 100644 --- a/libnm-glib/nm-object.c +++ b/libnm-glib/nm-object.c @@ -140,11 +140,15 @@ set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object); + DBusGConnection *connection; switch (prop_id) { case PROP_CONNECTION: /* Construct only */ - priv->connection = dbus_g_connection_ref ((DBusGConnection *) g_value_get_boxed (value)); + connection = (DBusGConnection *) g_value_get_boxed (value); + if (!connection) + connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); + priv->connection = dbus_g_connection_ref (connection); break; case PROP_PATH: /* Construct only */