[pygobject/invoke-rewrite] [gi-invoke-ng] add array cleanup for in arrays
- From: John Palmieri <johnp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject/invoke-rewrite] [gi-invoke-ng] add array cleanup for in arrays
- Date: Thu, 26 May 2011 17:24:49 +0000 (UTC)
commit a986b2b8e5ee37f2a330f5aabc85c73ebb0de508
Author: John (J5) Palmieri <johnp redhat com>
Date: Thu May 26 13:21:55 2011 -0400
[gi-invoke-ng] add array cleanup for in arrays
gi/pygi-cache.c | 2 +-
gi/pygi-marshal-cleanup.c | 72 ++++++++++++++++++++++++++++++++++++++++++++-
gi/pygi-marshal-cleanup.h | 9 +++++
gi/pygi-marshal.c | 13 ++++++--
4 files changed, 91 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygi-cache.c b/gi/pygi-cache.c
index 45d17a7..98e4607 100644
--- a/gi/pygi-cache.c
+++ b/gi/pygi-cache.c
@@ -525,7 +525,7 @@ _arg_cache_in_array_setup (PyGIArgCache *arg_cache,
callable_cache->args_cache[seq_cache->len_arg_index] = aux_cache;
}
- /* arg_cache->cleanup = _pygi_cleanup_array; */
+ arg_cache->in_cleanup = _pygi_marshal_cleanup_in_array;
return TRUE;
}
diff --git a/gi/pygi-marshal-cleanup.c b/gi/pygi-marshal-cleanup.c
index d4d2186..e3516b4 100644
--- a/gi/pygi-marshal-cleanup.c
+++ b/gi/pygi-marshal-cleanup.c
@@ -77,7 +77,7 @@ void
pygi_marshal_cleanup_args_in_marshal_success (PyGIInvokeState *state,
PyGICallableCache *cache)
{
- int i;
+ gsize i;
/* For in success, call cleanup for all GI_DIRECTION_IN values only. */
for (i = 0; i < cache->n_args; i++) {
@@ -242,3 +242,73 @@ _pygi_marshal_cleanup_out_interface_struct_foreign (PyGIInvokeState *state,
( (PyGIInterfaceCache *)arg_cache)->interface_info,
data);
}
+
+void
+_pygi_marshal_cleanup_in_array (PyGIInvokeState *state,
+ PyGIArgCache *arg_cache,
+ gpointer data,
+ gboolean was_processed)
+{
+ if (was_processed) {
+ GArray *array_;
+ PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache;
+
+ /* If this isn't a garray create one to help process variable sized
+ array elements */
+ if (sequence_cache->array_type == GI_ARRAY_TYPE_C) {
+ gsize len;
+ if (sequence_cache->fixed_size >= 0) {
+ len = sequence_cache->fixed_size;
+ } else if (sequence_cache->is_zero_terminated) {
+ len = g_strv_length ((gchar **)data);
+ } else {
+ GIArgument *len_arg = state->args[sequence_cache->len_arg_index];
+ len = len_arg->v_long;
+ }
+
+ array_ = g_array_new (FALSE,
+ FALSE,
+ sequence_cache->item_size);
+
+ if (array_ == NULL)
+ return;
+
+ array_->data = data;
+ array_->len = len;
+
+ } else {
+ array_ = (GArray *) data;
+ }
+
+ /* clean up items first */
+ if (sequence_cache->item_cache->in_cleanup != NULL) {
+ gsize i;
+ PyGIMarshalCleanupFunc cleanup_func =
+ sequence_cache->item_cache->in_cleanup;
+
+ for(i = 0; i < array_->len; i++) {
+ cleanup_func (state,
+ sequence_cache->item_cache,
+ g_array_index (array_, gpointer, i),
+ TRUE);
+ }
+ }
+
+ if (state->failed ||
+ arg_cache->transfer == GI_TRANSFER_NOTHING ||
+ arg_cache->transfer == GI_TRANSFER_CONTAINER) {
+ g_array_free (array_, TRUE);
+ } else if (sequence_cache->array_type == GI_ARRAY_TYPE_C) {
+ g_array_free (array_, FALSE);
+ }
+ }
+}
+
+void
+_pygi_marshal_cleanup_out_array (PyGIInvokeState *state,
+ PyGIArgCache *arg_cache,
+ gpointer data,
+ gboolean was_processed)
+{
+
+}
diff --git a/gi/pygi-marshal-cleanup.h b/gi/pygi-marshal-cleanup.h
index de1be57..6ed25d2 100644
--- a/gi/pygi-marshal-cleanup.h
+++ b/gi/pygi-marshal-cleanup.h
@@ -68,6 +68,15 @@ void _pygi_marshal_cleanup_out_interface_object (PyGIInvokeState *state,
PyGIArgCache *arg_cache,
gpointer data,
gboolean was_processed);
+void _pygi_marshal_cleanup_in_array (PyGIInvokeState *state,
+ PyGIArgCache *arg_cache,
+ gpointer data,
+ gboolean was_processed);
+void _pygi_marshal_cleanup_out_array (PyGIInvokeState *state,
+ PyGIArgCache *arg_cache,
+ gpointer data,
+ gboolean was_processed);
+
G_END_DECLS
diff --git a/gi/pygi-marshal.c b/gi/pygi-marshal.c
index f6c84fa..8b9a715 100644
--- a/gi/pygi-marshal.c
+++ b/gi/pygi-marshal.c
@@ -723,9 +723,16 @@ _pygi_marshal_in_array (PyGIInvokeState *state,
continue;
err:
if (sequence_cache->item_cache->in_cleanup != NULL) {
- GDestroyNotify cleanup = sequence_cache->item_cache->in_cleanup;
- /*for(j = 0; j < i; j++)
- cleanup((gpointer)(array_->data[j]));*/
+ gsize j;
+ PyGIMarshalCleanupFunc cleanup_func =
+ sequence_cache->item_cache->in_cleanup;
+
+ for(j = 0; j < i; j++) {
+ cleanup_func (state,
+ sequence_cache->item_cache,
+ g_array_index (array_, gpointer, j),
+ TRUE);
+ }
}
g_array_free (array_, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]