Commit d68455e9 authored by Paolo Borelli's avatar Paolo Borelli
Browse files

Handle NULL as a valid case of a char** array

Treat NULL as an empty array and add the corresponding testcase
parent e3451b8e
...@@ -264,8 +264,6 @@ _pygi_marshal_to_py_array (PyGIInvokeState *state, ...@@ -264,8 +264,6 @@ _pygi_marshal_to_py_array (PyGIInvokeState *state,
PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache; PyGISequenceCache *seq_cache = (PyGISequenceCache *)arg_cache;
gsize processed_items = 0; gsize processed_items = 0;
array_ = arg->v_pointer;
/* GArrays make it easier to iterate over arrays /* GArrays make it easier to iterate over arrays
* with different element sizes but requires that * with different element sizes but requires that
* we allocate a GArray if the argument was a C array * we allocate a GArray if the argument was a C array
...@@ -276,8 +274,9 @@ _pygi_marshal_to_py_array (PyGIInvokeState *state, ...@@ -276,8 +274,9 @@ _pygi_marshal_to_py_array (PyGIInvokeState *state,
g_assert(arg->v_pointer != NULL); g_assert(arg->v_pointer != NULL);
len = seq_cache->fixed_size; len = seq_cache->fixed_size;
} else if (seq_cache->is_zero_terminated) { } else if (seq_cache->is_zero_terminated) {
g_assert(arg->v_pointer != NULL); if (arg->v_pointer == NULL) {
if(seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) { len = 0;
} else if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) {
len = strlen (arg->v_pointer); len = strlen (arg->v_pointer);
} else { } else {
len = g_strv_length ((gchar **)arg->v_pointer); len = g_strv_length ((gchar **)arg->v_pointer);
...@@ -303,6 +302,8 @@ _pygi_marshal_to_py_array (PyGIInvokeState *state, ...@@ -303,6 +302,8 @@ _pygi_marshal_to_py_array (PyGIInvokeState *state,
g_free (array_->data); g_free (array_->data);
array_->data = arg->v_pointer; array_->data = arg->v_pointer;
array_->len = len; array_->len = len;
} else {
array_ = arg->v_pointer;
} }
if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) { if (seq_cache->item_cache->type_tag == GI_TYPE_TAG_UINT8) {
......
...@@ -743,6 +743,9 @@ class TestArray(unittest.TestCase): ...@@ -743,6 +743,9 @@ class TestArray(unittest.TestCase):
def test_array_zero_terminated_return(self): def test_array_zero_terminated_return(self):
self.assertEquals(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_return()) self.assertEquals(['0', '1', '2'], GIMarshallingTests.array_zero_terminated_return())
def test_array_zero_terminated_return_null(self):
self.assertEquals([], GIMarshallingTests.array_zero_terminated_return_null())
def test_array_zero_terminated_in(self): def test_array_zero_terminated_in(self):
GIMarshallingTests.array_zero_terminated_in(Sequence(['0', '1', '2'])) GIMarshallingTests.array_zero_terminated_in(Sequence(['0', '1', '2']))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment