[pygobject] handle NULL arrays correctly for each array type



commit 20ca3f129d6cc662285cce8c732b55596016aefa
Author: John (J5) Palmieri <johnp redhat com>
Date:   Wed Nov 2 14:50:42 2011 -0400

    handle NULL arrays correctly for each array type

 gi/pygi-marshal-to-py.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 67c21cb..1e4a8aa 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -266,8 +266,6 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
 
     array_ = arg->v_pointer;
 
-    g_assert(array_ != NULL);
-
      /* GArrays make it easier to iterate over arrays
       * with different element sizes but requires that
       * we allocate a GArray if the argument was a C array
@@ -275,8 +273,10 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
     if (seq_cache->array_type == GI_ARRAY_TYPE_C) {
         gsize len;
         if (seq_cache->fixed_size >= 0) {
+            g_assert(arg->v_pointer != NULL);
             len = seq_cache->fixed_size;
         } else if (seq_cache->is_zero_terminated) {
+            g_assert(arg->v_pointer != NULL);
             if(seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) {
                 len = strlen (arg->v_pointer);
             } else {
@@ -293,13 +293,14 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
         if (array_ == NULL) {
             PyErr_NoMemory ();
 
-            if (arg_cache->transfer == GI_TRANSFER_EVERYTHING)
+            if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && arg->v_pointer != NULL)
                 g_free (arg->v_pointer);
 
             return NULL;
         }
-        
-        g_free (array_->data);
+
+        if (array_->data != NULL) 
+            g_free (array_->data);
         array_->data = arg->v_pointer;
         array_->len = len;
     }



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