[pygobject] Drop sinkfuncs.



commit 04627488220b4f2a16e11f8982af7866fea9f7eb
Author: Tomeu Vizoso <tomeu vizoso collabora co uk>
Date:   Thu Jun 10 19:24:31 2010 +0200

    Drop sinkfuncs.
    
        * use g_object methods to sink floating refs instead of allowing
          custom sink functions to be registered
        * we now sink inside of pygobject_new_full to handle cases where
          a library creates its own gobject via g_object_new and just
          needs a python wrapper
          - a previous patch had done the sink when creating the gobject,
            since it needs to call pygobject_new_full to wrap the object,
            this patch handles both cases (e.g. pygobject created object
            and externally created gobject)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=583909

 gobject/gobjectmodule.c |    3 +--
 gobject/pygobject.c     |   42 ++++++++----------------------------------
 gobject/pygobject.h     |    1 +
 3 files changed, 10 insertions(+), 36 deletions(-)
---
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c
index be0bc0b..50a577c 100644
--- a/gobject/gobjectmodule.c
+++ b/gobject/gobjectmodule.c
@@ -1758,7 +1758,6 @@ 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;
 
@@ -2259,9 +2258,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)
diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index f8d7dd1..4b6fe6f 100644
--- a/gobject/pygobject.c
+++ b/gobject/pygobject.c
@@ -112,13 +112,6 @@ 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;
@@ -135,16 +128,8 @@ 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);
-		break;
-	    }
-	}
+    if (G_IS_INITIALLY_UNOWNED(obj) || g_object_is_floating(obj)) {
+        g_object_ref_sink(obj);
     }
 }
 
@@ -160,23 +145,13 @@ 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 {
@@ -586,20 +561,18 @@ 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.  It may also sink any
- * floating references on the GObject.
+ * always be used for this GObject instance.
  */
 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);
@@ -889,7 +862,7 @@ pygobject_lookup_class(GType gtype)
 /**
  * pygobject_new_full:
  * @obj: a GObject instance.
- * @sink: whether to sink any floating reference found on the GObject.
+ * @sink: whether to sink any floating reference found on the GObject. DEPRECATED.
  * @g_class: the GObjectClass
  *
  * This function gets a reference to a wrapper for the given GObject
@@ -940,6 +913,7 @@ 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);
     }
 
diff --git a/gobject/pygobject.h b/gobject/pygobject.h
index d7eba07..85d8bca 100644
--- a/gobject/pygobject.h
+++ b/gobject/pygobject.h
@@ -210,6 +210,7 @@ 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)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]