[pygobject] gimodule: fix floating state of python objects created with g_object_new



commit 6115565b13f13407021b9f0b4d92c8c890eb19d8
Author: Mathieu Duponchelle <mathieu centricular com>
Date:   Wed Dec 4 19:15:36 2019 +0100

    gimodule: fix floating state of python objects created with g_object_new
    
    If C code calls g_object_new() for a GInitiallyUnowned subclass
    implemented in python, the expectation is to receive a floating
    reference.
    
    The solution is used is the same picked for
    5efe2e5c8458d9f4d72329ea1209d96b5ebecfb4, this is simply a special
    case that was omitted at the time.

 gi/gimodule.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/gi/gimodule.c b/gi/gimodule.c
index 4668369c..02daba85 100644
--- a/gi/gimodule.c
+++ b/gi/gimodule.c
@@ -1087,9 +1087,18 @@ pygobject__g_instance_init(GTypeInstance   *instance,
           /* this looks like a python object created through
            * g_object_new -> we have no python wrapper, so create it
            * now */
-        wrapper = pygobject_new_full(object,
-                                     /*steal=*/ FALSE,
-                                     g_class);
+
+        if (g_object_is_floating (object)) {
+            g_object_ref (object);
+            wrapper = pygobject_new_full(object,
+                                         /*steal=*/ TRUE,
+                                         g_class);
+            g_object_force_floating (object);
+        } else {
+            wrapper = pygobject_new_full(object,
+                                         /*steal=*/ FALSE,
+                                         g_class);
+        }
 
         /* float the wrapper ref here because we are going to orphan it
          * so we don't destroy the wrapper. The next call to pygobject_new_full


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