[perl-Glib] Handle ownership of objects with floating refs differently
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Glib] Handle ownership of objects with floating refs differently
- Date: Fri, 30 Sep 2011 21:00:52 +0000 (UTC)
commit a521e50cb0d82f870cf60e0db88fd880e6e9808d
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Fri Sep 30 22:51:51 2011 +0200
Handle ownership of objects with floating refs differently
The special handling of floating objects introduced by a previous commit
turned out to be too invasive, philosophically and practically.
Practically, because Gtk2/t/GtkAction.t started failing, and I did not
see a way to fix it. And philosophically, because the only reason this
special handling was introduced was to account for some other special
handling in gobject-introspection. But the reaction to this should live
in Glib::Object::Introspection, not in Glib.
So instead, we now just register a custom sink func for
GInitiallyUnowned which does ref_sink+unref. Since sink funcs are
called only when we are supposed to own the object, this means that we
touch the floating flag only if we own the object. This differs
slightly from the Gtk2::Object semantics: its wrappers always sink
floating refs (by enforcing own=TRUE), except when they are inside
GValues (signal invocation, for example).
GObject.xs | 67 +++++++++---------------------------------------------------
1 files changed, 10 insertions(+), 57 deletions(-)
---
diff --git a/GObject.xs b/GObject.xs
index 3230d01..2e34c1e 100644
--- a/GObject.xs
+++ b/GObject.xs
@@ -563,6 +563,15 @@ gperl_object_take_ownership (GObject * object)
g_object_unref (object);
}
+#if GLIB_CHECK_VERSION (2, 10, 0)
+static void
+sink_initially_unowned (GObject *object)
+{
+ g_object_ref_sink (object);
+ g_object_unref (object);
+}
+#endif
+
=item void gperl_object_set_no_warn_unreg_subclass (GType gtype, gboolean nowarn)
@@ -926,63 +935,6 @@ gperl_new_object (GObject * object,
SvRV (sv), SvREFCNT (SvRV (sv)));
#endif
- /*
- * special handling for objects that have a floating ref. there are
- * three types of these objects that we can encounter:
- *
- * A: GInitiallyUnowned descendant, wrapped manually such that always
- * own=1, with a custom sink func; prototype: Gtk2::Object
- * B: GInitiallyUnowned descendant, wrapped via introspection
- * (i.e. always own=0 and no custom sink func); prototype:
- * Gtk3::Object
- * C: GInitiallyUnowned descendant, wrapped manually, no special own
- * handling, no custom sink func; prototype: ?
- *
- * then, with the code below, we have the following tables of changes
- * to object->ref_count:
- *
- * A own=1 own=0
- * floating=1 Â0 does not
- * floating=0 +1 happen
- *
- * B own=1 own=0
- * floating=1 does not Â0
- * floating=0 happen +1
- *
- * C own=1 own=0
- * floating=1 Â0 Â0
- * floating=0 Â0 +1
- *
- * These are the changes we want.
- *
- * There's also an alternative approach: Register a custom sink func
- * for GInitiallyUnowned that does ref_sink+unref, and then simply
- * enforce own=1 below for GInitiallyUnowned descendants. This would
- * indeed be mostly equivalent to the current code, and would
- * conceptually be cleaner. But I worry that their might be some weird
- * class out there that does not descend from GInitiallyUnowned to get
- * floating ref behavior but instead uses gobject's floating refs
- * manually, via g_object_force_floating.
- */
-#if GLIB_CHECK_VERSION (2, 10, 0)
- if (g_object_is_floating (object)) {
- /* clear the floating flag. */
- g_object_ref_sink (object);
- /* always assume ownership, irregardless of the ownership
- * setting that was passed in. this is somewhat of a hack for
- * gobject-introspection: it always sets transfer=none for
- * GInitiallyUnowned descendants. but Gtk2 effectively does
- * exactly the same thing for Gtk2::Object by always passing
- * own=1. */
- g_object_unref (object);
- /* we have already taken ownership, so don't try to do it
- * again. for cases A and B from above,
- * gperl_object_take_ownership would do nothing, so this just
- * saves a few cycles. but for case C, leaving own=1 would
- * result in the object being finalized prematurely. */
- own = FALSE;
- }
-#endif
if (own)
gperl_object_take_ownership (object);
@@ -1247,6 +1199,7 @@ BOOT:
gperl_register_object (G_TYPE_OBJECT, "Glib::Object");
#if GLIB_CHECK_VERSION (2, 10, 0)
gperl_register_object (G_TYPE_INITIALLY_UNOWNED, "Glib::InitiallyUnowned");
+ gperl_register_sink_func (G_TYPE_INITIALLY_UNOWNED, sink_initially_unowned);
#endif
wrapper_quark = g_quark_from_static_string ("Perl-wrapper-object");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]