hook gvariant vectors up to kdbus
[platform/upstream/glib.git] / gobject / gbinding.c
index 628ede9..2237e5e 100644 (file)
@@ -13,9 +13,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
  *
  * Author: Emmanuele Bassi <ebassi@linux.intel.com>
  */
  * value is applied to the target property; for instance, the following
  * binding:
  *
- * |[
+ * |[<!-- language="C" --> 
  *   g_object_bind_property (object1, "property-a",
  *                           object2, "property-b",
  *                           G_BINDING_DEFAULT);
  * ]|
  *
- * will cause <emphasis>object2:property-b</emphasis> to be updated every
- * time g_object_set() or the specific accessor changes the value of
- * <emphasis>object1:property-a</emphasis>.
+ * will cause the property named "property-b" of @object2 to be updated
+ * every time g_object_set() or the specific accessor changes the value of
+ * the property "property-a" of @object1.
  *
  * It is possible to create a bidirectional binding between two properties
  * of two #GObject instances, so that if either property changes, the
  * other is updated as well, for instance:
  *
- * |[
+ * |[<!-- language="C" --> 
  *   g_object_bind_property (object1, "property-a",
  *                           object2, "property-b",
  *                           G_BINDING_BIDIRECTIONAL);
@@ -58,7 +56,7 @@
  * transformation from the source value to the target value before
  * applying it; for instance, the following binding:
  *
- * |[
+ * |[<!-- language="C" --> 
  *   g_object_bind_property_full (adjustment1, "value",
  *                                adjustment2, "value",
  *                                G_BINDING_BIDIRECTIONAL,
  *                                NULL, NULL);
  * ]|
  *
- * will keep the <emphasis>value</emphasis> property of the two adjustments
- * in sync; the <function>celsius_to_fahrenheit</function> function will be
- * called whenever the <emphasis>adjustment1:value</emphasis> property changes
- * and will transform the current value of the property before applying it
- * to the <emphasis>adjustment2:value</emphasis> property; vice versa, the
- * <function>fahrenheit_to_celsius</function> function will be called whenever
- * the <emphasis>adjustment2:value</emphasis> property changes, and will
- * transform the current value of the property before applying it to the
- * <emphasis>adjustment1:value</emphasis>.
+ * will keep the "value" property of the two adjustments in sync; the
+ * @celsius_to_fahrenheit function will be called whenever the "value"
+ * property of @adjustment1 changes and will transform the current value
+ * of the property before applying it to the "value" property of @adjustment2.
+ *
+ * Vice versa, the @fahrenheit_to_celsius function will be called whenever
+ * the "value" property of @adjustment2 changes, and will transform the
+ * current value of the property before applying it to the "value" property
+ * of @adjustment1.
  *
  * Note that #GBinding does not resolve cycles by itself; a cycle like
  *
  * either one of the #GObject instances it refers to are finalized, or when
  * the #GBinding instance loses its last reference.
  *
+ * Bindings for languages with garbage collection can use
+ * g_binding_unbind() to explicitly release a binding between the source
+ * and target properties, instead of relying on the last reference on the
+ * binding, source, and target instances to drop.
+ *
  * #GBinding is available since GObject 2.26
  */
 
 
 #include "gbinding.h"
 #include "genums.h"
+#include "gmarshal.h"
 #include "gobject.h"
 #include "gsignal.h"
 #include "gparamspecs.h"
 
 #include "glibintl.h"
 
-#include "gobjectalias.h"
 
 GType
 g_binding_flags_get_type (void)
@@ -124,6 +127,8 @@ g_binding_flags_get_type (void)
       static const GFlagsValue values[] = {
         { G_BINDING_DEFAULT, "G_BINDING_DEFAULT", "default" },
         { G_BINDING_BIDIRECTIONAL, "G_BINDING_BIDIRECTIONAL", "bidirectional" },
+        { G_BINDING_SYNC_CREATE, "G_BINDING_SYNC_CREATE", "sync-create" },
+        { G_BINDING_INVERT_BOOLEAN, "G_BINDING_INVERT_BOOLEAN", "invert-boolean" },
         { 0, NULL, NULL }
       };
       GType g_define_type_id =
@@ -149,8 +154,8 @@ struct _GBinding
   GObject *target;
 
   /* the property names are interned, so they should not be freed */
-  gchar *source_property;
-  gchar *target_property;
+  const gchar *source_property;
+  const gchar *target_property;
 
   GParamSpec *source_pspec;
   GParamSpec *target_pspec;
@@ -203,10 +208,10 @@ add_binding_qdata (GObject  *gobject,
 
       g_object_set_qdata_full (gobject, quark_gbinding,
                                bindings,
-                               (GDestroyNotify) g_hash_table_destroy);
+                               (GDestroyNotify) g_hash_table_unref);
     }
 
-  g_hash_table_insert (bindings, binding, GUINT_TO_POINTER (1));
+  g_hash_table_add (bindings, binding);
 }
 
 static inline void
@@ -216,7 +221,8 @@ remove_binding_qdata (GObject  *gobject,
   GHashTable *bindings;
 
   bindings = g_object_get_qdata (gobject, quark_gbinding);
-  g_hash_table_remove (bindings, binding);
+  if (binding != NULL)
+    g_hash_table_remove (bindings, binding);
 }
 
 /* the basic assumption is that if either the source or the target
@@ -242,6 +248,8 @@ weak_unbind (gpointer  user_data,
 
       g_object_weak_unref (binding->source, weak_unbind, user_data);
       remove_binding_qdata (binding->source, binding);
+
+      binding->source_notify = 0;
       binding->source = NULL;
     }
 
@@ -255,6 +263,8 @@ weak_unbind (gpointer  user_data,
 
       g_object_weak_unref (binding->target, weak_unbind, user_data);
       remove_binding_qdata (binding->target, binding);
+
+      binding->target_notify = 0;
       binding->target = NULL;
     }
 
@@ -284,15 +294,15 @@ default_transform (const GValue *value_a,
         {
           if (g_value_transform (value_a, value_b))
             goto done;
+        }
 
-          g_warning ("%s: Unable to convert a value of type %s to a "
-                     "value of type %s",
-                     G_STRLOC,
-                     g_type_name (G_VALUE_TYPE (value_a)),
-                     g_type_name (G_VALUE_TYPE (value_b)));
+      g_warning ("%s: Unable to convert a value of type %s to a "
+                 "value of type %s",
+                 G_STRLOC,
+                 g_type_name (G_VALUE_TYPE (value_a)),
+                 g_type_name (G_VALUE_TYPE (value_b)));
 
-          return FALSE;
-        }
+      return FALSE;
     }
   else
     g_value_copy (value_a, value_b);
@@ -301,21 +311,44 @@ done:
   return TRUE;
 }
 
+static inline gboolean
+default_invert_boolean_transform (const GValue *value_a,
+                                  GValue       *value_b)
+{
+  gboolean value;
+
+  g_assert (G_VALUE_HOLDS_BOOLEAN (value_a));
+  g_assert (G_VALUE_HOLDS_BOOLEAN (value_b));
+
+  value = g_value_get_boolean (value_a);
+  value = !value;
+
+  g_value_set_boolean (value_b, value);
+
+  return TRUE;
+}
+
 static gboolean
-default_transform_to (GBinding     *binding G_GNUC_UNUSED,
+default_transform_to (GBinding     *binding,
                       const GValue *value_a,
                       GValue       *value_b,
                       gpointer      user_data G_GNUC_UNUSED)
 {
+  if (binding->flags & G_BINDING_INVERT_BOOLEAN)
+    return default_invert_boolean_transform (value_a, value_b);
+
   return default_transform (value_a, value_b);
 }
 
 static gboolean
-default_transform_from (GBinding     *binding G_GNUC_UNUSED,
+default_transform_from (GBinding     *binding,
                         const GValue *value_a,
                         GValue       *value_b,
                         gpointer      user_data G_GNUC_UNUSED)
 {
+  if (binding->flags & G_BINDING_INVERT_BOOLEAN)
+    return default_invert_boolean_transform (value_a, value_b);
+
   return default_transform (value_a, value_b);
 }
 
@@ -325,42 +358,39 @@ on_source_notify (GObject    *gobject,
                   GBinding   *binding)
 {
   const gchar *p_name;
-  GValue source_value = { 0, };
-  GValue target_value = { 0, };
+  GValue from_value = G_VALUE_INIT;
+  GValue to_value = G_VALUE_INIT;
   gboolean res;
 
   if (binding->is_frozen)
     return;
 
-  if (pspec->flags & G_PARAM_STATIC_NAME)
-    p_name = g_intern_static_string (pspec->name);
-  else
-    p_name = g_intern_string (pspec->name);
+  p_name = g_intern_string (pspec->name);
 
   if (p_name != binding->source_property)
     return;
 
-  g_value_init (&source_value, G_PARAM_SPEC_VALUE_TYPE (binding->source_pspec));
-  g_value_init (&target_value, G_PARAM_SPEC_VALUE_TYPE (binding->target_pspec));
+  g_value_init (&from_value, G_PARAM_SPEC_VALUE_TYPE (binding->source_pspec));
+  g_value_init (&to_value, G_PARAM_SPEC_VALUE_TYPE (binding->target_pspec));
 
-  g_object_get_property (binding->source, binding->source_pspec->name, &source_value);
+  g_object_get_property (binding->source, binding->source_pspec->name, &from_value);
 
   res = binding->transform_s2t (binding,
-                                &source_value,
-                                &target_value,
+                                &from_value,
+                                &to_value,
                                 binding->transform_data);
   if (res)
     {
       binding->is_frozen = TRUE;
 
-      g_param_value_validate (binding->target_pspec, &target_value);
-      g_object_set_property (binding->target, binding->target_pspec->name, &target_value);
+      g_param_value_validate (binding->target_pspec, &to_value);
+      g_object_set_property (binding->target, binding->target_pspec->name, &to_value);
 
       binding->is_frozen = FALSE;
     }
 
-  g_value_unset (&source_value);
-  g_value_unset (&target_value);
+  g_value_unset (&from_value);
+  g_value_unset (&to_value);
 }
 
 static void
@@ -369,49 +399,45 @@ on_target_notify (GObject    *gobject,
                   GBinding   *binding)
 {
   const gchar *p_name;
-  GValue source_value = { 0, };
-  GValue target_value = { 0, };
+  GValue from_value = G_VALUE_INIT;
+  GValue to_value = G_VALUE_INIT;
   gboolean res;
 
   if (binding->is_frozen)
     return;
 
-  if (pspec->flags & G_PARAM_STATIC_NAME)
-    p_name = g_intern_static_string (pspec->name);
-  else
-    p_name = g_intern_string (pspec->name);
+  p_name = g_intern_string (pspec->name);
 
   if (p_name != binding->target_property)
     return;
 
-  g_value_init (&source_value, G_PARAM_SPEC_VALUE_TYPE (binding->target_pspec));
-  g_value_init (&target_value, G_PARAM_SPEC_VALUE_TYPE (binding->source_pspec));
+  g_value_init (&from_value, G_PARAM_SPEC_VALUE_TYPE (binding->target_pspec));
+  g_value_init (&to_value, G_PARAM_SPEC_VALUE_TYPE (binding->source_pspec));
 
-  g_object_get_property (binding->target, binding->target_pspec->name, &source_value);
+  g_object_get_property (binding->target, binding->target_pspec->name, &from_value);
 
   res = binding->transform_t2s (binding,
-                                &source_value,
-                                &target_value,
+                                &from_value,
+                                &to_value,
                                 binding->transform_data);
   if (res)
     {
       binding->is_frozen = TRUE;
 
-      g_param_value_validate (binding->source_pspec, &target_value);
-      g_object_set_property (binding->source, binding->source_pspec->name, &target_value);
+      g_param_value_validate (binding->source_pspec, &to_value);
+      g_object_set_property (binding->source, binding->source_pspec->name, &to_value);
 
       binding->is_frozen = FALSE;
     }
 
-  g_value_unset (&source_value);
-  g_value_unset (&target_value);
+  g_value_unset (&from_value);
+  g_value_unset (&to_value);
 }
 
-static void
-g_binding_finalize (GObject *gobject)
+static inline void
+g_binding_unbind_internal (GBinding *binding,
+                           gboolean  unref_binding)
 {
-  GBinding *binding = G_BINDING (gobject);
-
   /* dispose of the transformation data */
   if (binding->notify != NULL)
     {
@@ -421,9 +447,6 @@ g_binding_finalize (GObject *gobject)
       binding->notify = NULL;
     }
 
-  /* we need this in case the source and target instance are still
-   * valid, and it was the GBinding that was unreferenced
-   */
   if (binding->source != NULL)
     {
       if (binding->source_notify != 0)
@@ -431,6 +454,9 @@ g_binding_finalize (GObject *gobject)
 
       g_object_weak_unref (binding->source, weak_unbind, binding);
       remove_binding_qdata (binding->source, binding);
+
+      binding->source_notify = 0;
+      binding->source = NULL;
     }
 
   if (binding->target != NULL)
@@ -440,8 +466,22 @@ g_binding_finalize (GObject *gobject)
 
       g_object_weak_unref (binding->target, weak_unbind, binding);
       remove_binding_qdata (binding->target, binding);
+
+      binding->target_notify = 0;
+      binding->target = NULL;
     }
 
+  if (unref_binding)
+    g_object_unref (binding);
+}
+
+static void
+g_binding_finalize (GObject *gobject)
+{
+  GBinding *binding = G_BINDING (gobject);
+
+  g_binding_unbind_internal (binding, FALSE);
+
   G_OBJECT_CLASS (g_binding_parent_class)->finalize (gobject);
 }
 
