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



commit 508b1b6ca1b143f1e123a3ddb83e8ce146758dfc
Author: John (J5) Palmieri <johnp redhat com>
Date:   Tue May 31 16:01:03 2011 -0400

    [gi-invoke-ng] add hash cleanup routines

 gi/pygi-cache.c           |    2 +
 gi/pygi-marshal-cleanup.c |   64 +++++++++++++++++++++++++++++++++++++++++++++
 gi/pygi-marshal-cleanup.h |   10 +++++-
 3 files changed, 74 insertions(+), 2 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index bfc367d..8ed9fad 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -606,12 +606,14 @@ static inline void
 _arg_cache_in_ghash_setup (PyGIArgCache *arg_cache)
 {
     arg_cache->in_marshaller = _pygi_marshal_in_ghash;
+    arg_cache->in_cleanup = _pygi_marshal_cleanup_in_ghash;
 }
 
 static inline void
 _arg_cache_out_ghash_setup (PyGIArgCache *arg_cache)
 {
     arg_cache->out_marshaller = _pygi_marshal_out_ghash;
+    arg_cache->out_cleanup = _pygi_marshal_cleanup_out_ghash;
 }
 
 static inline void
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index 645ad2e..fd6d25b 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -421,3 +421,67 @@ _pygi_marshal_cleanup_out_glist (PyGIInvokeState *state,
         }
     }
 }
+
+void
+_pygi_marshal_cleanup_in_ghash  (PyGIInvokeState *state,
+                                 PyGIArgCache    *arg_cache,
+                                 gpointer         data,
+                                 gboolean         was_processed)
+{
+    if (data == NULL)
+        return;
+
+    if (was_processed) {
+        GHashTable *hash_;
+        PyGIHashCache *hash_cache = (PyGIHashCache *)arg_cache;
+
+        hash_ = (GHashTable *)data;
+
+        /* clean up keys and values first */
+        if (hash_cache->key_cache->in_cleanup != NULL ||
+                hash_cache->value_cache->in_cleanup != NULL) {
+            GHashTableIter hiter;
+            gpointer key;
+            gpointer value;
+
+            PyGIMarshalCleanupFunc key_cleanup_func =
+                hash_cache->key_cache->in_cleanup;
+            PyGIMarshalCleanupFunc value_cleanup_func =
+                hash_cache->value_cache->in_cleanup;
+
+            g_hash_table_iter_init (&hiter, hash_);
+            while (g_hash_table_iter_next (&hiter, &key, &value)) {
+                if (key != NULL && key_cleanup_func != NULL)
+                    key_cleanup_func (state,
+                                      hash_cache->key_cache,
+                                      key,
+                                      TRUE);
+                if (value != NULL && value_cleanup_func != NULL)
+                    value_cleanup_func (state,
+                                        hash_cache->value_cache,
+                                        value,
+                                        TRUE);
+            }
+        }
+
+        if (state->failed ||
+               arg_cache->transfer == GI_TRANSFER_NOTHING ||
+                  arg_cache->transfer == GI_TRANSFER_CONTAINER)
+            g_hash_table_destroy (hash_);
+
+    }
+}
+
+void
+_pygi_marshal_cleanup_out_ghash (PyGIInvokeState *state,
+                                 PyGIArgCache    *arg_cache,
+                                 gpointer         data,
+                                 gboolean         was_processed)
+{
+    if (data == NULL)
+        return;
+
+    /* assume hashtable has boxed key and value */
+    if (arg_cache->transfer == GI_TRANSFER_EVERYTHING)
+        g_hash_table_destroy ( (GHashTable *)data);
+}
diff --git a/gi/pygi-marshal-cleanup.h b/gi/pygi-marshal-cleanup.h
index 44ead75..3aff8fa 100644
--- a/gi/pygi-marshal-cleanup.h
+++ b/gi/pygi-marshal-cleanup.h
@@ -84,8 +84,14 @@ void _pygi_marshal_cleanup_out_glist                    (PyGIInvokeState *state,
                                                          PyGIArgCache    *arg_cache,
                                                          gpointer         data,
                                                          gboolean         was_processed);
-
-
+void _pygi_marshal_cleanup_in_ghash                     (PyGIInvokeState *state,
+                                                         PyGIArgCache    *arg_cache,
+                                                         gpointer         data,
+                                                         gboolean         was_processed);
+void _pygi_marshal_cleanup_out_ghash                    (PyGIInvokeState *state,
+                                                         PyGIArgCache    *arg_cache,
+                                                         gpointer         data,
+                                                         gboolean         was_processed);
 G_END_DECLS
 
 #endif /* __PYGI_MARSHAL_CLEANUP_H__ */



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