bus, clock: make sure these never have a floating ref
authorTim-Philipp Müller <tim@centricular.net>
Mon, 2 Jul 2012 23:07:11 +0000 (00:07 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Mon, 9 Jul 2012 12:09:45 +0000 (13:09 +0100)
Clear the initial floating ref in the init function for
busses and clocks. These objects can be set on multiple
elements, so there's no clear parent-child relationship
here. Ideally we'd just not make them derive from
GInitiallyUnowned at all, but since we want to keep
using GstObject features for debugging, we'll just do
it like this.

This should also fix some problems with bindings, which
seem to get confused when they get floating refs from
non-constructor functions (or functions annotated to
have a 'transfer full' return type). This works now:

from gi.repository import GObject, Gst

GObject.threads_init()
Gst.init(None)

pipeline=Gst.Pipeline()
bus = pipeline.get_bus()
pipeline.set_state(Gst.State.NULL)
del pipeline;

https://bugzilla.gnome.org/show_bug.cgi?id=679286
https://bugzilla.gnome.org/show_bug.cgi?id=657202

gst/gstbus.c
gst/gstclock.c
gst/gstsystemclock.c
tests/check/gst/gstpipeline.c

index 1a82f54..898fc5e 100644 (file)
@@ -228,6 +228,9 @@ gst_bus_init (GstBus * bus)
   g_mutex_init (&bus->priv->queue_lock);
   bus->priv->queue = gst_atomic_queue_new (32);
 
+  /* clear floating flag */
+  gst_object_ref_sink (bus);
+
   GST_DEBUG_OBJECT (bus, "created");
 }
 
index 3d9e73b..c84700d 100644 (file)
@@ -699,6 +699,9 @@ gst_clock_init (GstClock * clock)
   priv->time_index = 0;
   priv->timeout = DEFAULT_TIMEOUT;
   priv->times = g_new0 (GstClockTime, 4 * priv->window_size);
+
+  /* clear floating flag */
+  gst_object_ref_sink (clock);
 }
 
 static void
index 9cac9ee..8385e1a 100644 (file)
@@ -304,9 +304,7 @@ gst_system_clock_obtain (void)
     clock = g_object_new (GST_TYPE_SYSTEM_CLOCK,
         "name", "GstSystemClock", NULL);
 
-    /* we created the global clock; take ownership so
-     * we can hand out instances later */
-    gst_object_ref_sink (clock);
+    g_assert (!g_object_is_floating (G_OBJECT (clock)));
 
     _the_system_clock = clock;
     g_mutex_unlock (&_gst_sysclock_mutex);
index 899c017..4e34eea 100644 (file)
@@ -125,6 +125,9 @@ GST_START_TEST (test_get_bus)
   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline after get_bus", 1);
   ASSERT_OBJECT_REFCOUNT (bus, "bus", 2);
 
+  /* bindings don't like the floating flag to be set here */
+  fail_if (g_object_is_floating (bus));
+
   gst_object_unref (pipeline);
 
   ASSERT_OBJECT_REFCOUNT (bus, "bus after unref pipeline", 1);