[pygobject] Revert "Revert "to python marshalling: collect cleanup data""



commit b1d1c8d9d8820fe405bddd8e9dea88b5ec2fcce2
Author: Mathieu Duponchelle <mathieu centricular com>
Date:   Thu Feb 15 23:32:20 2018 +0100

    Revert "Revert "to python marshalling: collect cleanup data""
    
    This reverts commit fa555767464fbe551b14cfbc121febc5290b1371.

 gi/pygi-array.c               | 24 ++++++++++++++++++------
 gi/pygi-basictype.c           |  8 +++++---
 gi/pygi-basictype.h           |  3 ++-
 gi/pygi-cache.h               | 13 ++++++++++---
 gi/pygi-closure.c             |  9 +++++++--
 gi/pygi-enum-marshal.c        |  6 ++++--
 gi/pygi-error.c               |  3 ++-
 gi/pygi-hashtable.c           | 13 +++++++++----
 gi/pygi-invoke-state-struct.h |  3 +++
 gi/pygi-invoke.c              | 17 +++++++++++++----
 gi/pygi-list.c                | 38 +++++++++++++++++++++++++++++++-------
 gi/pygi-marshal-cleanup.c     | 13 ++++++++-----
 gi/pygi-object.c              |  8 +++++---
 gi/pygi-struct-marshal.c      |  5 +++--
 14 files changed, 120 insertions(+), 43 deletions(-)
