8000 Add tests and bugfix. · zhurs/msgpack-python@37c2ad6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37c2ad6

Browse files
committed
Add tests and bugfix.
1 parent cb78959 commit 37c2ad6

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

msgpack/pack_template.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,8 @@ static inline int msgpack_pack_bin(msgpack_packer *x, size_t l)
705705

706706
static inline int msgpack_pack_raw_body(msgpack_packer* x, const void* b, size_t l)
707707
{
708-
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
708+
if (l > 0) msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
709+
return 0;
709710
}
710711

711712
/*

msgpack/unpack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static inline int unpack_callback_array_item(unpack_user* u, unsigned int curren
157157
static inline int unpack_callback_array_end(unpack_user* u, msgpack_unpack_object* c)
158158
{
159159
if (u->list_hook) {
160-
PyObject *new_c = PyObject_CallFunction(u->list_hook, "(O)", *c);
160+
PyObject *new_c = PyObject_CallFunctionObjArgs(u->list_hook, *c, NULL);
161161
if (!new_c)
162162
return -1;
163163
Py_DECREF(*c);
@@ -203,7 +203,7 @@ static inline int unpack_callback_map_item(unpack_user* u, unsigned int current,
203203
static inline int unpack_callback_map_end(unpack_user* u, msgpack_unpack_object* c)
204204
{
205205
if (u->object_hook) {
206-
PyObject *new_c = PyObject_CallFunction(u->object_hook, "(O)", *c);
206+
PyObject *new_c = PyObject_CallFunctionObjArgs(u->object_hook, *c, NULL);
207207
if (!new_c)
208208
return -1;
209209

test/test_newspec.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# coding: utf-8
22

3-
from msgpack import packb, unpackb
3+
from msgpack import packb, unpackb, ExtType
44

55

66
def test_str8():
@@ -66,4 +66,23 @@ def test_bin32():
6666
assert b[5:] == data
6767
assert unpackb(b) == data
6868

69-
69+
def test_ext():
70+
def check(ext, packed):
71+
assert packb(ext) == packed
72+
assert unpackb(packed) == ext
73+
check(ExtType(0x42, b'Z'), b'\xd4\x42Z') # fixext 1
74+
check(ExtType(0x42, b'ZZ'), b'\xd5\x42ZZ') # fixext 2
75+
check(ExtType(0x42, b'Z'*4), b'\xd6\x42' + b'Z'*4) # fixext 4
76+
check(ExtType(0x42, b'Z'*8), b'\xd7\x42' + b'Z'*8) # fixext 8
77+
check(ExtType(0x42, b'Z'*16), b'\xd8\x42' + b'Z'*16) # fixext 16
78+
# ext 8
79+
check(ExtType(0x42, b''), b'\xc7\x00\x42')
80+
check(ExtType(0x42, b'Z'*255), b'\xc7\xff\x42' + b'Z'*255)
81+
# ext 16
82+
check(ExtType(0x42, b'Z'*256), b'\xc8\x01\x00\x42' + b'Z'*256)
83+
check(ExtType(0x42, b'Z'*0xffff), b'\xc8\xff\xff\x42' + b'Z'*0xffff)
84+
# ext 32
85+
check(ExtType(0x42, b'Z'*0x10000), b'\xc9\x00\x01\x00\x00\x42' + b'Z'*0x10000)
86+
# needs large memory
87+
#check(ExtType(0x42, b'Z'*0xffffffff),
88+
# b'\xc9\xff\xff\xff\xff\x42' + b'Z'*0xffffffff)

0 commit comments

Comments
 (0)
0