Commit e71238a6 authored by Tomeu Vizoso's avatar Tomeu Vizoso

Revert "Drop sinkfuncs."

This reverts commit 04627488.
parent ec8d148e
......@@ -1758,6 +1758,7 @@ pyg_object_new (PyGObject *self, PyObject *args, PyObject *kwargs)
if (obj) {
self = (PyGObject *) pygobject_new_full((GObject *)obj, FALSE, NULL);
g_object_unref(obj);
pygobject_sink(obj);
} else
self = NULL;
......@@ -2258,9 +2259,9 @@ pygobject_constructv(PyGObject *self,
pygobject_init_wrapper_set(NULL);
if (self->obj == NULL) {
self->obj = obj;
pygobject_sink(obj);
pygobject_register_wrapper((PyObject *) self);
}
pygobject_sink(obj);
} else {
int i;
for (i = 0; i < n_parameters; ++i)
......
......@@ -112,6 +112,13 @@ pygobject_get_inst_data(PyGObject *self)
return inst_data;
}
typedef struct {
GType type;
void (* sinkfunc)(GObject *object);
} SinkFunc;
static GArray *sink_funcs = NULL;
GHashTable *custom_type_registration = NULL;
PyTypeObject *PyGObject_MetaType = NULL;
......@@ -128,8 +135,16 @@ PyTypeObject *PyGObject_MetaType = NULL;
void
pygobject_sink(GObject *obj)
{
if (G_IS_INITIALLY_UNOWNED(obj) || g_object_is_floating(obj)) {
g_object_ref_sink(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);
break;
}
}
}
}
......@@ -145,13 +160,23 @@ pygobject_sink(GObject *obj)
*
* The sinkfunc should be able to remove the floating reference on
* instances of the given type, or any subclasses.
*
* Deprecated: Since 2.20, sinkfuncs are not needed.
*/
void
pygobject_register_sinkfunc(GType type, void (* sinkfunc)(GObject *object))
{
SinkFunc sf;
#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 {
......@@ -563,18 +588,20 @@ pygobject_switch_to_toggle_ref(PyGObject *self)
/**
* pygobject_register_wrapper:
* @self: the wrapper instance
* @sink: whether to sink self. DEPRECATED
*
* In the constructor of PyGTK wrappers, this function should be
* called after setting the obj member. It will tie the wrapper
* instance to the GObject so that the same wrapper instance will
* always be used for this GObject instance.
* always be used for this GObject instance. It may also sink any
* floating references on the GObject.
*/
static inline void
pygobject_register_wrapper_full(PyGObject *self, gboolean sink)
{
GObject *obj = self->obj;
if (sink)
pygobject_sink(obj);
g_assert(obj->ref_count >= 1);
/* save wrapper pointer so we can access it later */
g_object_set_qdata_full(obj, pygobject_wrapper_key, self, NULL);
......@@ -864,7 +891,7 @@ pygobject_lookup_class(GType gtype)
/**
* pygobject_new_full:
* @obj: a GObject instance.
* @sink: whether to sink any floating reference found on the GObject. DEPRECATED.
* @sink: whether to sink any floating reference found on the GObject.
* @g_class: the GObjectClass
*
* This function gets a reference to a wrapper for the given GObject
......@@ -915,7 +942,6 @@ pygobject_new_full(GObject *obj, gboolean sink, gpointer g_class)
self->obj = obj;
g_object_ref(obj);
pygobject_register_wrapper_full(self, sink);
pygobject_sink(obj);
PyObject_GC_Track((PyObject *)self);
}
......
......@@ -210,7 +210,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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment