diff options
| author | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2010-06-21 17:33:56 +0200 |
|---|---|---|
| committer | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2010-06-21 17:36:32 +0200 |
| commit | 00a85f6a844714d1715e2f67431747d1a4cdacb1 (patch) | |
| tree | f78c8e6a104c9ea5a189c88f1cae21e7e4b3e184 /tests/test-floating.c | |
| parent | e71238a699ae783fd1a59c8a76e3555d8066cf82 (diff) | |
| download | pygobject-00a85f6a844714d1715e2f67431747d1a4cdacb1.tar.gz | |
Fall back to use the floating references API in glib if there isn't a sinkfunc defined.
* tests/*: Add ref counting tests for floating objects
* gobject/gobjectmodule.c, gobject/pygobject.c: Fall back to g_object_ref_sink
or g_object_ref if there isn't a sinkfunc defined. Make sure that
pygobject_sink gets called only once per GObject instance.
https://bugzilla.gnome.org/show_bug.cgi?id=583909
Diffstat (limited to 'tests/test-floating.c')
| -rw-r--r-- | tests/test-floating.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/tests/test-floating.c b/tests/test-floating.c new file mode 100644 index 00000000..918a42d0 --- /dev/null +++ b/tests/test-floating.c @@ -0,0 +1,95 @@ +/* + * test-floating.c - Source for TestFloatingWithSinkFunc and TestFloatingWithoutSinkFunc + * Copyright (C) 2010 Collabora Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "test-floating.h" + +/* TestFloatingWithSinkFunc */ + +G_DEFINE_TYPE(TestFloatingWithSinkFunc, test_floating_with_sink_func, G_TYPE_INITIALLY_UNOWNED) + +static void +test_floating_with_sink_func_finalize (GObject *gobject) +{ + TestFloatingWithSinkFunc *object = TEST_FLOATING_WITH_SINK_FUNC (gobject); + + if (g_object_is_floating (object)) + { + g_warning ("A floating object was finalized. This means that someone\n" + "called g_object_unref() on an object that had only a floating\n" + "reference; the initial floating reference is not owned by anyone\n" + "and must be removed with g_object_ref_sink()."); + } + + G_OBJECT_CLASS (test_floating_with_sink_func_parent_class)->finalize (gobject); +} + +static void +test_floating_with_sink_func_class_init (TestFloatingWithSinkFuncClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = test_floating_with_sink_func_finalize; +} + +static void +test_floating_with_sink_func_init (TestFloatingWithSinkFunc *self) +{ +} + +void +sink_test_floating_with_sink_func (GObject *object) +{ + if (g_object_is_floating(object)) { + g_object_ref_sink(object); + } +} + +/* TestFloatingWithoutSinkFunc */ + +G_DEFINE_TYPE(TestFloatingWithoutSinkFunc, test_floating_without_sink_func, G_TYPE_INITIALLY_UNOWNED) + +static void +test_floating_without_sink_func_finalize (GObject *gobject) +{ + TestFloatingWithoutSinkFunc *object = TEST_FLOATING_WITHOUT_SINK_FUNC (gobject); + + if (g_object_is_floating (object)) + { + g_warning ("A floating object was finalized. This means that someone\n" + "called g_object_unref() on an object that had only a floating\n" + "reference; the initial floating reference is not owned by anyone\n" + "and must be removed without g_object_ref_sink()."); + } + + G_OBJECT_CLASS (test_floating_without_sink_func_parent_class)->finalize (gobject); +} + +static void +test_floating_without_sink_func_class_init (TestFloatingWithoutSinkFuncClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = test_floating_without_sink_func_finalize; +} + +static void +test_floating_without_sink_func_init (TestFloatingWithoutSinkFunc *self) +{ +} + |