@@ -556,9 +596,11 @@ g_binding_constructed (GObject *gobject)
                                                G_CALLBACK (on_target_notify),
                                                binding);
 
-  g_object_weak_ref (binding->target, weak_unbind, binding);
-  add_binding_qdata (binding->target, binding);
-
+  if (binding->target != binding->source)
+    {
+      g_object_weak_ref (binding->target, weak_unbind, binding);
+      add_binding_qdata (binding->target, binding);
+    }
 }
 
 static void
@@ -662,9 +704,9 @@ g_binding_init (GBinding *binding)
  * g_binding_get_flags:
  * @binding: a #GBinding
  *
- * Retrieves the flags passed when constructing the #GBinding
+ * Retrieves the flags passed when constructing the #GBinding.
  *
- * Return value: the #GBindingFlags used by the #GBinding
+ * Returns: the #GBindingFlags used by the #GBinding
  *
  * Since: 2.26
  */
@@ -680,9 +722,9 @@ g_binding_get_flags (GBinding *binding)
  * g_binding_get_source:
  * @binding: a #GBinding
  *
- * Retrieves the #GObject instance used as the source of the binding
+ * Retrieves the #GObject instance used as the source of the binding.
  *
- * Return value: (transfer none): the source #GObject
+ * Returns: (transfer none): the source #GObject
  *
  * Since: 2.26
  */
