[pygobject] Handle NULL as a valid case of a char** array
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pygobject] Handle NULL as a valid case of a char** array
- Date: Tue, 3 Jan 2012 16:41:23 +0000 (UTC)
commit d68455e99b1a9ebba31209b17a11317b1958678b
Author: Paolo Borelli <pborelli gnome org>
Date: Tue Jan 3 16:57:40 2012 +0100
Handle NULL as a valid case of a char** array
Treat NULL as an empty array and add the corresponding testcase
gi/pygi-marshal-to-py.c | 9 +++++----
tests/test_gi.py | 3 +++
2 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/gi/pygi-marshal-to-py.c b/gi/pygi-marshal-to-py.c
index 1e4a8aa..709fef8 100644
--- a/gi/pygi-marshal-to-py.c
+++ b/gi/pygi-marshal-to-py.c
@@ -264,8 +264,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 +274,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 +302,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) {
diff --git a/tests/test_gi.py b/tests/test_gi.py
index 0a9b1b2..b95bebe 100644
--- a/tests/test_gi.py
+++ b/tests/test_gi.py
@@ -743,6 +743,9 @@ class TestArray(unittest.TestCase):
def test_array_zero_terminated_return(self):
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):
GIMarshallingTests.array_zero_terminated_in(Sequence(['0', '1', '2']))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]