[pygobject/invoke-rewrite] [gi-invoke-ng] handle in pointer array marshalling



commit 4fd957a5de364c0588168dee15e1e61d4f12e173
Author: John (J5) Palmieri <johnp redhat com>
Date:   Fri Jun 17 17:07:56 2011 -0400

    [gi-invoke-ng] handle in pointer array marshalling

 gi/pygi-marshal.c |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)
---
diff --git a/gi/pygi-marshal.c b/gi/pygi-marshal.c
index 50f3641..5c8c804 100644
--- a/gi/pygi-marshal.c
+++ b/gi/pygi-marshal.c
@@ -661,6 +661,7 @@ _pygi_marshal_in_array (PyGIInvokeState   *state,
     PyGIMarshalInFunc in_marshaller;
     int i;
     Py_ssize_t length;
+    gboolean is_ptr_array;
     GArray *array_ = NULL;
     PyGISequenceCache *sequence_cache = (PyGISequenceCache *)arg_cache;
 
@@ -688,10 +689,15 @@ _pygi_marshal_in_array (PyGIInvokeState   *state,
         return FALSE;
     }
 
-    array_ = g_array_sized_new (sequence_cache->is_zero_terminated,
-                                FALSE,
-                                sequence_cache->item_size,
-                                length);
+    is_ptr_array = (sequence_cache->array_type == GI_ARRAY_TYPE_PTR_ARRAY);
+    if (is_ptr_array) {
+        array_ = (GArray *)g_ptr_array_new ();
+    } else {
+        array_ = g_array_sized_new (sequence_cache->is_zero_terminated,
+                                    FALSE,
+                                    sequence_cache->item_size,
+                                    length);
+    }
 
     if (array_ == NULL) {
         PyErr_NoMemory ();
@@ -719,7 +725,14 @@ _pygi_marshal_in_array (PyGIInvokeState   *state,
                             &item))
             goto err;
 
-        g_array_insert_val (array_, i, item);
+        /* FIXME: it is much more efficent to have seperate marshaller
+         *        for ptr arrays than doing the evaluation
+         *        and casting each loop iteration
+         */
+        if (is_ptr_array)
+            g_ptr_array_add((GPtrArray *)array_, item.v_pointer);
+        else
+            g_array_insert_val (array_, i, item);
         continue;
 err:
         if (sequence_cache->item_cache->in_cleanup != NULL) {
@@ -735,7 +748,10 @@ err:
             }
         }
 
-        g_array_free (array_, TRUE);
+        if (is_ptr_array)
+            g_ptr_array_free (array_, TRUE);
+        else
+            g_array_free (array_, TRUE);
         _PyGI_ERROR_PREFIX ("Item %i: ", i);
         return FALSE;
     }



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