[pygobject] Re-add support for passing GValue's by reference



commit 466567373289e6f141709f08efa80ba588d3d64a
Author: Simon Feltman <sfeltman src gnome org>
Date:   Tue Jul 2 18:06:01 2013 -0700

    Re-add support for passing GValue's by reference
    
    Fix special casing when marshaling from a Python held GValue
    to a GValue argument intended for a function call.
    The re-factoring of GValue marshaling in commit #9e47afe459df942d9f
    broke this by always making a copy of the GValue. This removed the
    ability to retrieve values with functions like
    gtk_style_context_get_style_property.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701058

 gi/pygi-argument.c        |    2 +-
 gi/pygi-marshal-from-py.c |   32 +++++++++++++++-----------------
 2 files changed, 16 insertions(+), 18 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index f477fdf..d5ed7b0 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1164,7 +1164,7 @@ array_success:
                                                            g_type,
                                                            py_type,
                                                            transfer,
-                                                           FALSE, /*is_caller_allocates*/
+                                                           FALSE, /*copy_reference*/
                                                            g_struct_info_is_foreign (info));
 
                     Py_DECREF (py_type);
diff --git a/gi/pygi-marshal-from-py.c b/gi/pygi-marshal-from-py.c
index 639a226..4ff9fce 100644
--- a/gi/pygi-marshal-from-py.c
+++ b/gi/pygi-marshal-from-py.c
@@ -1651,7 +1651,7 @@ _pygi_marshal_from_py_interface_struct (PyGIInvokeState   *state,
                                                   iface_cache->g_type,
                                                   iface_cache->py_type,
                                                   arg_cache->transfer,
-                                                  arg_cache->is_caller_allocates,
+                                                  TRUE, /*copy_reference*/
                                                   iface_cache->is_foreign);
 }
 
@@ -1856,13 +1856,14 @@ pygi_marshal_from_py_gobject (PyObject *py_arg, /*in*/
  * py_arg: (in):
  * arg: (out):
  * transfer:
- * is_allocated: TRUE if arg->v_pointer is an already allocated GValue
+ * copy_reference: TRUE if arg should use the pointer reference held by py_arg
+ *                 when it is already holding a GValue vs. copying the value.
  */
 gboolean
 pygi_marshal_from_py_gvalue (PyObject *py_arg,
                              GIArgument *arg,
                              GITransfer transfer,
-                             gboolean is_allocated) {
+                             gboolean copy_reference) {
     GValue *value;
     GType object_type;
 
@@ -1872,24 +1873,21 @@ pygi_marshal_from_py_gvalue (PyObject *py_arg,
         return FALSE;
     }
 
-    if (is_allocated)
-        value = (GValue *)arg->v_pointer;
-    else
-        value = g_slice_new0 (GValue);
-
     /* if already a gvalue, use that, else marshal into gvalue */
     if (object_type == G_TYPE_VALUE) {
         GValue *source_value = pyg_boxed_get (py_arg, GValue);
-        if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
+        if (copy_reference) {
+            value = source_value;
+        } else {
+            value = g_slice_new0 (GValue);
             g_value_init (value, G_VALUE_TYPE (source_value));
-        g_value_copy (source_value, value);
+            g_value_copy (source_value, value);
+        }
     } else {
-        if (G_VALUE_TYPE (value) == G_TYPE_INVALID)
-            g_value_init (value, object_type);
-
+        value = g_slice_new0 (GValue);
+        g_value_init (value, object_type);
         if (pyg_value_from_pyobject (value, py_arg) < 0) {
-            if (!is_allocated)
-                g_slice_free (GValue, value);
+            g_slice_free (GValue, value);
             PyErr_SetString (PyExc_RuntimeError, "PyObject conversion to GValue failed");
             return FALSE;
         }
@@ -1940,7 +1938,7 @@ pygi_marshal_from_py_interface_struct (PyObject *py_arg,
                                        GType g_type,
                                        PyObject *py_type,
                                        GITransfer transfer,
-                                       gboolean is_allocated,
+                                       gboolean copy_reference,
                                        gboolean is_foreign)
 {
     if (py_arg == Py_None) {
@@ -1958,7 +1956,7 @@ pygi_marshal_from_py_interface_struct (PyObject *py_arg,
         return pygi_marshal_from_py_gvalue(py_arg,
                                            arg,
                                            transfer,
-                                           is_allocated);
+                                           copy_reference);
     } else if (is_foreign) {
         PyObject *success;
         success = pygi_struct_foreign_convert_to_g_argument (py_arg,


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