[pygobject] _pygi_argument_to_object(): Clean up array unmarshalling



commit 1223358e2c558dd7ac3300126f989054ec5a5b3f
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Sep 3 07:17:57 2012 +0200

    _pygi_argument_to_object(): Clean up array unmarshalling
    
    The NULL case is already handled at the top, so it does not need to be
    re-checked again.
    
    Emit a critical if we fail to allocate a Python array of the requested size.

 gi/pygi-argument.c |   45 +++++++++++++++------------------------------
 1 files changed, 15 insertions(+), 30 deletions(-)
---
diff --git a/gi/pygi-argument.c b/gi/pygi-argument.c
index 1560556..79a0ec5 100644
--- a/gi/pygi-argument.c
+++ b/gi/pygi-argument.c
@@ -1658,7 +1658,7 @@ _pygi_argument_to_object (GIArgument  *arg,
             GITypeTag item_type_tag;
             GITransfer item_transfer;
             gsize i, item_size;
-            
+
             if (arg->v_pointer == NULL)
                 return PyList_New (0);
             
@@ -1679,45 +1679,30 @@ _pygi_argument_to_object (GIArgument  *arg,
 
             if (item_type_tag == GI_TYPE_TAG_UINT8) {
                 /* Return as a byte array */
-                if (arg->v_pointer == NULL) {
-                    object = PYGLIB_PyBytes_FromString ("");
-                    g_base_info_unref ( (GIBaseInfo *) item_type_info);
-                    break;
-                }
-
-                object = PYGLIB_PyBytes_FromStringAndSize(array->data, array->len);
-                g_base_info_unref ( (GIBaseInfo *) item_type_info);
-                break;
-
+                object = PYGLIB_PyBytes_FromStringAndSize (array->data, array->len);
             } else {
-                if (arg->v_pointer == NULL) {
-                    object = PyList_New (0);
-                    g_base_info_unref ( (GIBaseInfo *) item_type_info);
-                    break;
-                }
-
                 object = PyList_New (array->len);
                 if (object == NULL) {
+                    g_critical ("Failure to allocate array for %u items", array->len);
                     g_base_info_unref ( (GIBaseInfo *) item_type_info);
                     break;
                 }
 
-            }            
-
-            for (i = 0; i < array->len; i++) {
-                GIArgument item = { 0 };
-                PyObject *py_item;
-                
-                memcpy (&item, array->data + i * item_size, item_size);
+                for (i = 0; i < array->len; i++) {
+                    GIArgument item = { 0 };
+                    PyObject *py_item;
+                    
+                    memcpy (&item, array->data + i * item_size, item_size);
+
+                    py_item = _pygi_argument_to_object (&item, item_type_info, item_transfer);
+                    if (py_item == NULL) {
+                        Py_CLEAR (object);
+                        _PyGI_ERROR_PREFIX ("Item %zu: ", i);
+                        break;
+                    }
 
-                py_item = _pygi_argument_to_object (&item, item_type_info, item_transfer);
-                if (py_item == NULL) {
-                    Py_CLEAR (object);
-                    _PyGI_ERROR_PREFIX ("Item %zu: ", i);
-                    break;
+                    PyList_SET_ITEM (object, i, py_item);
                 }
-
-                PyList_SET_ITEM (object, i, py_item);
             }
 
             g_base_info_unref ( (GIBaseInfo *) item_type_info);



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