mirror of
https://github.com/msgpack/msgpack-python.git
synced 2026-02-06 17:59:52 +00:00
commit
8f82252687
3 changed files with 28 additions and 2 deletions
|
|
@ -163,6 +163,8 @@ static inline int template_callback_array_end(unpack_user* u, msgpack_unpack_obj
|
|||
{
|
||||
if (u->list_hook) {
|
||||
PyObject *new_c = PyEval_CallFunction(u->list_hook, "(O)", *c);
|
||||
if (!new_c)
|
||||
return -1;
|
||||
Py_DECREF(*c);
|
||||
*c = new_c;
|
||||
}
|
||||
|
|
@ -207,6 +209,9 @@ static inline int template_callback_map_end(unpack_user* u, msgpack_unpack_objec
|
|||
{
|
||||
if (u->object_hook) {
|
||||
PyObject *new_c = PyEval_CallFunction(u->object_hook, "(O)", *c);
|
||||
if (!new_c)
|
||||
return -1;
|
||||
|
||||
Py_DECREF(*c);
|
||||
*c = new_c;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ _push:
|
|||
if(construct_cb(_array_item)(user, c->count, &c->obj, obj) < 0) { goto _failed; }
|
||||
if(++c->count == c->size) {
|
||||
obj = c->obj;
|
||||
construct_cb(_array_end)(user, &obj);
|
||||
if (construct_cb(_array_end)(user, &obj) < 0) { goto _failed; }
|
||||
--top;
|
||||
/*printf("stack pop %d\n", top);*/
|
||||
goto _push;
|
||||
|
|
@ -361,7 +361,7 @@ _push:
|
|||
if(construct_cb(_map_item)(user, c->count, &c->obj, c->map_key, obj) < 0) { goto _failed; }
|
||||
if(++c->count == c->size) {
|
||||
obj = c->obj;
|
||||
construct_cb(_map_end)(user, &obj);
|
||||
if (construct_cb(_map_end)(user, &obj) < 0) { goto _failed; }
|
||||
--top;
|
||||
/*printf("stack pop %d\n", top);*/
|
||||
goto _push;
|
||||
|
|
|
|||
|
|
@ -49,5 +49,26 @@ def test_array_hook():
|
|||
unpacked = unpackb(packed, list_hook=_arr_to_str, use_list=1)
|
||||
eq_(unpacked, '123')
|
||||
|
||||
|
||||
class DecodeError(Exception):
|
||||
pass
|
||||
|
||||
def bad_complex_decoder(o):
|
||||
raise DecodeError("Ooops!")
|
||||
|
||||
|
||||
@raises(DecodeError)
|
||||
def test_an_exception_in_objecthook1():
|
||||
packed = packb({1: {'__complex__': True, 'real': 1, 'imag': 2}})
|
||||
unpackb(packed, object_hook=bad_complex_decoder)
|
||||
|
||||
|
||||
@raises(DecodeError)
|
||||
def test_an_exception_in_objecthook2():
|
||||
packed = packb({1: [{'__complex__': True, 'real': 1, 'imag': 2}]})
|
||||
unpackb(packed, list_hook=bad_complex_decoder, use_list=1)
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue