[pygobject/invoke-rewrite] [gi-invoke-ng] add list cleanup routines



commit b626c46b4a95602c7bf1278c2a39aacb7f5027d9
Author: John (J5) Palmieri <johnp redhat com>
Date:   Tue May 31 14:40:49 2011 -0400

    [gi-invoke-ng] add list cleanup routines

 gi/pygi-cache.c           |    8 ++--
 gi/pygi-marshal-cleanup.c |   84 +++++++++++++++++++++++++++++++++++++++++++++
 gi/pygi-marshal-cleanup.h |    8 ++++
 3 files changed, 96 insertions(+), 4 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index a892655..bfc367d 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -575,7 +575,7 @@ _arg_cache_in_glist_setup (PyGIArgCache *arg_cache,
                            GITransfer transfer)
 {
     arg_cache->in_marshaller = _pygi_marshal_in_glist;
-    /* arg_cache->cleanup = */
+    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_glist;
 }
 
 static inline void
@@ -583,7 +583,7 @@ _arg_cache_out_glist_setup (PyGIArgCache *arg_cache,
                             GITransfer transfer)
 {
     arg_cache->out_marshaller = _pygi_marshal_out_glist;
-    /* arg_cache->cleanup = */
+    arg_cache->in_cleanup = _pygi_marshal_cleanup_out_glist;
 }
 
 static inline void
@@ -591,7 +591,7 @@ _arg_cache_in_gslist_setup (PyGIArgCache *arg_cache,
                             GITransfer transfer)
 {
     arg_cache->in_marshaller = _pygi_marshal_in_gslist;
-    /* arg_cache->cleanup = */
+    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_glist;
 }
 
 static inline void
@@ -599,7 +599,7 @@ _arg_cache_out_gslist_setup (PyGIArgCache *arg_cache,
                              GITransfer transfer)
 {
     arg_cache->out_marshaller = _pygi_marshal_out_gslist;
-    /* arg_cache->cleanup = */
+    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_glist;
 }
 
 static inline void
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index a74cda8..6e84125 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -336,3 +336,87 @@ _pygi_marshal_cleanup_out_array (PyGIInvokeState *state,
             g_array_free (array_, TRUE);
     }
 }
+
+void
+_pygi_marshal_cleanup_in_glist  (PyGIInvokeState *state,
+                                 PyGIArgCache    *arg_cache,
+                                 gpointer         data,
+                                 gboolean         was_processed)
+{
+    if (was_processed) {
+        GSList *list_;
+        PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache;
+
+        list_ = (GSList *)data;
+
+        /* clean up items first */
+        if (sequence_cache->item_cache->in_cleanup != NULL) {
+            PyGIMarshalCleanupFunc cleanup_func =
+                sequence_cache->item_cache->in_cleanup;
+            GSList *node = list_;
+            while (node != NULL) {
+                cleanup_func (state,
+                              sequence_cache->item_cache,
+                              node->data,
+                              TRUE);
+                node = node->next;
+            }
+        }
+
+        if (state->failed ||
+               arg_cache->transfer == GI_TRANSFER_NOTHING ||
+                  arg_cache->transfer == GI_TRANSFER_CONTAINER) {
+            switch (arg_cache->type_tag) {
+                case GI_TYPE_TAG_GLIST:
+                    g_list_free ( (GList *)list_);
+                    break;
+                case GI_TYPE_TAG_GSLIST:
+                    g_slist_free (list_);
+                    break;
+                default:
+                    g_assert_not_reached();
+            }
+        }
+    }
+}
+
+void
+_pygi_marshal_cleanup_out_glist (PyGIInvokeState *state,
+                                 PyGIArgCache    *arg_cache,
+                                 gpointer         data,
+                                 gboolean         was_processed)
+{
+    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->out_cleanup != NULL) {
+            PyGIMarshalCleanupFunc cleanup_func =
+                sequence_cache->item_cache->out_cleanup;
+            GSList *node = list_;
+
+            while (node != NULL) {
+                cleanup_func (state,
+                              sequence_cache->item_cache,
+                              node->data,
+                              was_processed);
+                node = node->next;
+            }
+        }
+
+        if (arg_cache->transfer == GI_TRANSFER_EVERYTHING) {
+            switch (arg_cache->type_tag) {
+                case GI_TYPE_TAG_GLIST:
+                    g_list_free ( (GList *)list_);
+                    break;
+                case GI_TYPE_TAG_GSLIST:
+                    g_slist_free (list_);
+                    break;
+                default:
+                    g_assert_not_reached();
+            }
+        }
+    }
+}
diff --git a/gi/pygi-marshal-cleanup.h b/gi/pygi-marshal-cleanup.h
index 6ed25d2..44ead75 100644
--- a/gi/pygi-marshal-cleanup.h
+++ b/gi/pygi-marshal-cleanup.h
@@ -76,6 +76,14 @@ void _pygi_marshal_cleanup_out_array                    (PyGIInvokeState *state,
                                                          PyGIArgCache    *arg_cache,
                                                          gpointer         data,
                                                          gboolean         was_processed);
+void _pygi_marshal_cleanup_in_glist                     (PyGIInvokeState *state,
+                                                         PyGIArgCache    *arg_cache,
+                                                         gpointer         data,
+                                                         gboolean         was_processed);
+void _pygi_marshal_cleanup_out_glist                    (PyGIInvokeState *state,
+                                                         PyGIArgCache    *arg_cache,
+                                                         gpointer         data,
+                                                         gboolean         was_processed);
 
 
 G_END_DECLS



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