summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <smcv@debian.org>2010-11-23 19:17:19 +0000
committerSimon McVittie <smcv@debian.org>2010-11-23 19:17:19 +0000
commit53e9cde2ca64de906967546750e5c6dd6aa58da6 (patch)
tree9af9c6437c8db9065d12400662ae40f3efb0fce4
parent292a9eab92e908b6dc0e97b5ea07c432f41b8bae (diff)
downloaddbus-python-53e9cde2ca64de906967546750e5c6dd6aa58da6.tar.gz
fd.o #21831: deserialize empty ByteArray objects correctly
For some reason libdbus gives us NULL instead of a pointer to a zero-length object (i.e. any random place in the message would do), which Py_BuildValue doesn't interpret the way we'd want it to.
-rw-r--r--_dbus_bindings/message-get-args.c6
-rwxr-xr-xtest/test-standalone.py7
2 files changed, 13 insertions, 0 deletions
diff --git a/_dbus_bindings/message-get-args.c b/_dbus_bindings/message-get-args.c
index 7d55ffd..d6b7aba 100644
--- a/_dbus_bindings/message-get-args.c
+++ b/_dbus_bindings/message-get-args.c
@@ -387,6 +387,12 @@ _message_iter_get_pyobject(DBusMessageIter *iter,
dbus_message_iter_get_fixed_array(&sub,
(const unsigned char **)&u.s,
&n);
+ if (n == 0 && u.s == NULL) {
+ /* fd.o #21831: s# turns (NULL, 0) into None, but
+ * dbus_message_iter_get_fixed_array produces (NULL, 0)
+ * for an empty byte-blob... */
+ u.s = "";
+ }
args = Py_BuildValue("(s#)", u.s, (Py_ssize_t)n);
if (!args) break;
ret = PyObject_Call((PyObject *)&DBusPyByteArray_Type,
diff --git a/test/test-standalone.py b/test/test-standalone.py
index 929fc37..04d1e6d 100755
--- a/test/test-standalone.py
+++ b/test/test-standalone.py
@@ -82,6 +82,9 @@ class TestTypes(unittest.TestCase):
def test_Byte(self):
self.assertEquals(types.Byte('x', variant_level=2), types.Byte(ord('x')))
+ def test_ByteArray(self):
+ self.assertEquals(types.ByteArray(''), '')
+
def test_object_path_attr(self):
class MyObject(object):
__dbus_object_path__ = '/foo'
@@ -175,6 +178,10 @@ class TestMessageMarshalling(unittest.TestCase):
s = SignalMessage('/', 'foo.bar', 'baz')
s.append(types.ByteArray('ab'), signature='av')
aeq(s.get_args_list(), [[types.Byte('a'), types.Byte('b')]])
+ s = SignalMessage('/', 'foo.bar', 'baz')
+ s.append(types.ByteArray(''), signature='ay')
+ aeq(s.get_args_list(), [[]])
+ aeq(s.get_args_list(byte_arrays=True), [types.ByteArray('')])
def test_append_Variant(self):
a = self.assert_