@@ -698,9 +740,9 @@ g_binding_get_source (GBinding *binding)
  * g_binding_get_target:
  * @binding: a #GBinding
  *
- * Retrieves the #GObject instance used as the target of the binding
+ * Retrieves the #GObject instance used as the target of the binding.
  *
- * Return value: (transfer none): the target #GObject
+ * Returns: (transfer none): the target #GObject
  *
  * Since: 2.26
  */
@@ -717,13 +759,13 @@ g_binding_get_target (GBinding *binding)
  * @binding: a #GBinding
  *
  * Retrieves the name of the property of #GBinding:source used as the source
- * of the binding
+ * of the binding.
  *
- * Return value: the name of the source property
+ * Returns: the name of the source property
  *
  * Since: 2.26
  */
-G_CONST_RETURN gchar *
+const gchar *
 g_binding_get_source_property (GBinding *binding)
 {
   g_return_val_if_fail (G_IS_BINDING (binding), NULL);
@@ -736,13 +778,13 @@ g_binding_get_source_property (GBinding *binding)
  * @binding: a #GBinding
  *
  * Retrieves the name of the property of #GBinding:target used as the target
- * of the binding
+ * of the binding.
  *
- * Return value: the name of the target property
+ * Returns: the name of the target property
  *
  * Since: 2.26
  */
-G_CONST_RETURN gchar *
+const gchar *
 g_binding_get_target_property (GBinding *binding)
 {
   g_return_val_if_fail (G_IS_BINDING (binding), NULL);
@@ -751,20 +793,42 @@ g_binding_get_target_property (GBinding *binding)
 }
 
 /**
+ * g_binding_unbind:
+ * @binding: a #GBinding
+ *
+ * Explicitly releases the binding between the source and the target
+ * property expressed by @binding.
+ *
+ * This function will release the reference that is being held on
+ * the @binding instance; if you want to hold on to the #GBinding instance
+ * after calling g_binding_unbind(), you will need to hold a reference
+ * to it.
+ *
+ * Since: 2.38
+ */
+void
+g_binding_unbind (GBinding *binding)
+{
+  g_return_if_fail (G_IS_BINDING (binding));
+
+  g_binding_unbind_internal (binding, TRUE);
+}
+
+/**
  * g_object_bind_property_full:
- * @source: the source #GObject
+ * @source: (type GObject.Object): the source #GObject
  * @source_property: the property on @source to bind
- * @target: the target #GObject
+ * @target: (type GObject.Object): the target #GObject
  * @target_property: the property on @target to bind
  * @flags: flags to pass to #GBinding
  * @transform_to: (scope notified) (allow-none): the transformation function
- *   from the @source to the @target, or %NULL to use the default
+ *     from the @source to the @target, or %NULL to use the default
  * @transform_from: (scope notified) (allow-none): the transformation function
- *   from the @target to the @source, or %NULL to use the default
+ *     from the @target to the @source, or %NULL to use the default
  * @user_data: custom data to be passed to the transformation functions,
- *   or %NULL
+ *     or %NULL
  * @notify: function to be called when disposing the binding, to free the
- *   resources used by the transformation functions
+ *     resources used by the transformation functions
  *
  * Complete version of g_object_bind_property().
  *
@@ -784,9 +848,15 @@ g_binding_get_target_property (GBinding *binding)
  *
  * A #GObject can have multiple bindings.
  *
- * Return value: (transfer none): the #GBinding instance representing the
- *   binding between the two #GObject instances. The binding is released
- *   whenever the #GBinding reference count reaches zero.
+ * The same @user_data parameter will be used for both @transform_to
+ * and @transform_from transformation functions; the @notify function will
+ * be called once, when the binding is removed. If you need different data
+ * for each transformation function, please use
+ * g_object_bind_property_with_closures() instead.
+ *
+ * Returns: (transfer none): the #GBinding instance representing the
+ *     binding between the two #GObject instances. The binding is released
+ *     whenever the #GBinding reference count reaches zero.
  *
  * Since: 2.26
  */
@@ -815,11 +885,14 @@ g_object_bind_property_full (gpointer               source,
       return NULL;
     }
 
-  if (transform_to == NULL)
-    transform_to = default_transform_to;
-
-  if (transform_from == NULL)
-    transform_from = default_transform_from;
+  /* remove the G_BINDING_INVERT_BOOLEAN flag in case we have
+   * custom transformation functions
+   */
+  if ((flags & G_BINDING_INVERT_BOOLEAN) &&
+      (transform_to != NULL || transform_from != NULL))
+    {
+      flags &= ~G_BINDING_INVERT_BOOLEAN;
+    }
 
   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (source), source_property);
   if (pspec == NULL)
