[next] telepathy-glib: Use #define'd constants for interface-added, interface-removed signals

Simon McVittie smcv at kemper.freedesktop.org
Wed May 7 02:18:25 PDT 2014


Module: telepathy-glib
Branch: next
Commit: 2941ce2adbc9cc3970328a751f0451f49f32e647
URL:    http://cgit.freedesktop.org/telepathy/telepathy-glib/commit/?id=2941ce2adbc9cc3970328a751f0451f49f32e647

Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Tue Apr 22 11:29:14 2014 +0100

Use #define'd constants for interface-added, interface-removed signals

Xavier suggested that an enum would be clearer than +1 and -1. However,
since these constants are only ever used in a pointer-typed parameter,
it seems clearer still to #define their GINT_TO_POINTER form.

I deliberately avoided 0 because casting a literal 0 to a pointer type
is special (it produces a null pointer constant, which in theory is
not necessarily all-bits-zero, although in practice any reasonable
architecture uses all-bits-zero to avoid breaking people's assumptions
about calloc()).

Reviewed-by: Xavier Claessens <xavier.claessens at collabora.com>
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77189

---

 telepathy-glib/base-connection.c |   14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/telepathy-glib/base-connection.c b/telepathy-glib/base-connection.c
index 4fc1f13..76cd50f 100644
--- a/telepathy-glib/base-connection.c
+++ b/telepathy-glib/base-connection.c
@@ -643,16 +643,20 @@ _tp_base_connection_set_handle_repo (TpBaseConnection *self,
   self->priv->handles[entity_type] = g_object_ref (handle_repo);
 }
 
+/* User data for interface-added and interface-removed signals, with vaguely
+ * mnemonic values */
+#define INTERFACE_ADDED (GINT_TO_POINTER(1))
+#define INTERFACE_REMOVED (GINT_TO_POINTER(-1))
+
 static void
 tp_base_connection_interface_changed_cb (TpBaseConnection *self,
     GDBusInterface *interface,
     gpointer user_data)
 {
   GDBusInterfaceInfo *info = g_dbus_interface_get_info (interface);
-  gint what_happened = GPOINTER_TO_INT (user_data);
-  const gchar *verb = (what_happened == 1 ? "add" : "remove");
+  const gchar *verb = (user_data == INTERFACE_ADDED ? "add" : "remove");
 
-  g_assert (what_happened == 1 || what_happened == -1);
+  g_assert (user_data == INTERFACE_ADDED || user_data == INTERFACE_REMOVED);
 
   if (self->priv->status == TP_CONNECTION_STATUS_CONNECTED)
     {
@@ -763,10 +767,10 @@ tp_base_connection_constructed (GObject *object)
 
   g_signal_connect (self, "interface-added",
       G_CALLBACK (tp_base_connection_interface_changed_cb),
-      GINT_TO_POINTER (+1));
+      INTERFACE_ADDED);
   g_signal_connect (self, "interface-removed",
       G_CALLBACK (tp_base_connection_interface_changed_cb),
-      GINT_TO_POINTER (-1));
+      INTERFACE_REMOVED);
 
   /* We don't have any interfaces yet (except for Connection and Requests)
    * so it's OK that the default for _TpGDBusConnection:interfaces is NULL. */



More information about the telepathy-commits mailing list