[pygobject] Drop support for sink functions.
- From: Steve FrÃcinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Drop support for sink functions.
- Date: Fri, 26 Aug 2011 09:14:32 +0000 (UTC)
commit 3961a405e1bddef22e1a5a0c7aa3ae55e4ec09ad
Author: Steve FrÃcinaux <code istique net>
Date: Fri Aug 26 10:45:59 2011 +0200
Drop support for sink functions.
Sink functions were meant to deal with floating references in a custom
way. They are not useful anymore with the dynamic bindings.
https://bugzilla.gnome.org/show_bug.cgi?id=642233
gi/_gobject/gobjectmodule.c | 1 -
gi/_gobject/pygobject.c | 53 --------------------------------------
gi/_gobject/pygobject.h | 4 ---
tests/test-floating.c | 59 ++++++------------------------------------
tests/test-floating.h | 42 ++++++++----------------------
tests/test_gobject.py | 13 ++-------
tests/testhelpermodule.c | 32 ++++++----------------
7 files changed, 32 insertions(+), 172 deletions(-)
---
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c
index ac0a6f4..a2f62af 100644
--- a/gi/_gobject/gobjectmodule.c
+++ b/gi/_gobject/gobjectmodule.c
@@ -2408,7 +2408,6 @@ disable_warning_redirections(void)
struct _PyGObject_Functions pygobject_api_functions = {
pygobject_register_class,
pygobject_register_wrapper,
- pygobject_register_sinkfunc,
pygobject_lookup_class,
pygobject_new,
diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 56b9aef..07f0295 100644
--- a/gi/_gobject/pygobject.c
+++ b/gi/_gobject/pygobject.c
@@ -113,12 +113,6 @@ pygobject_get_inst_data(PyGObject *self)
}
-typedef struct {
- GType type;
- void (* sinkfunc)(GObject *object);
-} SinkFunc;
-static GArray *sink_funcs = NULL;
-
GHashTable *custom_type_registration = NULL;
PyTypeObject *PyGObject_MetaType = NULL;
@@ -135,17 +129,6 @@ PyTypeObject *PyGObject_MetaType = NULL;
void
pygobject_sink(GObject *obj)
{
- if (sink_funcs) {
- gint i;
-
- for (i = 0; i < sink_funcs->len; i++) {
- if (g_type_is_a(G_OBJECT_TYPE(obj),
- g_array_index(sink_funcs, SinkFunc, i).type)) {
- g_array_index(sink_funcs, SinkFunc, i).sinkfunc(obj);
- return;
- }
- }
- }
/* The default behaviour for GInitiallyUnowned subclasses is to call ref_sink().
* - if the object is new and owned by someone else, its ref has been sunk and
* we need to keep the one from that someone and add our own "fresh ref"
@@ -157,42 +140,6 @@ pygobject_sink(GObject *obj)
}
}
-/**
- * pygobject_register_sinkfunc:
- * type: the GType the sink function applies to.
- * sinkfunc: a function to remove the floating reference on an object.
- *
- * As Python handles reference counting for us, the "floating
- * reference" code in GTK is not all that useful. In fact, it can
- * cause leaks. For this reason, PyGTK removes the floating
- * references on objects on construction.
- *
- * The sinkfunc should be able to remove the floating reference on
- * instances of the given type, or any subclasses.
- *
- * Deprecated: Since 2.22, sinkfuncs are not needed.
- */
-void
-pygobject_register_sinkfunc(GType type, void (* sinkfunc)(GObject *object))
-{
- SinkFunc sf;
-
- g_message ("pygobject_register_sinkfunc is deprecated (%s)",
- g_type_name(type));
-
-#if 0
- g_return_if_fail(G_TYPE_IS_OBJECT(type));
-#endif
- g_return_if_fail(sinkfunc != NULL);
-
- if (!sink_funcs)
- sink_funcs = g_array_new(FALSE, FALSE, sizeof(SinkFunc));
-
- sf.type = type;
- sf.sinkfunc = sinkfunc;
- g_array_append_val(sink_funcs, sf);
-}
-
typedef struct {
PyObject_HEAD
GParamSpec **props;
diff --git a/gi/_gobject/pygobject.h b/gi/_gobject/pygobject.h
index 7952e5e..0688fc7 100644
--- a/gi/_gobject/pygobject.h
+++ b/gi/_gobject/pygobject.h
@@ -92,8 +92,6 @@ struct _PyGObject_Functions {
void (* register_class)(PyObject *dict, const gchar *class_name,
GType gtype, PyTypeObject *type, PyObject *bases);
void (* register_wrapper)(PyObject *self);
- void (* register_sinkfunc)(GType type,
- void (* sinkfunc)(GObject *object));
PyTypeObject *(* lookup_class)(GType type);
PyObject *(* newgobj)(GObject *obj);
@@ -211,8 +209,6 @@ struct _PyGObject_Functions *_PyGObject_API;
#define pygobject_register_class (_PyGObject_API->register_class)
#define pygobject_register_wrapper (_PyGObject_API->register_wrapper)
-/* This is deprecated, sinkfuncs are not needed anymore */
-#define pygobject_register_sinkfunc (_PyGObject_API->register_sinkfunc)
#define pygobject_lookup_class (_PyGObject_API->lookup_class)
#define pygobject_new (_PyGObject_API->newgobj)
#define pyg_closure_new (_PyGObject_API->closure_new)
diff --git a/tests/test-floating.c b/tests/test-floating.c
index 8e8ba5d..18e4a46 100644
--- a/tests/test-floating.c
+++ b/tests/test-floating.c
@@ -1,5 +1,5 @@
/*
- * test-floating.c - Source for TestFloatingWithSinkFunc and TestFloatingWithoutSinkFunc
+ * test-floating.c - Source for TestFloating
* Copyright (C) 2010 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
@@ -19,55 +19,14 @@
#include "test-floating.h"
-/* TestFloatingWithSinkFunc */
+/* TestFloating */
-G_DEFINE_TYPE(TestFloatingWithSinkFunc, test_floating_with_sink_func, G_TYPE_INITIALLY_UNOWNED)
+G_DEFINE_TYPE(TestFloating, test_floating, G_TYPE_INITIALLY_UNOWNED)
static void
-test_floating_with_sink_func_finalize (GObject *gobject)
+test_floating_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);
+ TestFloating *object = TEST_FLOATING (gobject);
if (g_object_is_floating (object))
{
@@ -77,19 +36,19 @@ test_floating_without_sink_func_finalize (GObject *gobject)
"and must be removed without g_object_ref_sink().");
}
- G_OBJECT_CLASS (test_floating_without_sink_func_parent_class)->finalize (gobject);
+ G_OBJECT_CLASS (test_floating_parent_class)->finalize (gobject);
}
static void
-test_floating_without_sink_func_class_init (TestFloatingWithoutSinkFuncClass *klass)
+test_floating_class_init (TestFloatingClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->finalize = test_floating_without_sink_func_finalize;
+ gobject_class->finalize = test_floating_finalize;
}
static void
-test_floating_without_sink_func_init (TestFloatingWithoutSinkFunc *self)
+test_floating_init (TestFloating *self)
{
}
diff --git a/tests/test-floating.h b/tests/test-floating.h
index bf4e101..ecf2462 100644
--- a/tests/test-floating.h
+++ b/tests/test-floating.h
@@ -1,5 +1,5 @@
/*
- * test-floating.h - Header for TestFloatingWithSinkFunc and TestFloatingWithoutSinkFunc
+ * test-floating.h - Header for TestFloating
* Copyright (C) 2010 Collabora Ltd.
*
* This library is free software; you can redistribute it and/or
@@ -19,44 +19,24 @@
#include <glib-object.h>
-/* TestFloatingWithSinkFunc */
+/* TestFloating */
typedef struct {
GInitiallyUnowned parent;
-} TestFloatingWithSinkFunc;
+} TestFloating;
typedef struct {
GInitiallyUnownedClass parent_class;
-} TestFloatingWithSinkFuncClass;
+} TestFloatingClass;
-#define TEST_TYPE_FLOATING_WITH_SINK_FUNC (test_floating_with_sink_func_get_type())
-#define TEST_FLOATING_WITH_SINK_FUNC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_FLOATING_WITH_SINK_FUNC, TestFloatingWithSinkFunc))
-#define TEST_FLOATING_WITH_SINK_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_FLOATING_WITH_SINK_FUNC, TestFloatingWithSinkFuncClass))
-#define TEST_IS_FLOATING_WITH_SINK_FUNC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_FLOATING_WITH_SINK_FUNC))
-#define TEST_IS_FLOATING_WITH_SINK_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TEST_TYPE_FLOATING_WITH_SINK_FUNC))
-#define TEST_FLOATING_WITH_SINK_FUNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TEST_TYPE_FLOATING_WITH_SINK_FUNC, TestFloatingWithSinkFuncClass))
+#define TEST_TYPE_FLOATING (test_floating_get_type())
+#define TEST_FLOATING(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_FLOATING, TestFloating))
+#define TEST_FLOATING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_FLOATING, TestFloatingClass))
+#define TEST_IS_FLOATING(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_FLOATING))
+#define TEST_IS_FLOATING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TEST_TYPE_FLOATING))
+#define TEST_FLOATING_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TEST_TYPE_FLOATING, TestFloatingClass))
-GType test_floating_with_sink_func_get_type (void);
-void sink_test_floating_with_sink_func (GObject *object);
-
-/* TestFloatingWithoutSinkFunc */
-
-typedef struct {
- GInitiallyUnowned parent;
-} TestFloatingWithoutSinkFunc;
-
-typedef struct {
- GInitiallyUnownedClass parent_class;
-} TestFloatingWithoutSinkFuncClass;
-
-#define TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC (test_floating_without_sink_func_get_type())
-#define TEST_FLOATING_WITHOUT_SINK_FUNC(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC, TestFloatingWithoutSinkFunc))
-#define TEST_FLOATING_WITHOUT_SINK_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC, TestFloatingWithoutSinkFuncClass))
-#define TEST_IS_FLOATING_WITHOUT_SINK_FUNC(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC))
-#define TEST_IS_FLOATING_WITHOUT_SINK_FUNC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC))
-#define TEST_FLOATING_WITHOUT_SINK_FUNC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC, TestFloatingWithoutSinkFuncClass))
-
-GType test_floating_without_sink_func_get_type (void);
+GType test_floating_get_type (void);
/* TestOwnedByLibrary */
diff --git a/tests/test_gobject.py b/tests/test_gobject.py
index dbbc5b7..eef9cf6 100644
--- a/tests/test_gobject.py
+++ b/tests/test_gobject.py
@@ -23,18 +23,11 @@ class TestReferenceCounting(unittest.TestCase):
obj = GObject.new(GObject.GObject)
self.assertEquals(obj.__grefcount__, 1)
- def testFloatingWithSinkFunc(self):
- obj = testhelper.FloatingWithSinkFunc()
+ def testFloating(self):
+ obj = testhelper.Floating()
self.assertEquals(obj.__grefcount__, 1)
- obj = GObject.new(testhelper.FloatingWithSinkFunc)
- self.assertEquals(obj.__grefcount__, 1)
-
- def testFloatingWithoutSinkFunc(self):
- obj = testhelper.FloatingWithoutSinkFunc()
- self.assertEquals(obj.__grefcount__, 1)
-
- obj = GObject.new(testhelper.FloatingWithoutSinkFunc)
+ obj = GObject.new(testhelper.Floating)
self.assertEquals(obj.__grefcount__, 1)
def testOwnedByLibrary(self):
diff --git a/tests/testhelpermodule.c b/tests/testhelpermodule.c
index b242a34..202239d 100644
--- a/tests/testhelpermodule.c
+++ b/tests/testhelpermodule.c
@@ -224,11 +224,8 @@ static const GInterfaceInfo __TestInterface__iinfo = {
NULL
};
-/* TestFloatingWithSinkFunc */
-PYGLIB_DEFINE_TYPE("testhelper.FloatingWithSinkFunc", PyTestFloatingWithSinkFunc_Type, PyGObject);
-
-/* TestFloatingWithoutSinkFunc */
-PYGLIB_DEFINE_TYPE("testhelper.FloatingWithoutSinkFunc", PyTestFloatingWithoutSinkFunc_Type, PyGObject);
+/* TestFloating */
+PYGLIB_DEFINE_TYPE("testhelper.Floating", PyTestFloating_Type, PyGObject);
/* TestOwnedByLibrary */
PYGLIB_DEFINE_TYPE("testhelper.OwnedByLibrary", PyTestOwnedByLibrary_Type, PyGObject);
@@ -566,26 +563,15 @@ PYGLIB_MODULE_START(testhelper, "testhelper")
pyg_set_object_has_new_constructor(TEST_TYPE_UNKNOWN);
//pyg_register_class_init(TEST_TYPE_UNKNOWN, __GtkUIManager_class_init);
- /* TestFloatingWithSinkFunc */
- PyTestFloatingWithSinkFunc_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
- PyTestFloatingWithSinkFunc_Type.tp_weaklistoffset = offsetof(PyGObject, weakreflist);
- PyTestFloatingWithSinkFunc_Type.tp_dictoffset = offsetof(PyGObject, inst_dict);
- pygobject_register_class(d, "FloatingWithSinkFunc", TEST_TYPE_FLOATING_WITH_SINK_FUNC,
- &PyTestFloatingWithSinkFunc_Type,
- Py_BuildValue("(O)",
- &PyGObject_Type));
- pyg_set_object_has_new_constructor(TEST_TYPE_FLOATING_WITH_SINK_FUNC);
- pygobject_register_sinkfunc(TEST_TYPE_FLOATING_WITH_SINK_FUNC, sink_test_floating_with_sink_func);
-
- /* TestFloatingWithoutSinkFunc */
- PyTestFloatingWithoutSinkFunc_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
- PyTestFloatingWithoutSinkFunc_Type.tp_weaklistoffset = offsetof(PyGObject, weakreflist);
- PyTestFloatingWithoutSinkFunc_Type.tp_dictoffset = offsetof(PyGObject, inst_dict);
- pygobject_register_class(d, "FloatingWithoutSinkFunc", TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC,
- &PyTestFloatingWithoutSinkFunc_Type,
+ /* TestFloating */
+ PyTestFloating_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
+ PyTestFloating_Type.tp_weaklistoffset = offsetof(PyGObject, weakreflist);
+ PyTestFloating_Type.tp_dictoffset = offsetof(PyGObject, inst_dict);
+ pygobject_register_class(d, "Floating", TEST_TYPE_FLOATING,
+ &PyTestFloating_Type,
Py_BuildValue("(O)",
&PyGObject_Type));
- pyg_set_object_has_new_constructor(TEST_TYPE_FLOATING_WITHOUT_SINK_FUNC);
+ pyg_set_object_has_new_constructor(TEST_TYPE_FLOATING);
/* TestOwnedByLibrary */
PyTestOwnedByLibrary_Type.tp_flags = (Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]