---
diff --git a/gi/pygi-array.c b/gi/pygi-array.c
index e55f9f6c..0f6c6d8d 100644
--- a/gi/pygi-array.c
+++ b/gi/pygi-array.c
@@ -505,7 +505,8 @@ static PyObject *
 _pygi_marshal_to_py_array (PyGIInvokeState   *state,
                            PyGICallableCache *callable_cache,
                            PyGIArgCache      *arg_cache,
-                           GIArgument        *arg)
+                           GIArgument        *arg,
+                           gpointer          *cleanup_data)
 {
     GArray *array_;
     PyObject *py_obj = NULL;
@@ -575,11 +576,14 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
             gsize item_size;
             PyGIMarshalToPyFunc item_to_py_marshaller;
             PyGIArgCache *item_arg_cache;
+            GPtrArray *item_cleanups;
 
             py_obj = PyList_New (array_->len);
             if (py_obj == NULL)
                 goto err;
 
+            item_cleanups = g_ptr_array_sized_new (array_->len);
+            *cleanup_data = item_cleanups;
 
             item_arg_cache = seq_cache->item_cache;
             item_to_py_marshaller = item_arg_cache->to_py_marshaller;
@@ -589,6 +593,7 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
             for (i = 0; i < array_->len; i++) {
                 GIArgument item_arg = {0};
                 PyObject *py_item;
+                gpointer item_cleanup_data = NULL;
 
                 /* If we are receiving an array of pointers, simply assign the pointer
                  * and move on, letting the per-item marshaler deal with the
@@ -632,7 +637,10 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
                 py_item = item_to_py_marshaller ( state,
                                                 callable_cache,
                                                 item_arg_cache,
-                                                &item_arg);
+                                                &item_arg,
+                                                &item_cleanup_data);
+
+                g_ptr_array_index (item_cleanups, i) = item_cleanup_data;
 
                 if (py_item == NULL) {
                     Py_CLEAR (py_obj);
@@ -640,6 +648,8 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
                     if (array_cache->array_type == GI_ARRAY_TYPE_C)
                         g_array_unref (array_);
 
+                    g_ptr_array_unref (item_cleanups);
+
                     goto err;
                 }
                 PyList_SET_ITEM (py_obj, i, py_item);
@@ -660,7 +670,7 @@ err:
         /* clean up unprocessed items */
         if (seq_cache->item_cache->to_py_cleanup != NULL) {
             guint j;
-            PyGIMarshalCleanupFunc cleanup_func = seq_cache->item_cache->to_py_cleanup;
+            PyGIMarshalToPyCleanupFunc cleanup_func = seq_cache->item_cache->to_py_cleanup;
             for (j = processed_items; j < array_->len; j++) {
                 cleanup_func (state,
                               seq_cache->item_cache,
@@ -711,7 +721,7 @@ _wrap_c_array (PyGIInvokeState   *state,
 static void
 _pygi_marshal_cleanup_to_py_array (PyGIInvokeState *state,
                                    PyGIArgCache    *arg_cache,
-                                   PyObject        *dummy,
+                                   gpointer         cleanup_data,
                                    gpointer         data,
                                    gboolean         was_processed)
 {
@@ -737,17 +747,19 @@ _pygi_marshal_cleanup_to_py_array (PyGIInvokeState *state,
         }
 
         if (sequence_cache->item_cache->to_py_cleanup != NULL) {
+            GPtrArray *item_cleanups = (GPtrArray *) cleanup_data;
             gsize i;
             guint len = (array_ != NULL) ? array_->len : ptr_array_->len;
 
-            PyGIMarshalCleanupFunc cleanup_func = sequence_cache->item_cache->to_py_cleanup;
+            PyGIMarshalToPyCleanupFunc cleanup_func = sequence_cache->item_cache->to_py_cleanup;
             for (i = 0; i < len; i++) {
                 cleanup_func (state,
                               sequence_cache->item_cache,
-                              NULL,
+                              g_ptr_array_index(item_cleanups, i),
                               (array_ != NULL) ? g_array_index (array_, gpointer, i) : g_ptr_array_index 
(ptr_array_, i),
                               was_processed);
             }
+            g_ptr_array_unref (item_cleanups);
         }
 
         if (array_ != NULL)
diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c
index 6d4e64ef..ddb02f9b 100644
--- a/gi/pygi-basictype.c
+++ b/gi/pygi-basictype.c
@@ -684,7 +684,8 @@ static PyObject *
 _pygi_marshal_to_py_void (PyGIInvokeState   *state,
                           PyGICallableCache *callable_cache,
                           PyGIArgCache      *arg_cache,
-                          GIArgument        *arg)
+                          GIArgument        *arg,
+                          gpointer          *cleanup_data)
 {
     if (arg_cache->is_pointer) {
         return PyLong_FromVoidPtr (arg->v_pointer);
@@ -828,7 +829,8 @@ PyObject *
 _pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState   *state,
                                               PyGICallableCache *callable_cache,
                                               PyGIArgCache      *arg_cache,
-                                              GIArgument        *arg)
+                                              GIArgument        *arg,
+                                              gpointer          *cleanup_data)
 {
     return _pygi_marshal_to_py_basic_type (arg,
                                             arg_cache->type_tag,
@@ -838,7 +840,7 @@ _pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState   *state,
 static void
 _pygi_marshal_cleanup_to_py_utf8 (PyGIInvokeState *state,
                                   PyGIArgCache    *arg_cache,
-                                  PyObject        *dummy,
+                                  gpointer         cleanup_data,
                                   gpointer         data,
                                   gboolean         was_processed)
 {
diff --git a/gi/pygi-basictype.h b/gi/pygi-basictype.h
index 466c7d4a..62f11c6f 100644
--- a/gi/pygi-basictype.h
+++ b/gi/pygi-basictype.h
@@ -43,7 +43,8 @@ PyObject *_pygi_marshal_to_py_basic_type               (GIArgument    *arg,
 PyObject *_pygi_marshal_to_py_basic_type_cache_adapter (PyGIInvokeState   *state,
                                                         PyGICallableCache *callable_cache,
                                                         PyGIArgCache      *arg_cache,
-                                                        GIArgument        *arg);
+                                                        GIArgument        *arg,
+                                                        gpointer          *cleanup_data);
 
 PyGIArgCache *pygi_arg_basic_type_new_from_info        (GITypeInfo    *type_info,
                                                         GIArgInfo     *arg_info,   /* may be null */
diff --git a/gi/pygi-cache.h b/gi/pygi-cache.h
index 4dfabd86..574563b6 100644
--- a/gi/pygi-cache.h
+++ b/gi/pygi-cache.h
@@ -50,14 +50,21 @@ typedef gboolean (*PyGIMarshalFromPyFunc) (PyGIInvokeState   *state,
 typedef PyObject *(*PyGIMarshalToPyFunc) (PyGIInvokeState   *state,
                                           PyGICallableCache *callable_cache,
                                           PyGIArgCache      *arg_cache,
-                                          GIArgument        *arg);
+                                          GIArgument        *arg,
+                                          gpointer          *cleanup_data);
 
 typedef void (*PyGIMarshalCleanupFunc) (PyGIInvokeState *state,
                                         PyGIArgCache    *arg_cache,
-                                        PyObject        *py_arg, /* always NULL for to_py cleanup */
+                                        PyObject        *py_arg,
                                         gpointer         data,
                                         gboolean         was_processed);
 
+typedef void (*PyGIMarshalToPyCleanupFunc) (PyGIInvokeState *state,
+                                            PyGIArgCache    *arg_cache,
+                                            gpointer         cleanup_data,
+                                            gpointer         data,
+                                            gboolean         was_processed);
+
 /* Argument meta types denote how we process the argument:
  *  - PYGI_META_ARG_TYPE_PARENT - parents may or may not have children
  *    but are always processed via the normal marshaller for their
@@ -118,7 +125,7 @@ struct _PyGIArgCache
     PyGIMarshalToPyFunc to_py_marshaller;
 
     PyGIMarshalCleanupFunc from_py_cleanup;
-    PyGIMarshalCleanupFunc to_py_cleanup;
+    PyGIMarshalToPyCleanupFunc to_py_cleanup;
 
     GDestroyNotify destroy_notify;
 
diff --git a/gi/pygi-closure.c b/gi/pygi-closure.c
index b51c04c5..42144e07 100644
--- a/gi/pygi-closure.c
+++ b/gi/pygi-closure.c
@@ -393,10 +393,14 @@ _pygi_closure_convert_arguments (PyGIInvokeState *state,
             } else if (arg_cache->meta_type != PYGI_META_ARG_TYPE_PARENT) {
                 continue;
             } else {
+                gpointer cleanup_data = NULL;
+
                 value = arg_cache->to_py_marshaller (state,
                                                      cache,
                                                      arg_cache,
-                                                     &state->args[i].arg_value);
+                                                     &state->args[i].arg_value,
+                                                     &cleanup_data);
+                state->args[i].to_py_arg_cleanup_data = cleanup_data;
 
                 if (value == NULL) {
                     pygi_marshal_cleanup_args_to_py_parameter_fail (state,
@@ -800,7 +804,8 @@ static PyObject *
 _pygi_marshal_to_py_interface_callback (PyGIInvokeState   *state,
                                         PyGICallableCache *callable_cache,
                                         PyGIArgCache      *arg_cache,
-                                        GIArgument        *arg)
+                                        GIArgument        *arg,
+                                        gpointer          *arg_cleanup_data)
 {
     PyGICallbackCache *callback_cache = (PyGICallbackCache *) arg_cache;
     gssize user_data_index;
diff --git a/gi/pygi-enum-marshal.c b/gi/pygi-enum-marshal.c
index 44eb0097..fe6c7d72 100644
--- a/gi/pygi-enum-marshal.c
+++ b/gi/pygi-enum-marshal.c
@@ -225,7 +225,8 @@ static PyObject *
 _pygi_marshal_to_py_interface_enum (PyGIInvokeState   *state,
                                     PyGICallableCache *callable_cache,
                                     PyGIArgCache      *arg_cache,
-                                    GIArgument        *arg)
+                                    GIArgument        *arg,
+                                    gpointer          *cleanup_data)
 {
     PyObject *py_obj = NULL;
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
@@ -253,7 +254,8 @@ static PyObject *
 _pygi_marshal_to_py_interface_flags (PyGIInvokeState   *state,
                                      PyGICallableCache *callable_cache,
                                      PyGIArgCache      *arg_cache,
-                                     GIArgument        *arg)
+                                     GIArgument        *arg,
+                                     gpointer          *cleanup_data)
 {
     PyObject *py_obj = NULL;
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
diff --git a/gi/pygi-error.c b/gi/pygi-error.c
index e3d88384..4827e9f4 100644
--- a/gi/pygi-error.c
+++ b/gi/pygi-error.c
@@ -275,7 +275,8 @@ static PyObject *
 _pygi_marshal_to_py_gerror (PyGIInvokeState   *state,
                             PyGICallableCache *callable_cache,
                             PyGIArgCache      *arg_cache,
-                            GIArgument        *arg)
+                            GIArgument        *arg,
+                            gpointer          *cleanup_data)
 {
     GError *error = arg->v_pointer;
     PyObject *py_obj = NULL;
diff --git a/gi/pygi-hashtable.c b/gi/pygi-hashtable.c
index 647bf04d..f0cda78f 100644
--- a/gi/pygi-hashtable.c
+++ b/gi/pygi-hashtable.c
@@ -220,7 +220,8 @@ static PyObject *
 _pygi_marshal_to_py_ghash (PyGIInvokeState   *state,
                            PyGICallableCache *callable_cache,
                            PyGIArgCache      *arg_cache,
-                           GIArgument        *arg)
+                           GIArgument        *arg,
+                           gpointer          *cleanup_data)
 {
     GHashTable *hash_;
     GHashTableIter hash_table_iter;
@@ -259,6 +260,8 @@ _pygi_marshal_to_py_ghash (PyGIInvokeState   *state,
     while (g_hash_table_iter_next (&hash_table_iter,
                                    &key_arg.v_pointer,
                                    &value_arg.v_pointer)) {
+        gpointer key_cleanup_data = NULL;
+        gpointer value_cleanup_data = NULL;
         PyObject *py_key;
         PyObject *py_value;
         int retval;
@@ -268,7 +271,8 @@ _pygi_marshal_to_py_ghash (PyGIInvokeState   *state,
         py_key = key_to_py_marshaller ( state,
                                       callable_cache,
                                       key_arg_cache,
-                                     &key_arg);
+                                     &key_arg,
+                                     &key_cleanup_data);
 
         if (py_key == NULL) {
             Py_CLEAR (py_obj);
@@ -279,7 +283,8 @@ _pygi_marshal_to_py_ghash (PyGIInvokeState   *state,
         py_value = value_to_py_marshaller ( state,
                                           callable_cache,
                                           value_arg_cache,
-                                         &value_arg);
+                                         &value_arg,
+                                         &value_cleanup_data);
 
         if (py_value == NULL) {
             Py_CLEAR (py_obj);
@@ -304,7 +309,7 @@ _pygi_marshal_to_py_ghash (PyGIInvokeState   *state,
 static void
 _pygi_marshal_cleanup_to_py_ghash (PyGIInvokeState *state,
                                    PyGIArgCache    *arg_cache,
-                                   PyObject        *dummy,
+                                   gpointer         cleanup_data,
                                    gpointer         data,
                                    gboolean         was_processed)
 {
diff --git a/gi/pygi-invoke-state-struct.h b/gi/pygi-invoke-state-struct.h
index 64711cb1..dbf4e665 100644
--- a/gi/pygi-invoke-state-struct.h
+++ b/gi/pygi-invoke-state-struct.h
@@ -20,6 +20,8 @@ typedef struct _PyGIInvokeArgState
     /* Holds from_py marshaler cleanup data. */
     gpointer arg_cleanup_data;
 
+    /* Holds to_py marshaler cleanup data. */
+    gpointer to_py_arg_cleanup_data;
 } PyGIInvokeArgState;
 
 
@@ -45,6 +47,7 @@ typedef struct _PyGIInvokeState
 
     /* Memory to receive the result of the C ffi function call. */
     GIArgument return_arg;
+    gpointer to_py_return_arg_cleanup_data;
 
     /* A GError exception which is indirectly bound into the last position of
      * the "args" array if the callable caches "throws" member is set.
diff --git a/gi/pygi-invoke.c b/gi/pygi-invoke.c
index fd9e4746..fca48bae 100644
--- a/gi/pygi-invoke.c
+++ b/gi/pygi-invoke.c
@@ -565,10 +565,13 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGIFunctionCache *function_ca
 
     if (cache->return_cache) {
         if (!cache->return_cache->is_skipped) {
+            gpointer cleanup_data = NULL;
             py_return = cache->return_cache->to_py_marshaller ( state,
                                                                 cache,
                                                                 cache->return_cache,
-                                                               &state->return_arg);
+                                                               &state->return_arg,
+                                                               &cleanup_data);
+            state->to_py_return_arg_cleanup_data = cleanup_data;
             if (py_return == NULL) {
                 pygi_marshal_cleanup_args_return_fail (state,
                                                        cache);
@@ -576,7 +579,7 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGIFunctionCache *function_ca
             }
         } else {
             if (cache->return_cache->transfer == GI_TRANSFER_EVERYTHING) {
-                PyGIMarshalCleanupFunc to_py_cleanup =
+                PyGIMarshalToPyCleanupFunc to_py_cleanup =
                     cache->return_cache->to_py_cleanup;
 
                 if (to_py_cleanup != NULL)
@@ -604,10 +607,13 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGIFunctionCache *function_ca
     } else if (!cache->has_return && n_out_args == 1) {
         /* if we get here there is one out arg an no return */
         PyGIArgCache *arg_cache = (PyGIArgCache *)cache->to_py_args->data;
+        gpointer cleanup_data = NULL;
         py_out = arg_cache->to_py_marshaller (state,
                                               cache,
                                               arg_cache,
-                                              state->args[arg_cache->c_arg_index].arg_pointer.v_pointer);
+                                              state->args[arg_cache->c_arg_index].arg_pointer.v_pointer,
+                                              &cleanup_data);
+        state->args[arg_cache->c_arg_index].to_py_arg_cleanup_data = cleanup_data;
         if (py_out == NULL) {
             pygi_marshal_cleanup_args_to_py_parameter_fail (state,
                                                             cache,
@@ -637,10 +643,13 @@ _invoke_marshal_out_args (PyGIInvokeState *state, PyGIFunctionCache *function_ca
 
         for (; py_arg_index < tuple_len; py_arg_index++) {
             PyGIArgCache *arg_cache = (PyGIArgCache *)cache_item->data;
+            gpointer cleanup_data = NULL;
             PyObject *py_obj = arg_cache->to_py_marshaller (state,
                                                             cache,
                                                             arg_cache,
-                                                            
state->args[arg_cache->c_arg_index].arg_pointer.v_pointer);
+                                                            
state->args[arg_cache->c_arg_index].arg_pointer.v_pointer,
+                                                            &cleanup_data);
+            state->args[arg_cache->c_arg_index].to_py_arg_cleanup_data = cleanup_data;
 
             if (py_obj == NULL) {
                 if (cache->has_return)
diff --git a/gi/pygi-list.c b/gi/pygi-list.c
index 72a3d205..e9fc92ca 100644
--- a/gi/pygi-list.c
+++ b/gi/pygi-list.c
@@ -234,11 +234,13 @@ static PyObject *
 _pygi_marshal_to_py_glist (PyGIInvokeState   *state,
                            PyGICallableCache *callable_cache,
                            PyGIArgCache      *arg_cache,
-                           GIArgument        *arg)
+                           GIArgument        *arg,
+                           gpointer          *cleanup_data)
 {
     GList *list_;
     gsize length;
     gsize i;
+    GPtrArray *item_cleanups;
 
     PyGIMarshalToPyFunc item_to_py_marshaller;
     PyGIArgCache *item_arg_cache;
@@ -253,23 +255,31 @@ _pygi_marshal_to_py_glist (PyGIInvokeState   *state,
     if (py_obj == NULL)
         return NULL;
 
+    item_cleanups = g_ptr_array_sized_new (length);
+    *cleanup_data = item_cleanups;
+
     item_arg_cache = seq_cache->item_cache;
     item_to_py_marshaller = item_arg_cache->to_py_marshaller;
 
     for (i = 0; list_ != NULL; list_ = g_list_next (list_), i++) {
         GIArgument item_arg;
         PyObject *py_item;
+        gpointer item_cleanup_data = NULL;
 
         item_arg.v_pointer = list_->data;
         _pygi_hash_pointer_to_arg (&item_arg, item_arg_cache->type_info);
         py_item = item_to_py_marshaller (state,
                                          callable_cache,
                                          item_arg_cache,
-                                         &item_arg);
+                                         &item_arg,
+                                         &item_cleanup_data);
+
+        g_ptr_array_index (item_cleanups, i) = item_cleanup_data;
 
         if (py_item == NULL) {
             Py_CLEAR (py_obj);
             _PyGI_ERROR_PREFIX ("Item %zu: ", i);
+            g_ptr_array_unref (item_cleanups);
             return NULL;
         }
 
@@ -283,11 +293,13 @@ static PyObject *
 _pygi_marshal_to_py_gslist (PyGIInvokeState   *state,
                             PyGICallableCache *callable_cache,
                             PyGIArgCache      *arg_cache,
-                            GIArgument        *arg)
+                            GIArgument        *arg,
+                            gpointer *cleanup_data)
 {
     GSList *list_;
     gsize length;
     gsize i;
+    GPtrArray *item_cleanups;
 
     PyGIMarshalToPyFunc item_to_py_marshaller;
     PyGIArgCache *item_arg_cache;
@@ -302,23 +314,30 @@ _pygi_marshal_to_py_gslist (PyGIInvokeState   *state,
     if (py_obj == NULL)
         return NULL;
 
+    item_cleanups = g_ptr_array_sized_new (length);
+    *cleanup_data = item_cleanups;
+
     item_arg_cache = seq_cache->item_cache;
     item_to_py_marshaller = item_arg_cache->to_py_marshaller;
 
     for (i = 0; list_ != NULL; list_ = g_slist_next (list_), i++) {
         GIArgument item_arg;
         PyObject *py_item;
+        gpointer item_cleanup_data = NULL;
 
         item_arg.v_pointer = list_->data;
         _pygi_hash_pointer_to_arg (&item_arg, item_arg_cache->type_info);
         py_item = item_to_py_marshaller (state,
                                         callable_cache,
                                         item_arg_cache,
-                                        &item_arg);
+                                        &item_arg,
+                                        &item_cleanup_data);
 
+        g_ptr_array_index (item_cleanups, i) = item_cleanup_data;
         if (py_item == NULL) {
             Py_CLEAR (py_obj);
             _PyGI_ERROR_PREFIX ("Item %zu: ", i);
+            g_ptr_array_unref (item_cleanups);
             return NULL;
         }
 
@@ -331,27 +350,30 @@ _pygi_marshal_to_py_gslist (PyGIInvokeState   *state,
 static void
 _pygi_marshal_cleanup_to_py_glist (PyGIInvokeState *state,
                                    PyGIArgCache    *arg_cache,
-                                   PyObject        *dummy,
+                                   gpointer         cleanup_data,
                                    gpointer         data,
                                    gboolean         was_processed)
 {
+    GPtrArray *item_cleanups = (GPtrArray *) cleanup_data;
     PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache;
     if (arg_cache->transfer == GI_TRANSFER_EVERYTHING ||
             arg_cache->transfer == GI_TRANSFER_CONTAINER) {
         GSList *list_ = (GSList *)data;
 
         if (sequence_cache->item_cache->to_py_cleanup != NULL) {
-            PyGIMarshalCleanupFunc cleanup_func =
+            PyGIMarshalToPyCleanupFunc cleanup_func =
                 sequence_cache->item_cache->to_py_cleanup;
             GSList *node = list_;
+            guint i = 0;
 
             while (node != NULL) {
                 cleanup_func (state,
                               sequence_cache->item_cache,
-                              NULL,
+                              g_ptr_array_index(item_cleanups, i),
                               node->data,
                               was_processed);
                 node = node->next;
+                i++;
             }
         }
 
@@ -363,6 +385,8 @@ _pygi_marshal_cleanup_to_py_glist (PyGIInvokeState *state,
             g_assert_not_reached();
         }
     }
+
+    g_ptr_array_unref (item_cleanups);
 }
 
 static void
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index 906be58c..ddda5943 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -119,13 +119,15 @@ pygi_marshal_cleanup_args_to_py_marshal_success (PyGIInvokeState   *state,
                                                  PyGICallableCache *cache)
 {
     GSList *cache_item;
+    guint i = 0;
+
     /* clean up the return if available */
     if (cache->return_cache != NULL) {
-        PyGIMarshalCleanupFunc cleanup_func = cache->return_cache->to_py_cleanup;
+        PyGIMarshalToPyCleanupFunc cleanup_func = cache->return_cache->to_py_cleanup;
         if (cleanup_func && state->return_arg.v_pointer != NULL)
             cleanup_func (state,
                           cache->return_cache,
-                          NULL,
+                          state->to_py_return_arg_cleanup_data,
                           state->return_arg.v_pointer,
                           TRUE);
     }
@@ -134,23 +136,24 @@ pygi_marshal_cleanup_args_to_py_marshal_success (PyGIInvokeState   *state,
     cache_item = cache->to_py_args;
     while (cache_item) {
         PyGIArgCache *arg_cache = (PyGIArgCache *) cache_item->data;
-        PyGIMarshalCleanupFunc cleanup_func = arg_cache->to_py_cleanup;
+        PyGIMarshalToPyCleanupFunc cleanup_func = arg_cache->to_py_cleanup;
         gpointer data = state->args[arg_cache->c_arg_index].arg_value.v_pointer;
 
         if (cleanup_func != NULL && data != NULL)
             cleanup_func (state,
                           arg_cache,
-                          NULL,
+                          state->args[arg_cache->c_arg_index].to_py_arg_cleanup_data,
                           data,
                           TRUE);
         else if (arg_cache->is_caller_allocates && data != NULL) {
             _cleanup_caller_allocates (state,
                                        arg_cache,
-                                       NULL,
+                                       state->args[arg_cache->c_arg_index].to_py_arg_cleanup_data,
                                        data,
                                        TRUE);
         }
 
+        i++;
         cache_item = cache_item->next;
     }
 }
diff --git a/gi/pygi-object.c b/gi/pygi-object.c
index 8fd8ee0f..80c90555 100644
--- a/gi/pygi-object.c
+++ b/gi/pygi-object.c
@@ -279,7 +279,8 @@ static PyObject *
 _pygi_marshal_to_py_called_from_c_interface_object_cache_adapter (PyGIInvokeState   *state,
                                                                   PyGICallableCache *callable_cache,
                                                                   PyGIArgCache      *arg_cache,
-                                                                  GIArgument        *arg)
+                                                                  GIArgument        *arg,
+                                                                  gpointer          *cleanup_data)
 {
     return pygi_arg_gobject_to_py_called_from_c (arg, arg_cache->transfer);
 }
@@ -288,7 +289,8 @@ static PyObject *
 _pygi_marshal_to_py_called_from_py_interface_object_cache_adapter (PyGIInvokeState   *state,
                                                                    PyGICallableCache *callable_cache,
                                                                    PyGIArgCache      *arg_cache,
-                                                                   GIArgument        *arg)
+                                                                   GIArgument        *arg,
+                                                                   gpointer          *cleanup_data)
 {
     return pygi_arg_gobject_to_py (arg, arg_cache->transfer);
 }
@@ -296,7 +298,7 @@ _pygi_marshal_to_py_called_from_py_interface_object_cache_adapter (PyGIInvokeSta
 static void
 _pygi_marshal_cleanup_to_py_interface_object (PyGIInvokeState *state,
                                               PyGIArgCache    *arg_cache,
-                                              PyObject        *dummy,
+                                              gpointer         cleanup_data,
                                               gpointer         data,
                                               gboolean         was_processed)
 {
diff --git a/gi/pygi-struct-marshal.c b/gi/pygi-struct-marshal.c
index d594239f..f1b9f13b 100644
--- a/gi/pygi-struct-marshal.c
+++ b/gi/pygi-struct-marshal.c
@@ -435,7 +435,8 @@ static PyObject *
 arg_struct_to_py_marshal_adapter (PyGIInvokeState   *state,
                                   PyGICallableCache *callable_cache,
                                   PyGIArgCache      *arg_cache,
-                                  GIArgument        *arg)
+                                  GIArgument        *arg,
+                                  gpointer          *cleanup_data)
 {
     PyGIInterfaceCache *iface_cache = (PyGIInterfaceCache *)arg_cache;
 
@@ -451,7 +452,7 @@ arg_struct_to_py_marshal_adapter (PyGIInvokeState   *state,
 static void
 arg_foreign_to_py_cleanup (PyGIInvokeState *state,
                            PyGIArgCache    *arg_cache,
-                           PyObject        *dummy,
+                           gpointer         cleanup_data,
                            gpointer         data,
                            gboolean         was_processed)
 {


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