@@ -850,6 +923,18 @@ g_object_bind_property_full (gpointer               source,
       return NULL;
     }
 
+  if ((flags & G_BINDING_INVERT_BOOLEAN) &&
+      !(G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_BOOLEAN))
+    {
+      g_warning ("%s: The G_BINDING_INVERT_BOOLEAN flag can only be used "
+                 "when binding boolean properties; the source property '%s' "
+                 "is of type '%s'",
+                 G_STRLOC,
+                 source_property,
+                 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
+      return NULL;
+    }
+
   pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (target), target_property);
   if (pspec == NULL)
     {
@@ -872,13 +957,25 @@ g_object_bind_property_full (gpointer               source,
   if ((flags & G_BINDING_BIDIRECTIONAL) &&
       !(pspec->flags & G_PARAM_READABLE))
     {
-      g_warning ("%s: The starget object of type %s has no writable property called '%s'",
+      g_warning ("%s: The target object of type %s has no readable property called '%s'",
                  G_STRLOC,
                  G_OBJECT_TYPE_NAME (target),
                  target_property);
       return NULL;
     }
 
+  if ((flags & G_BINDING_INVERT_BOOLEAN) &&
+      !(G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_BOOLEAN))
+    {
+      g_warning ("%s: The G_BINDING_INVERT_BOOLEAN flag can only be used "
+                 "when binding boolean properties; the target property '%s' "
+                 "is of type '%s'",
+                 G_STRLOC,
+                 target_property,
+                 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
+      return NULL;
+    }
+
   binding = g_object_new (G_TYPE_BINDING,
                           "source", source,
                           "source-property", source_property,
@@ -887,20 +984,31 @@ g_object_bind_property_full (gpointer               source,
                           "flags", flags,
                           NULL);
 
-  /* making these properties would be awkward, though not impossible */
-  binding->transform_s2t = transform_to;
-  binding->transform_t2s = transform_from;
+  if (transform_to != NULL)
+    binding->transform_s2t = transform_to;
+
+  if (transform_from != NULL)
+    binding->transform_t2s = transform_from;
+
   binding->transform_data = user_data;
   binding->notify = notify;
 
+  /* synchronize the target with the source by faking an emission of
+   * the ::notify signal for the source property; this will also take
+   * care of the bidirectional binding case because the eventual change
+   * will emit a notification on the target
+   */
+  if (flags & G_BINDING_SYNC_CREATE)
+    on_source_notify (binding->source, binding->source_pspec, binding);
+
   return binding;
 }
 
 /**
  * g_object_bind_property:
- * @source: the source #GObject
+ * @source: (type GObject.Object): the source #GObject
  * @source_property: the property on @source to bind
- * @target: the target #GObject
+ * @target: (type GObject.Object): the target #GObject
  * @target_property: the property on @target to bind
  * @flags: flags to pass to #GBinding
  *
@@ -927,9 +1035,9 @@ g_object_bind_property_full (gpointer               source,
  *
  * A #GObject can have multiple bindings.
  *
- * Return value: (transfer none): the #GBinding instance representing the
- *   binding between the two #GObject instances. The binding is released
- *   whenever the #GBinding reference count reaches zero.
+ * Returns: (transfer none): the #GBinding instance representing the
+ *     binding between the two #GObject instances. The binding is released
+ *     whenever the #GBinding reference count reaches zero.
  *
  * Since: 2.26
  */
@@ -950,5 +1058,176 @@ g_object_bind_property (gpointer       source,
                                       NULL, NULL);
 }
 
-#define __G_BINDING_C__
-#include "gobjectaliasdef.c"
+typedef struct _TransformData
+{
+  GClosure *transform_to_closure;
+  GClosure *transform_from_closure;
+} TransformData;
+
+static gboolean
+bind_with_closures_transform_to (GBinding     *binding,
+                                 const GValue *source,
+                                 GValue       *target,
+                                 gpointer      data)
+{
+  TransformData *t_data = data;
+  GValue params[3] = { G_VALUE_INIT, G_VALUE_INIT, G_VALUE_INIT };
+  GValue retval = G_VALUE_INIT;
+  gboolean res;
+
+  g_value_init (&params[0], G_TYPE_BINDING);
+  g_value_set_object (&params[0], binding);
+
+  g_value_init (&params[1], G_TYPE_VALUE);
+  g_value_set_boxed (&params[1], source);
+
+  g_value_init (&params[2], G_TYPE_VALUE);
+  g_value_set_boxed (&params[2], target);
+
+  g_value_init (&retval, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&retval, FALSE);
+
+  g_closure_invoke (t_data->transform_to_closure, &retval, 3, params, NULL);
+
+  res = g_value_get_boolean (&retval);
+  if (res)
+    {
+      const GValue *out_value = g_value_get_boxed (&params[2]);
+
+      g_assert (out_value != NULL);
+
+      g_value_copy (out_value, target);
+    }
+
+  g_value_unset (&params[0]);
+  g_value_unset (&params[1]);
+  g_value_unset (&params[2]);
+  g_value_unset (&retval);
+
+  return res;
+}
+
+static gboolean
+bind_with_closures_transform_from (GBinding     *binding,
+                                   const GValue *source,
+                                   GValue       *target,
+                                   gpointer      data)
+{
+  TransformData *t_data = data;
+  GValue params[3] = { G_VALUE_INIT, G_VALUE_INIT, G_VALUE_INIT };
+  GValue retval = G_VALUE_INIT;
+  gboolean res;
+
+  g_value_init (&params[0], G_TYPE_BINDING);
+  g_value_set_object (&params[0], binding);
+
+  g_value_init (&params[1], G_TYPE_VALUE);
+  g_value_set_boxed (&params[1], source);
+
+  g_value_init (&params[2], G_TYPE_VALUE);
+  g_value_set_boxed (&params[2], target);
+
+  g_value_init (&retval, G_TYPE_BOOLEAN);
+  g_value_set_boolean (&retval, FALSE);
+
+  g_closure_invoke (t_data->transform_from_closure, &retval, 3, params, NULL);
+
+  res = g_value_get_boolean (&retval);
+  if (res)
+    {
+      const GValue *out_value = g_value_get_boxed (&params[2]);
+
+      g_assert (out_value != NULL);
+
+      g_value_copy (out_value, target);
+    }
+
+  g_value_unset (&params[0]);
+  g_value_unset (&params[1]);
+  g_value_unset (&params[2]);
+  g_value_unset (&retval);
+
+  return res;
+}
+
+static void
+bind_with_closures_free_func (gpointer data)
+{
+  TransformData *t_data = data;
+
+  if (t_data->transform_to_closure != NULL)
+    g_closure_unref (t_data->transform_to_closure);
+
+  if (t_data->transform_from_closure != NULL)
+    g_closure_unref (t_data->transform_from_closure);
+
+  g_slice_free (TransformData, t_data);
+}
+
+/**
+ * g_object_bind_property_with_closures:
+ * @source: (type GObject.Object): the source #GObject
+ * @source_property: the property on @source to bind
+ * @target: (type GObject.Object): the target #GObject
+ * @target_property: the property on @target to bind
+ * @flags: flags to pass to #GBinding
+ * @transform_to: a #GClosure wrapping the transformation function
+ *     from the @source to the @target, or %NULL to use the default
+ * @transform_from: a #GClosure wrapping the transformation function
+ *     from the @target to the @source, or %NULL to use the default
+ *
+ * Creates a binding between @source_property on @source and @target_property
+ * on @target, allowing you to set the transformation functions to be used by
+ * the binding.
+ *
+ * This function is the language bindings friendly version of
+ * g_object_bind_property_full(), using #GClosures instead of
+ * function pointers.
+ *
+ * Rename to: g_object_bind_property_full
+ *
+ * Returns: (transfer none): the #GBinding instance representing the
+ *     binding between the two #GObject instances. The binding is released
+ *     whenever the #GBinding reference count reaches zero.
+ *
+ * Since: 2.26
+ */
+GBinding *
+g_object_bind_property_with_closures (gpointer       source,
+                                      const gchar   *source_property,
+                                      gpointer       target,
+                                      const gchar   *target_property,
+                                      GBindingFlags  flags,
+                                      GClosure      *transform_to,
+                                      GClosure      *transform_from)
+{
+  TransformData *data;
+
+  data = g_slice_new0 (TransformData);
+
+  if (transform_to != NULL)
+    {
+      if (G_CLOSURE_NEEDS_MARSHAL (transform_to))
+        g_closure_set_marshal (transform_to, g_cclosure_marshal_BOOLEAN__BOXED_BOXED);
+
+      data->transform_to_closure = g_closure_ref (transform_to);
+      g_closure_sink (data->transform_to_closure);
+    }
+
+  if (transform_from != NULL)
+    {
+      if (G_CLOSURE_NEEDS_MARSHAL (transform_from))
+        g_closure_set_marshal (transform_from, g_cclosure_marshal_BOOLEAN__BOXED_BOXED);
+
+      data->transform_from_closure = g_closure_ref (transform_from);
+      g_closure_sink (data->transform_from_closure);
+    }
+
+  return g_object_bind_property_full (source, source_property,
+                                      target, target_property,
+                                      flags,
+                                      transform_to != NULL ? bind_with_closures_transform_to : NULL,
+                                      transform_from != NULL ? bind_with_closures_transform_from : NULL,
+                                      data,
+                                      bind_with_closures_free_func);
+}