[pygobject/invoke-rewrite] [gi] fix some transfer issues and test case failures



commit 5b1db41d60204c8021f47f43b85dac126c389c8d
Author: John (J5) Palmieri <johnp redhat com>
Date:   Wed Jan 19 13:57:54 2011 -0500

    [gi] fix some transfer issues and test case failures

 gi/pygi-argument.c |    4 ++++
 gi/pygi-cache.c    |   11 ++++++++---
 gi/pygi-invoke.c   |   17 +++++++++--------
 3 files changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index a59d24e..888db99 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -3566,6 +3566,10 @@ _pygi_marshal_out_interface_object (PyGIInvokeState   *state,
 {
     PyObject *py_obj = pygobject_new (arg->v_pointer);
 ;
+    /* The new wrapper increased the reference count, so decrease it. */
+    if (arg_cache->transfer == GI_TRANSFER_EVERYTHING)
+        g_object_unref (arg->v_pointer);
+
     return py_obj;
 }
 
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 5b575ba..75b29e0 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -621,7 +621,6 @@ _arg_cache_new_for_out_void(void)
 {
      PyGIArgCache *arg_cache = _arg_cache_new();
      arg_cache->out_marshaller = _pygi_marshal_out_void;
-
      return arg_cache;
 }
 
@@ -1028,6 +1027,7 @@ _arg_cache_out_new_from_type_info (GITypeInfo *type_info,
         arg_cache->transfer = transfer;
         arg_cache->type_tag = type_tag;
         arg_cache->c_arg_index = c_arg_index;
+        arg_cache->is_pointer = g_type_info_is_pointer(type_info);
     }
 
     return arg_cache;
@@ -1137,6 +1137,7 @@ _arg_cache_in_new_from_type_info (GITypeInfo *type_info,
         arg_cache->type_tag = type_tag;
         arg_cache->py_arg_index = py_arg_index;
         arg_cache->c_arg_index = c_arg_index;
+        arg_cache->is_pointer = g_type_info_is_pointer(type_info);
     }
 
     return arg_cache;
@@ -1150,15 +1151,19 @@ _args_cache_generate(GIFunctionInfo *function_info,
     int i;
     GITypeInfo *return_info;
     GITypeTag return_type_tag;
+    GITransfer return_transfer;
     PyGIArgCache *return_cache;
     /* cache the return arg */
-    return_info = g_callable_info_get_return_type( (GICallableInfo *)function_info);
+    return_info = 
+        g_callable_info_get_return_type( (GICallableInfo *)function_info);
+    return_transfer = 
+        g_callable_info_get_caller_owns( (GICallableInfo *)function_info);
     return_type_tag = g_type_info_get_tag(return_info);
     return_cache =
         _arg_cache_out_new_from_type_info(return_info,
                                           function_cache,
                                           return_type_tag,
-                                          GI_TRANSFER_EVERYTHING,
+                                          return_transfer,
                                           GI_DIRECTION_OUT,
                                           -1);
 
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index 1669024..00381e9 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -964,7 +964,7 @@ _invoke_marshal_in_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
 
     if (state->n_py_in_args > cache->n_py_args) {
         PyErr_Format(PyExc_TypeError,
-                     "%s() takes exactly %zd arguments (%zd given)",
+                     "%s() takes exactly %zd argument(s) (%zd given)",
                      cache->name,
                      cache->n_py_args,
                      state->n_py_in_args);
@@ -987,7 +987,7 @@ _invoke_marshal_in_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
 
                 if (arg_cache->py_arg_index >= state->n_py_in_args) {
                     PyErr_Format(PyExc_TypeError,
-                                 "%s() takes exactly %zd arguments (%zd given)",
+                                 "%s() takes exactly %zd argument(s) (%zd given)",
                                   cache->name,
                                   cache->n_py_args,
                                   state->n_py_in_args);
@@ -1059,23 +1059,24 @@ _invoke_marshal_out_args(PyGIInvokeState *state, PyGIFunctionCache *cache)
                                            arg_cache,
                                            &(state->out_values[0]));
     } else {
-        int arg_index = 0;
+        int out_cache_index = 0;
+        int py_arg_index = 0;
         GSList *cache_item = cache->out_args;
         /* return a tuple */
         py_out = PyTuple_New(total_out_args);
         if (has_return) {
-            PyTuple_SET_ITEM(py_out, arg_index, py_return);
-            arg_index++;
+            PyTuple_SET_ITEM(py_out, py_arg_index, py_return);
+            py_arg_index++;
         }
 
-        for(; arg_index < total_out_args; arg_index++) {
+        for(; py_arg_index < total_out_args; py_arg_index++, out_cache_index++) {
             PyGIArgCache *arg_cache = (PyGIArgCache *)cache_item->data;
             PyObject *py_obj = arg_cache->out_marshaller(state,
                                                          cache,
                                                          arg_cache,
-                                                         &(state->out_values[arg_index]));
+                                                         &(state->out_values[out_cache_index]));
 
-            PyTuple_SET_ITEM(py_out, arg_index, py_obj);
+            PyTuple_SET_ITEM(py_out, py_arg_index, py_obj);
             cache_item = cache_item->next;
         }
     }



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