From fd5f5ad8d0426daad63bf90d397659b0ffbd9d47 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 7 Oct 2005 16:21:22 +0000 Subject: [PATCH] gst/pygstiterator.c: Unref the return value, since the iterator refs them. Original commit message from CVS: * gst/pygstiterator.c: Unref the return value, since the iterator refs them. * testsuite/test_iterator.py: Added more test cases, re-enabled gcverify now the bug is fixed * gst/pygstminiobject.c: (pygstminiobject_register_wrapper), (pygstminiobject_new), (pygstminiobject_dealloc): Comments to better track the creation/destruction of PyGstMiniObject Fixed naming (gst.GstMiniObject => gst.MiniObject) * testsuite/python.supp: Updated python specific valgrind suppressions to latest version and added x86_64 cases * testsuite/gstpython.supp: Series of suppressions for errors/leaks not solvable within gst-python * testsuite/Makefile.am: Added gstpython.supp --- ChangeLog | 6 ++++++ gst/pygstiterator.c | 21 ++++++++++++++----- testsuite/Makefile.am | 4 ++-- testsuite/test_iterator.py | 41 ++++++++++++++++++++++++++++++++++---- 4 files changed, 61 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66ab013eb1..4a94473ce2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2005-10-07 Edward Hervey + * gst/pygstiterator.c: + Unref the return value, since the iterator refs them. + + * testsuite/test_iterator.py: + Added more test cases, re-enabled gcverify now the bug is fixed + * gst/pygstminiobject.c: (pygstminiobject_register_wrapper), (pygstminiobject_new), (pygstminiobject_dealloc): Comments to better track the creation/destruction of PyGstMiniObject diff --git a/gst/pygstiterator.c b/gst/pygstiterator.c index eb184b7125..3f1285795a 100644 --- a/gst/pygstiterator.c +++ b/gst/pygstiterator.c @@ -35,7 +35,7 @@ pygst_iterator_iter_next(PyGstIterator *self) gpointer element; PyObject *retval = NULL; GstIteratorResult result; - + result = gst_iterator_next(self->iter, &element); switch (result) { @@ -43,11 +43,20 @@ pygst_iterator_iter_next(PyGstIterator *self) PyErr_SetNone(PyExc_StopIteration); break; case GST_ITERATOR_OK: - if (g_type_is_a(self->iter->type, G_TYPE_OBJECT)) + if (g_type_is_a(self->iter->type, GST_TYPE_OBJECT)) { retval = pygstobject_new(G_OBJECT(element)); - else { + pygst_object_unref (element); + } else if (g_type_is_a(self->iter->type, G_TYPE_OBJECT)) { + retval = pygobject_new(G_OBJECT(element)); + g_object_unref (element); + } else if (g_type_is_a(self->iter->type, GST_TYPE_MINI_OBJECT)) { + retval = pygstminiobject_new(GST_MINI_OBJECT(element)); + gst_mini_object_unref (element); + } else { + const gchar *type_name; + type_name = g_type_name(self->iter->type); PyErr_Format(PyExc_TypeError, "Unsupported child type: %s", - g_type_name(self->iter->type)); + type_name ? type_name : "unknown"); } break; case GST_ITERATOR_RESYNC: @@ -61,7 +70,6 @@ pygst_iterator_iter_next(PyGstIterator *self) g_assert_not_reached(); break; } - return retval; } @@ -138,7 +146,10 @@ PyObject* pygst_iterator_new(GstIterator *iter) { PyGstIterator *self; + self = PyObject_NEW(PyGstIterator, &PyGstIterator_Type); self->iter = iter; + GST_DEBUG("self:%p , iterator:%p, type:%d", + self, self->iter, self->iter->type); return (PyObject *) self; } diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index d3a6dcbc69..8c791a3d4e 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -17,7 +17,7 @@ testhelper_la_SOURCES = \ testhelper.la: $(testhelper_la_OBJECTS) $(testhelper_la_DEPENDENCIES) $(LINK) -rpath $(pkgpyexecdir) $(testhelper_la_LDFLAGS) $(testhelper_la_OBJECTS) $(testhelper_la_LIBADD) $(LIBS) -TESTS = \ +tests = \ test_bin.py \ test_buffer.py \ test_caps.py \ @@ -40,7 +40,7 @@ check-verbose: testhelper.la @VERBOSE=yes PYTHONPATH=$(top_builddir):$(top_builddir)/gst/.libs:`pwd`:$(top_srcdir):$(PYTHONPATH) $(PYTHON) $(srcdir)/runtests.py @rm -fr *.pyc -EXTRA_DIST = $(TESTS) common.py runtests.py test-object.h python.supp gstpython.supp +EXTRA_DIST = $(tests) common.py runtests.py test-object.h python.supp gstpython.supp if HAVE_VALGRIND check-valgrind: diff --git a/testsuite/test_iterator.py b/testsuite/test_iterator.py index 6a6eeb884d..4a4e22542c 100644 --- a/testsuite/test_iterator.py +++ b/testsuite/test_iterator.py @@ -21,11 +21,44 @@ import unittest from common import gst, TestCase class IteratorTest(TestCase): - # XXX: This is busted. Testsuite or iterator bindings? - def gcverify(self): - pass - # XXX: Elements + def testBinIterateElements(self): + pipeline = gst.parse_launch("fakesrc name=src ! fakesink name=sink") + elements = list(pipeline.elements()) + fakesrc = pipeline.get_by_name("src") + fakesink = pipeline.get_by_name("sink") + + self.assertEqual(len(elements), 2) + self.failUnless(fakesrc in elements) + self.failUnless(fakesink in elements) + + pipeline.remove(fakesrc) + elements = list(pipeline.elements()) + + self.assertEqual(len(elements), 1) + self.failUnless(not fakesrc in pipeline) + + # XXX : There seems to be a problem about the GType + # set in gst_bin_iterated_sorted + +## def testBinIterateSorted(self): +## gst.info("testBinIterateSorted beginning") +## pipeline = gst.parse_launch("fakesrc name=src ! fakesink name=sink") +## gst.info("before calling pipeline.sorted()") +## elements = list(pipeline.sorted()) +## gst.info("after calling pipeline.sorted()") +## fakesrc = pipeline.get_by_name("src") +## fakesink = pipeline.get_by_name("sink") + +## self.assertEqual(elements[0], fakesink) +## self.assertEqual(elements[1], fakesrc) +## gst.info("testBinIterateSorted end") + + def testBinIterateSinks(self): + pipeline = gst.parse_launch("fakesrc name=src ! fakesink name=sink") + elements = list(pipeline.elements()) + fakesrc = pipeline.get_by_name("src") + fakesink = pipeline.get_by_name("sink") def testIteratePadsFakeSrc(self): fakesrc = gst.element_factory_make('fakesrc')