summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorINADA Naoki <inada-n@klab.com>2013-10-21 00:29:05 +0900
committerINADA Naoki <inada-n@klab.com>2013-10-21 00:29:05 +0900
commit37c2ad63af8a6e5cb6944f80d931fedbc6b49e7d (patch)
treeeb64d69860be6da6d1cb64c0c24a7347fbb5c4d1
parentcb789596787592f4ec6bf7dcc0c646e8976b3f16 (diff)
downloadmsgpack-python-37c2ad63af8a6e5cb6944f80d931fedbc6b49e7d.tar.gz
Add tests and bugfix.
-rw-r--r--msgpack/pack_template.h3
-rw-r--r--msgpack/unpack.h4
-rw-r--r--test/test_newspec.py23
3 files changed, 25 insertions, 5 deletions
diff --git a/msgpack/pack_template.h b/msgpack/pack_template.h
index 8b91619..2879bbd 100644
--- a/msgpack/pack_template.h
+++ b/msgpack/pack_template.h
@@ -705,7 +705,8 @@ static inline int msgpack_pack_bin(msgpack_packer *x, size_t l)
static inline int msgpack_pack_raw_body(msgpack_packer* x, const void* b, size_t l)
{
- msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
+ if (l > 0) msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
+ return 0;
}
/*
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index c733b24..aced40b 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -157,7 +157,7 @@ static inline int unpack_callback_array_item(unpack_user* u, unsigned int curren
static inline int unpack_callback_array_end(unpack_user* u, msgpack_unpack_object* c)
{
if (u->list_hook) {
- PyObject *new_c = PyObject_CallFunction(u->list_hook, "(O)", *c);
+ PyObject *new_c = PyObject_CallFunctionObjArgs(u->list_hook, *c, NULL);
if (!new_c)
return -1;
Py_DECREF(*c);
@@ -203,7 +203,7 @@ static inline int unpack_callback_map_item(unpack_user* u, unsigned int current,
static inline int unpack_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
{
if (u->object_hook) {
- PyObject *new_c = PyObject_CallFunction(u->object_hook, "(O)", *c);
+ PyObject *new_c = PyObject_CallFunctionObjArgs(u->object_hook, *c, NULL);
if (!new_c)
return -1;
diff --git a/test/test_newspec.py b/test/test_newspec.py
index 8bc2cfe..ab05029 100644
--- a/test/test_newspec.py
+++ b/test/test_newspec.py
@@ -1,6 +1,6 @@
# coding: utf-8
-from msgpack import packb, unpackb
+from msgpack import packb, unpackb, ExtType
def test_str8():
@@ -66,4 +66,23 @@ def test_bin32():
assert b[5:] == data
assert unpackb(b) == data
-
+def test_ext():
+ def check(ext, packed):
+ assert packb(ext) == packed
+ assert unpackb(packed) == ext
+ check(ExtType(0x42, b'Z'), b'\xd4\x42Z') # fixext 1
+ check(ExtType(0x42, b'ZZ'), b'\xd5\x42ZZ') # fixext 2
+ check(ExtType(0x42, b'Z'*4), b'\xd6\x42' + b'Z'*4) # fixext 4
+ check(ExtType(0x42, b'Z'*8), b'\xd7\x42' + b'Z'*8) # fixext 8
+ check(ExtType(0x42, b'Z'*16), b'\xd8\x42' + b'Z'*16) # fixext 16
+ # ext 8
+ check(ExtType(0x42, b''), b'\xc7\x00\x42')
+ check(ExtType(0x42, b'Z'*255), b'\xc7\xff\x42' + b'Z'*255)
+ # ext 16
+ check(ExtType(0x42, b'Z'*256), b'\xc8\x01\x00\x42' + b'Z'*256)
+ check(ExtType(0x42, b'Z'*0xffff), b'\xc8\xff\xff\x42' + b'Z'*0xffff)
+ # ext 32
+ check(ExtType(0x42, b'Z'*0x10000), b'\xc9\x00\x01\x00\x00\x42' + b'Z'*0x10000)
+ # needs large memory
+ #check(ExtType(0x42, b'Z'*0xffffffff),
+ # b'\xc9\xff\xff\xff\xff\x42' + b'Z'*0xffffffff)