From 718a3efd64b859d052a1cd94e2025c61c84d7af7 Mon Sep 17 00:00:00 2001 From: INADA Naoki Date: Sat, 29 Jan 2011 23:22:41 +0900 Subject: [PATCH] python: Fix segmentation fault when `default` returns it's argument. --- python/msgpack/_msgpack.pyx | 4 ++-- python/test/test_obj.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/msgpack/_msgpack.pyx b/python/msgpack/_msgpack.pyx index 4df03458..9a6c232c 100644 --- a/python/msgpack/_msgpack.pyx +++ b/python/msgpack/_msgpack.pyx @@ -118,9 +118,9 @@ cdef class Packer(object): for v in o: ret = self._pack(v, nest_limit-1) if ret != 0: break - elif self._default is not None: + elif self._default: o = self._default(o) - ret = self._pack(o, nest_limit) + ret = self._pack(o, nest_limit-1) else: raise TypeError("can't serialize %r" % (o,)) return ret diff --git a/python/test/test_obj.py b/python/test/test_obj.py index bc857361..0eebe7be 100644 --- a/python/test/test_obj.py +++ b/python/test/test_obj.py @@ -26,7 +26,7 @@ def test_decode_hook(): unpacked = unpacks(packed, object_hook=_decode_complex) eq_(unpacked[1], 1+2j) -@raises(TypeError) +@raises(ValueError) def test_bad_hook(): packed = packs([3, 1+2j], default=lambda o: o) unpacked = unpacks(packed)