[pygobject] Move special handling of GObject from Python when calling from C



commit cf295f636b6324a46abbaf329cd6d92c04155d9d
Author: Garrett Regier <Garrett Regier riftio com>
Date:   Wed Aug 6 11:59:09 2014 -0400

    Move special handling of GObject from Python when calling from C
    
    This will soon be used in the GObject arg cache marshaling when
    the calling context is C.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=727004

 gi/pygi-argument.c |   21 +--------------------
 gi/pygi-object.c   |   30 ++++++++++++++++++++++++++++++
 gi/pygi-object.h   |    5 +++++
 3 files changed, 36 insertions(+), 20 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 15be78c..cf26808 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1420,26 +1420,7 @@ _pygi_argument_to_object (GIArgument  *arg,
                 }
                 case GI_INFO_TYPE_INTERFACE:
                 case GI_INFO_TYPE_OBJECT:
-                    /* HACK:
-                     * The following hack is to work around GTK+ sending signals which
-                     * contain floating widgets in them. This assumes control of how
-                     * references are added by the PyGObject wrapper and avoids the sink
-                     * behavior by explicitly passing GI_TRANSFER_EVERYTHING as the transfer
-                     * mode and then re-forcing the object as floating afterwards.
-                     *
-                     * This can be deleted once the following ticket is fixed:
-                     * https://bugzilla.gnome.org/show_bug.cgi?id=693400
-                     */
-                    if (arg->v_pointer &&
-                            !G_IS_PARAM_SPEC (arg->v_pointer) &&
-                            transfer == GI_TRANSFER_NOTHING &&
-                            g_object_is_floating (arg->v_pointer)) {
-                        g_object_ref (arg->v_pointer);
-                        object = pygi_arg_gobject_to_py (arg, GI_TRANSFER_EVERYTHING);
-                        g_object_force_floating (arg->v_pointer);
-                    } else {
-                        object = pygi_arg_gobject_to_py (arg, transfer);
-                    }
+                    object = pygi_arg_gobject_to_py_called_from_c (arg, transfer);
 
                     break;
                 default:
diff --git a/gi/pygi-object.c b/gi/pygi-object.c
index 8ed7ffc..042b629 100644
--- a/gi/pygi-object.c
+++ b/gi/pygi-object.c
@@ -200,6 +200,36 @@ pygi_arg_gobject_to_py (GIArgument *arg, GITransfer transfer) {
     return pyobj;
 }
 
+PyObject *
+pygi_arg_gobject_to_py_called_from_c (GIArgument *arg,
+                                      GITransfer  transfer)
+{
+    PyObject *object;
+
+    /* HACK:
+     * The following hack is to work around GTK+ sending signals which
+     * contain floating widgets in them. This assumes control of how
+     * references are added by the PyGObject wrapper and avoids the sink
+     * behavior by explicitly passing GI_TRANSFER_EVERYTHING as the transfer
+     * mode and then re-forcing the object as floating afterwards.
+     *
+     * See: https://bugzilla.gnome.org/show_bug.cgi?id=693400
+     */
+    if (arg->v_pointer != NULL &&
+            transfer == GI_TRANSFER_NOTHING &&
+            !G_IS_PARAM_SPEC (arg->v_pointer) &&
+            g_object_is_floating (arg->v_pointer)) {
+
+        g_object_ref (arg->v_pointer);
+        object = pygi_arg_gobject_to_py (arg, GI_TRANSFER_EVERYTHING);
+        g_object_force_floating (arg->v_pointer);
+    } else {
+        object = pygi_arg_gobject_to_py (arg, transfer);
+    }
+
+    return object;
+}
+
 static PyObject *
 _pygi_marshal_to_py_interface_object_cache_adapter (PyGIInvokeState   *state,
                                                     PyGICallableCache *callable_cache,
diff --git a/gi/pygi-object.h b/gi/pygi-object.h
index 8a59acd..360bce1 100644
--- a/gi/pygi-object.h
+++ b/gi/pygi-object.h
@@ -34,6 +34,11 @@ PyObject *
 pygi_arg_gobject_to_py               (GIArgument        *arg,
                                       GITransfer         transfer);
 
+PyObject *
+pygi_arg_gobject_to_py_called_from_c (GIArgument        *arg,
+                                      GITransfer         transfer);
+
+
 PyGIArgCache *
 pygi_arg_gobject_new_from_info       (GITypeInfo        *type_info,
                                       GIArgInfo         *arg_info,   /* may be null */


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