Skip to content

Commit 822cce8

Browse files
committed
Support unpacking new types.
1 parent 96bcd76 commit 822cce8

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

msgpack/unpack.h

Lines changed: 7 additions & 3 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 = PyEval_CallFunction(u->list_hook, "(O)", *c);
160+
PyObject *new_c = PyObject_CallFunction(u->list_hook, "(O)", *c);
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 = PyEval_CallFunction(u->object_hook, "(O)", *c);
206+
PyObject *new_c = PyObject_CallFunction(u->object_hook, "(O)", *c);
207207
if (!new_c)
208208
return -1;
209209

@@ -246,7 +246,11 @@ static inline int unpack_callback_ext(unpack_user* u, const char* base, const ch
246246
return -1;
247247
}
248248
// length also includes the typecode, so the actual data is lenght-1
249-
py = PyEval_CallFunction(u->ext_hook, "(is#)", typecode, pos, lenght-1);
249+
#if PY_MAJOR_VERSION == 2
250+
py = PyObject_CallFunction(u->ext_hook, "(is#)", typecode, pos, lenght-1);
251+
#else
252+
py = PyObject_CallFunction(u->ext_hook, "(iy#)", typecode, pos, lenght-1);
253+
#endif
250254
if (!py)
251255
return -1;
252256
*o = py;

msgpack/unpack_define.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,3 @@ typedef enum {
9393
#endif
9494

9595
#endif /* msgpack/unpack_define.h */
96-

msgpack/unpack_template.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,17 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, size_t l
178178
switch(*p) {
179179
case 0xc0: // nil
180180
push_simple_value(_nil);
181-
//case 0xc1: // string
182-
// again_terminal_trail(NEXT_CS(p), p+1);
181+
//case 0xc1: // never used
183182
case 0xc2: // false
184183
push_simple_value(_false);
185184
case 0xc3: // true
186185
push_simple_value(_true);
187-
//case 0xc4:
188-
//case 0xc5:
189-
//case 0xc6:
186+
case 0xc4: // bin 8
187+
again_fixed_trail(NEXT_CS(p), 1);
188+
case 0xc5: // bin 16
189+
again_fixed_trail(NEXT_CS(p), 2);
190+
case 0xc6: // bin 32
191+
again_fixed_trail(NEXT_CS(p), 4);
190192
case 0xc7: // ext 8
191193
again_fixed_trail(NEXT_CS(p), 1);
192194
case 0xc8: // ext 16
@@ -213,7 +215,8 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, size_t l
213215
_ext_zero);
214216
case 0xd8: // fixext 16
215217
again_fixed_trail_if_zero(ACS_EXT_VALUE, 16+1, _ext_zero);
216-
//case 0xd9:
218+
case 0xd9: // str 8
219+
again_fixed_trail(NEXT_CS(p), 1);
217220
case 0xda: // raw 16
218221
case 0xdb: // raw 32
219222
case 0xdc: // array 16

test/test_obj.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_only_one_obj_hook():
3535
unpackb(b'', object_hook=lambda x: x, object_pairs_hook=lambda x: x)
3636

3737
def test_bad_hook():
38-
with raises(ValueError):
38+
with raises(TypeError):
3939
packed = packb([3, 1+2j], default=lambda o: o)
4040
unpacked = unpackb(packed, use_list=1)
4141

0 commit comments

Comments
 (0)