From: Matthew Barnes Date: Sat, 13 Oct 2012 13:49:00 +0000 (-0400) Subject: Deprecate e_source_extension_get_source(). X-Git-Tag: upstream/3.7.4~336 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=af520782f1eddd58ec86fba25c9291b1e6b20d80;p=platform%2Fupstream%2Fevolution-data-server.git Deprecate e_source_extension_get_source(). Replace it with a thread-safe version: e_source_extension_ref_source() Also use GWeakRef within ESourceExtension, which itself is thread-safe. --- diff --git a/addressbook/backends/ldap/e-source-ldap.c b/addressbook/backends/ldap/e-source-ldap.c index ccc2f68..18bb104 100644 --- a/addressbook/backends/ldap/e-source-ldap.c +++ b/addressbook/backends/ldap/e-source-ldap.c @@ -243,7 +243,7 @@ source_ldap_constructed (GObject *object) const gchar *extension_name; this_extension = E_SOURCE_EXTENSION (object); - source = e_source_extension_get_source (this_extension); + source = e_source_extension_ref_source (this_extension); extension_name = E_SOURCE_EXTENSION_AUTHENTICATION; other_extension = e_source_get_extension (source, extension_name); @@ -268,6 +268,8 @@ source_ldap_constructed (GObject *object) source_ldap_transform_enum_nick_to_value, source_ldap_transform_enum_value_to_nick, NULL, (GDestroyNotify) NULL); + + g_object_unref (source); } static void diff --git a/calendar/backends/contacts/e-source-contacts.c b/calendar/backends/contacts/e-source-contacts.c index 8e8eac3..c19cc66 100644 --- a/calendar/backends/contacts/e-source-contacts.c +++ b/calendar/backends/contacts/e-source-contacts.c @@ -86,7 +86,7 @@ source_contacts_constructed (GObject *object) G_OBJECT_CLASS (e_source_contacts_parent_class)->constructed (object); extension = E_SOURCE_EXTENSION (object); - source = e_source_extension_get_source (extension); + source = e_source_extension_ref_source (extension); extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK; backend_extension = e_source_get_extension (source, extension_name); @@ -97,6 +97,8 @@ source_contacts_constructed (GObject *object) contacts_extension = E_SOURCE_CONTACTS (extension); e_source_contacts_set_include_me (contacts_extension, include_me); + + g_object_unref (source); } static void diff --git a/docs/reference/libedataserver/libedataserver-sections.txt b/docs/reference/libedataserver/libedataserver-sections.txt index a963209..52b9b57 100644 --- a/docs/reference/libedataserver/libedataserver-sections.txt +++ b/docs/reference/libedataserver/libedataserver-sections.txt @@ -493,6 +493,7 @@ e_source_collection_get_type ESourceExtension ESourceExtension E_SOURCE_PARAM_SETTING +e_source_extension_ref_source e_source_extension_get_source E_SOURCE_EXTENSION diff --git a/libedataserver/e-source-camel.c b/libedataserver/e-source-camel.c index 06256c0..2672636 100644 --- a/libedataserver/e-source-camel.c +++ b/libedataserver/e-source-camel.c @@ -331,7 +331,7 @@ source_camel_constructed (GObject *object) class = E_SOURCE_CAMEL_GET_CLASS (object); priv = E_SOURCE_CAMEL_GET_PRIVATE (object); - source = e_source_extension_get_source (E_SOURCE_EXTENSION (object)); + source = e_source_extension_ref_source (E_SOURCE_EXTENSION (object)); priv->settings = g_object_new (class->settings_type, NULL); @@ -412,6 +412,8 @@ source_camel_constructed (GObject *object) g_array_set_size (priv->value_array, array_index); g_free (properties); + + g_object_unref (source); } static void diff --git a/libedataserver/e-source-extension.c b/libedataserver/e-source-extension.c index b13d0d1..a46033a 100644 --- a/libedataserver/e-source-extension.c +++ b/libedataserver/e-source-extension.c @@ -36,7 +36,7 @@ ((obj), E_TYPE_SOURCE_EXTENSION, ESourceExtensionPrivate)) struct _ESourceExtensionPrivate { - gpointer source; /* weak pointer */ + GWeakRef source; }; enum { @@ -54,12 +54,8 @@ source_extension_set_source (ESourceExtension *extension, ESource *source) { g_return_if_fail (E_IS_SOURCE (source)); - g_return_if_fail (extension->priv->source == NULL); - extension->priv->source = source; - - g_object_add_weak_pointer ( - G_OBJECT (source), &extension->priv->source); + g_weak_ref_set (&extension->priv->source, source); } static void @@ -87,8 +83,8 @@ source_extension_get_property (GObject *object, { switch (property_id) { case PROP_SOURCE: - g_value_set_object ( - value, e_source_extension_get_source ( + g_value_take_object ( + value, e_source_extension_ref_source ( E_SOURCE_EXTENSION (object))); return; } @@ -103,11 +99,7 @@ source_extension_dispose (GObject *object) priv = E_SOURCE_EXTENSION_GET_PRIVATE (object); - if (priv->source != NULL) { - g_object_remove_weak_pointer ( - G_OBJECT (priv->source), &priv->source); - priv->source = NULL; - } + g_weak_ref_set (&priv->source, NULL); /* Chain up to parent's dispose() method. */ G_OBJECT_CLASS (e_source_extension_parent_class)->dispose (object); @@ -121,11 +113,13 @@ source_extension_notify (GObject *object, ESourceExtension *extension; extension = E_SOURCE_EXTENSION (object); - source = e_source_extension_get_source (extension); + source = e_source_extension_ref_source (extension); g_return_if_fail (source != NULL); if ((pspec->flags & E_SOURCE_PARAM_SETTING) != 0) e_source_changed (source); + + g_object_unref (source); } static void @@ -161,23 +155,56 @@ e_source_extension_init (ESourceExtension *extension) } /** + * e_source_extension_ref_source: + * @extension: an #ESourceExtension + * + * Returns the #ESource instance to which the @extension belongs. + * + * The returned #ESource is referenced for thread-safety. Unreference + * the #ESource with g_object_unref() when finished with it. + * + * Returns: the #ESource instance + * + * Since: 3.8 + **/ +ESource * +e_source_extension_ref_source (ESourceExtension *extension) +{ + g_return_val_if_fail (E_IS_SOURCE_EXTENSION (extension), NULL); + + return g_weak_ref_get (&extension->priv->source); +} + +/** * e_source_extension_get_source: * @extension: an #ESourceExtension * * Returns the #ESource instance to which @extension belongs. * + * Note this function is not thread-safe. The returned #ESource could + * be finalized by another thread while the caller is still using it. + * * Returns: (transfer none): the #ESource instance * * Since: 3.6 + * + * Deprecated: 3.8: Use e_source_extension_ref_source() instead. **/ ESource * e_source_extension_get_source (ESourceExtension *extension) { + ESource *source; + g_return_val_if_fail (E_IS_SOURCE_EXTENSION (extension), NULL); - /* If the ESource was finalized and our weak pointer set this - * to NULL, then the type cast macro will fail and we'll get a - * runtime warning about it, which is what we want. */ - return E_SOURCE (extension->priv->source); + source = e_source_extension_ref_source (extension); + + /* XXX Drop the ESource reference for backward-compatibility. + * This is risky. Without a reference, the ESource could + * be finalized while the caller is still using it. */ + if (source != NULL) + g_object_unref (source); + + return source; } diff --git a/libedataserver/e-source-extension.h b/libedataserver/e-source-extension.h index a51e4df..80788e9 100644 --- a/libedataserver/e-source-extension.h +++ b/libedataserver/e-source-extension.h @@ -70,7 +70,11 @@ struct _ESourceExtensionClass { }; GType e_source_extension_get_type (void) G_GNUC_CONST; +ESource * e_source_extension_ref_source (ESourceExtension *extension); + +#ifndef EDS_DISABLE_DEPRECATED ESource * e_source_extension_get_source (ESourceExtension *extension); +#endif /* EDS_DISABLE_DEPRECATED */ G_END_DECLS diff --git a/libedataserver/e-source-mail-signature.c b/libedataserver/e-source-mail-signature.c index 68de9db..03bb1a7 100644 --- a/libedataserver/e-source-mail-signature.c +++ b/libedataserver/e-source-mail-signature.c @@ -174,7 +174,7 @@ source_mail_signature_constructed (GObject *object) constructed (object); extension = E_SOURCE_EXTENSION (object); - source = e_source_extension_get_source (extension); + source = e_source_extension_ref_source (extension); uid = e_source_get_uid (source); config_dir = e_get_user_config_dir (); @@ -184,6 +184,8 @@ source_mail_signature_constructed (GObject *object) g_mkdir_with_parents (base_dir, 0700); g_free (base_dir); g_free (path); + + g_object_unref (source); } static void diff --git a/libedataserver/e-source-refresh.c b/libedataserver/e-source-refresh.c index d210ae4..a92c379 100644 --- a/libedataserver/e-source-refresh.c +++ b/libedataserver/e-source-refresh.c @@ -106,14 +106,16 @@ timeout_node_invoke (gpointer data) ESource *source; extension = E_SOURCE_EXTENSION (node->extension); - source = e_source_extension_get_source (extension); - g_return_val_if_fail (E_IS_SOURCE (source), FALSE); + source = e_source_extension_ref_source (extension); + g_return_val_if_fail (source != NULL, FALSE); /* We allow timeouts to be scheduled for disabled data sources * but we don't invoke the callback. Keeps the logic simple. */ if (e_source_get_enabled (source)) node->callback (source, node->user_data); + g_object_unref (source); + return TRUE; } @@ -309,7 +311,7 @@ source_refresh_constructed (GObject *object) G_OBJECT_CLASS (e_source_refresh_parent_class)->constructed (object); extension = E_SOURCE_EXTENSION (object); - source = e_source_extension_get_source (extension); + source = e_source_extension_ref_source (extension); /* There should be no lifecycle issues here * since we get finalized with our ESource. */ @@ -317,6 +319,8 @@ source_refresh_constructed (GObject *object) source, "notify::enabled", G_CALLBACK (source_refresh_notify_enabled_cb), extension); + + g_object_unref (source); } static void diff --git a/libedataserver/e-source-webdav.c b/libedataserver/e-source-webdav.c index c624e1b..510d48a 100644 --- a/libedataserver/e-source-webdav.c +++ b/libedataserver/e-source-webdav.c @@ -123,7 +123,7 @@ source_webdav_update_properties_from_soup_uri (ESourceWebdav *webdav_extension) g_mutex_unlock (webdav_extension->priv->property_lock); extension = E_SOURCE_EXTENSION (webdav_extension); - source = e_source_extension_get_source (extension); + source = e_source_extension_ref_source (extension); g_object_set ( extension, @@ -149,6 +149,8 @@ source_webdav_update_properties_from_soup_uri (ESourceWebdav *webdav_extension) "secure", (soup_uri->scheme == SOUP_URI_SCHEME_HTTPS), NULL); + g_object_unref (source); + soup_uri_free (soup_uri); } @@ -167,7 +169,7 @@ source_webdav_update_soup_uri_from_properties (ESourceWebdav *webdav_extension) gboolean secure; extension = E_SOURCE_EXTENSION (webdav_extension); - source = e_source_extension_get_source (extension); + source = e_source_extension_ref_source (extension); g_object_get ( extension, @@ -193,6 +195,8 @@ source_webdav_update_soup_uri_from_properties (ESourceWebdav *webdav_extension) "secure", &secure, NULL); + g_object_unref (source); + g_mutex_lock (webdav_extension->priv->property_lock); soup_uri = webdav_extension->priv->soup_uri; @@ -383,7 +387,7 @@ source_webdav_constructed (GObject *object) * how it's supposed to work if everyone follows the rules. */ extension = E_SOURCE_EXTENSION (object); - source = e_source_extension_get_source (extension); + source = e_source_extension_ref_source (extension); g_signal_connect ( extension, "notify::resource-path", @@ -424,6 +428,8 @@ source_webdav_constructed (GObject *object) g_signal_connect ( extension, "notify::secure", G_CALLBACK (source_webdav_notify_cb), object); + + g_object_unref (source); } static void