Skip to content

Commit

Permalink
binding: Remove GObject data usage
Browse files Browse the repository at this point in the history
It isn't actually doing anything, instead it is
being managed without actually being used.
This has the result that GBinding is now more
thread-safe.

https://bugzilla.gnome.org/show_bug.cgi?id=745013
  • Loading branch information
gregier committed Jun 4, 2015
1 parent f685823 commit 36593a3
Showing 1 changed file with 2 additions and 44 deletions.
46 changes: 2 additions & 44 deletions gobject/gbinding.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,40 +192,9 @@ enum
};

static guint gobject_notify_signal_id;
static GQuark quark_gbinding = 0;

G_DEFINE_TYPE (GBinding, g_binding, G_TYPE_OBJECT);

static inline void
add_binding_qdata (GObject *gobject,
GBinding *binding)
{
GHashTable *bindings;

bindings = g_object_get_qdata (gobject, quark_gbinding);
if (bindings == NULL)
{
bindings = g_hash_table_new (NULL, NULL);

g_object_set_qdata_full (gobject, quark_gbinding,
bindings,
(GDestroyNotify) g_hash_table_unref);
}

g_hash_table_add (bindings, binding);
}

static inline void
remove_binding_qdata (GObject *gobject,
GBinding *binding)
{
GHashTable *bindings;

bindings = g_object_get_qdata (gobject, quark_gbinding);
if (binding != NULL)
g_hash_table_remove (bindings, binding);
}

/* the basic assumption is that if either the source or the target
* goes away then the binding does not exist any more and it should
* be reaped as well
Expand All @@ -248,7 +217,6 @@ weak_unbind (gpointer user_data,
g_signal_handler_disconnect (binding->source, binding->source_notify);

g_object_weak_unref (binding->source, weak_unbind, user_data);
remove_binding_qdata (binding->source, binding);

binding->source_notify = 0;
binding->source = NULL;
Expand All @@ -263,7 +231,6 @@ weak_unbind (gpointer user_data,
g_signal_handler_disconnect (binding->target, binding->target_notify);

g_object_weak_unref (binding->target, weak_unbind, user_data);
remove_binding_qdata (binding->target, binding);

binding->target_notify = 0;
binding->target = NULL;
Expand Down Expand Up @@ -444,7 +411,6 @@ g_binding_unbind_internal (GBinding *binding,
g_signal_handler_disconnect (binding->source, binding->source_notify);

g_object_weak_unref (binding->source, weak_unbind, binding);
remove_binding_qdata (binding->source, binding);

binding->source_notify = 0;
binding->source = NULL;
Expand All @@ -456,10 +422,7 @@ g_binding_unbind_internal (GBinding *binding,
g_signal_handler_disconnect (binding->target, binding->target_notify);

if (!source_is_target)
{
g_object_weak_unref (binding->target, weak_unbind, binding);
remove_binding_qdata (binding->target, binding);
}
g_object_weak_unref (binding->target, weak_unbind, binding);

binding->target_notify = 0;
binding->target = NULL;
Expand Down Expand Up @@ -590,7 +553,6 @@ g_binding_constructed (GObject *gobject)
FALSE);

g_object_weak_ref (binding->source, weak_unbind, binding);
add_binding_qdata (binding->source, binding);

if (binding->flags & G_BINDING_BIDIRECTIONAL)
{
Expand All @@ -608,18 +570,14 @@ g_binding_constructed (GObject *gobject)
}

if (binding->target != binding->source)
{
g_object_weak_ref (binding->target, weak_unbind, binding);
add_binding_qdata (binding->target, binding);
}
g_object_weak_ref (binding->target, weak_unbind, binding);
}

static void
g_binding_class_init (GBindingClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);

quark_gbinding = g_quark_from_static_string ("g-binding");
gobject_notify_signal_id = g_signal_lookup ("notify", G_TYPE_OBJECT);
g_assert (gobject_notify_signal_id != 0);

Expand Down

0 comments on commit 36593a3

Please sign in to comment.