[glib] gobject: Handle ref_count==0 in notify_by_pspec
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gobject: Handle ref_count==0 in notify_by_pspec
- Date: Wed, 14 Aug 2013 17:11:13 +0000 (UTC)
commit 4b334ef8f1393c997a2d83de4ffe0976dff238c3
Author: Nick Schermer <nick xfce org>
Date: Wed Aug 7 21:01:00 2013 +0200
gobject: Handle ref_count==0 in notify_by_pspec
Just like g_object_notify, check for a zero ref_count in
g_object_notify_by_pspec and leave if it is 0.
This allows using functions in ->finalize() that possibly also
notify a property change on the object. Previously,
this resulted in an error from g_object_ref.
https://bugzilla.gnome.org/show_bug.cgi?id=705570
gobject/gobject.c | 3 +++
gobject/tests/properties.c | 7 +++++++
2 files changed, 10 insertions(+), 0 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index d843d57..96a9d4f 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -1238,6 +1238,9 @@ g_object_notify_by_pspec (GObject *object,
g_return_if_fail (G_IS_OBJECT (object));
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
+ if (g_atomic_int_get (&object->ref_count) == 0)
+ return;
+
g_object_ref (object);
g_object_notify_by_spec_internal (object, pspec);
g_object_unref (object);
diff --git a/gobject/tests/properties.c b/gobject/tests/properties.c
index 27c2a22..7140f90 100644
--- a/gobject/tests/properties.c
+++ b/gobject/tests/properties.c
@@ -67,6 +67,13 @@ test_object_finalize (GObject *gobject)
{
g_free (((TestObject *) gobject)->baz);
+ /* When the ref_count of an object is zero it is still
+ * possible to notify the property, but it should do
+ * nothing and silenty quit (bug #705570)
+ */
+ g_object_notify (gobject, "foo");
+ g_object_notify_by_pspec (gobject, properties[PROP_BAR]);
+
G_OBJECT_CLASS (test_object_parent_class)->finalize (gobject);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]