Imported Upstream version 3.1.0
[platform/upstream/pygobject2.git] / gi / pygi-marshal-to-py.c
index 1e4a8aa..4b99278 100644 (file)
@@ -26,6 +26,7 @@
 #include <string.h>
 #include <time.h>
 
+#include <pyglib.h>
 #include <pygobject.h>
 #include <pyglib-python-compat.h>
 
@@ -264,8 +265,6 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
     PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache;
     gsize processed_items = 0;
 
-    array_ = arg->v_pointer;
-
      /* 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
@@ -276,8 +275,9 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
             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) {
+            if (arg->v_pointer == NULL) {
+                len = 0;
+            } else if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) {
                 len = strlen (arg->v_pointer);
             } else {
                 len = g_strv_length ((gchar **)arg->v_pointer);
@@ -303,6 +303,8 @@ _pygi_marshal_to_py_array (PyGIInvokeState   *state,
             g_free (array_->data);
         array_->data = arg->v_pointer;
         array_->len = len;
+    } else {
+        array_ = arg->v_pointer;
     }
 
     if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) {
@@ -597,11 +599,20 @@ _pygi_marshal_to_py_gerror (PyGIInvokeState   *state,
                             PyGIArgCache      *arg_cache,
                             GIArgument        *arg)
 {
+    GError *error = arg->v_pointer;
     PyObject *py_obj = NULL;
 
-    PyErr_Format (PyExc_NotImplementedError,
-                  "Marshalling for gerror to PyObject is not implemented");
-    return py_obj;
+    py_obj = pyglib_error_marshal(&error);
+
+    if (arg_cache->transfer == GI_TRANSFER_EVERYTHING && error != NULL) {
+        g_error_free (error);
+    }
+
+    if (py_obj != NULL) {
+        return py_obj;
+    } else {
+        Py_RETURN_NONE;
+    }
 }
 
 PyObject *