summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/reference/gobject/gobject-sections.txt2
-rw-r--r--gobject/gbinding.c54
-rw-r--r--gobject/gbinding.h4
3 files changed, 60 insertions, 0 deletions
diff --git a/docs/reference/gobject/gobject-sections.txt b/docs/reference/gobject/gobject-sections.txt
index 36552b1b3..54fbccaf8 100644
--- a/docs/reference/gobject/gobject-sections.txt
+++ b/docs/reference/gobject/gobject-sections.txt
@@ -978,8 +978,10 @@ g_io_condition_get_type
GBinding
GBindingFlags
g_binding_get_source
+g_binding_dup_source
g_binding_get_source_property
g_binding_get_target
+g_binding_dup_target
g_binding_get_target_property
g_binding_get_flags
g_binding_unbind
diff --git a/gobject/gbinding.c b/gobject/gbinding.c
index 1448adb36..8451dc48e 100644
--- a/gobject/gbinding.c
+++ b/gobject/gbinding.c
@@ -793,6 +793,10 @@ g_binding_get_flags (GBinding *binding)
* strong reference to the source. If the source is destroyed before the
* binding then this function will return %NULL.
*
+ * Use g_binding_dup_source() if the source or binding are used from different
+ * threads as otherwise the pointer returned from this function might become
+ * invalid if the source is finalized from another thread in the meantime.
+ *
* Returns: (transfer none) (nullable): the source #GObject, or %NULL if the
* source does not exist any more.
*
@@ -815,6 +819,29 @@ g_binding_get_source (GBinding *binding)
}
/**
+ * g_binding_dup_source:
+ * @binding: a #GBinding
+ *
+ * Retrieves the #GObject instance used as the source of the binding.
+ *
+ * A #GBinding can outlive the source #GObject as the binding does not hold a
+ * strong reference to the source. If the source is destroyed before the
+ * binding then this function will return %NULL.
+ *
+ * Returns: (transfer full) (nullable): the source #GObject, or %NULL if the
+ * source does not exist any more.
+ *
+ * Since: 2.68
+ */
+GObject *
+g_binding_dup_source (GBinding *binding)
+{
+ g_return_val_if_fail (G_IS_BINDING (binding), NULL);
+
+ return g_weak_ref_get (&binding->source);
+}
+
+/**
* g_binding_get_target:
* @binding: a #GBinding
*
@@ -824,6 +851,10 @@ g_binding_get_source (GBinding *binding)
* strong reference to the target. If the target is destroyed before the
* binding then this function will return %NULL.
*
+ * Use g_binding_dup_target() if the target or binding are used from different
+ * threads as otherwise the pointer returned from this function might become
+ * invalid if the target is finalized from another thread in the meantime.
+ *
* Returns: (transfer none) (nullable): the target #GObject, or %NULL if the
* target does not exist any more.
*
@@ -846,6 +877,29 @@ g_binding_get_target (GBinding *binding)
}
/**
+ * g_binding_dup_target:
+ * @binding: a #GBinding
+ *
+ * Retrieves the #GObject instance used as the target of the binding.
+ *
+ * A #GBinding can outlive the target #GObject as the binding does not hold a
+ * strong reference to the target. If the target is destroyed before the
+ * binding then this function will return %NULL.
+ *
+ * Returns: (transfer full) (nullable): the target #GObject, or %NULL if the
+ * target does not exist any more.
+ *
+ * Since: 2.68
+ */
+GObject *
+g_binding_dup_target (GBinding *binding)
+{
+ g_return_val_if_fail (G_IS_BINDING (binding), NULL);
+
+ return g_weak_ref_get (&binding->target);
+}
+
+/**
* g_binding_get_source_property:
* @binding: a #GBinding
*
diff --git a/gobject/gbinding.h b/gobject/gbinding.h
index b4eb233b3..f269ad5a8 100644
--- a/gobject/gbinding.h
+++ b/gobject/gbinding.h
@@ -110,8 +110,12 @@ GLIB_AVAILABLE_IN_ALL
GBindingFlags g_binding_get_flags (GBinding *binding);
GLIB_AVAILABLE_IN_ALL
GObject * g_binding_get_source (GBinding *binding);
+GLIB_AVAILABLE_IN_2_68
+GObject * g_binding_dup_source (GBinding *binding);
GLIB_AVAILABLE_IN_ALL
GObject * g_binding_get_target (GBinding *binding);
+GLIB_AVAILABLE_IN_2_68
+GObject * g_binding_dup_target (GBinding *binding);
GLIB_AVAILABLE_IN_ALL
const gchar * g_binding_get_source_property (GBinding *binding);
GLIB_AVAILABLE_IN_ALL