[PATCH spice-gtk v2 16/19] channel: deprecate spice_channel_destroy()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This function is somewhat useless, and dangerous since it is
calling g_object_unref() on your back (although this is mention in the
doc, I consider this a bad practice).
---
 gtk/spice-channel.c | 7 ++++++-
 gtk/spice-channel.h | 3 ++-
 gtk/spice-session.c | 8 ++++----
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gtk/spice-channel.c b/gtk/spice-channel.c
index 7585823..510ce25 100644
--- a/gtk/spice-channel.c
+++ b/gtk/spice-channel.c
@@ -2038,8 +2038,13 @@ SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id)
  * spice_channel_destroy:
  * @channel:
  *
- * Disconnect and unref the @channel. Called by @spice_session_channel_destroy()
+ * Disconnect and unref the @channel.
  *
+ * Deprecated: 0.27: this function has been deprecated because it is
+ * misleading, the object is not actually destroyed. And it is too
+ * easy to forget that the object is unref(). Instead, it is
+ * recommended to call explicitely spice_channel_disconnect() and
+ * g_object_unref().
  **/
 void spice_channel_destroy(SpiceChannel *channel)
 {
diff --git a/gtk/spice-channel.h b/gtk/spice-channel.h
index 1c303b4..8d07383 100644
--- a/gtk/spice-channel.h
+++ b/gtk/spice-channel.h
@@ -107,7 +107,6 @@ GType spice_channel_get_type(void);
 typedef void (*spice_msg_handler)(SpiceChannel *channel, SpiceMsgIn *in);
 
 SpiceChannel *spice_channel_new(SpiceSession *s, int type, int id);
-void spice_channel_destroy(SpiceChannel *channel);
 gboolean spice_channel_connect(SpiceChannel *channel);
 gboolean spice_channel_open_fd(SpiceChannel *channel, int fd);
 void spice_channel_disconnect(SpiceChannel *channel, SpiceChannelEvent reason);
@@ -118,6 +117,8 @@ gboolean spice_channel_flush_finish(SpiceChannel *channel, GAsyncResult *result,
 #ifndef SPICE_DISABLE_DEPRECATED
 SPICE_DEPRECATED
 void spice_channel_set_capability(SpiceChannel *channel, guint32 cap);
+SPICE_DEPRECATED
+void spice_channel_destroy(SpiceChannel *channel);
 #endif
 
 const gchar* spice_channel_type_to_string(gint type);
diff --git a/gtk/spice-session.c b/gtk/spice-session.c
index be8569f..5729d8a 100644
--- a/gtk/spice-session.c
+++ b/gtk/spice-session.c
@@ -1664,9 +1664,8 @@ void spice_session_disconnect(SpiceSession *session)
     memset(s->uuid, 0, sizeof(s->uuid));
 
     spice_session_abort_migration(session);
-    /* we leave disconnecting = TRUE, so that spice_channel_destroy()
-       is not called multiple times on channels that are in pending
-       destroy state. */
+    /* we leave disconnecting = TRUE, so that spice_channel_disconnect()
+       is not called multiple times */
 }
 
 /**
@@ -1971,7 +1970,8 @@ static void spice_session_channel_destroy(SpiceSession *session, SpiceChannel *c
     g_signal_emit(session, signals[SPICE_SESSION_CHANNEL_DESTROY], 0, channel);
 
     g_clear_object(&channel->priv->session);
-    spice_channel_destroy(channel);
+    spice_channel_disconnect(channel, SPICE_CHANNEL_NONE);
+    g_object_unref(channel);
 }
 
 G_GNUC_INTERNAL
-- 
1.9.3

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]