summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPramukta Kumar <pramukta.kumar@gmail.com>2015-03-17 15:16:17 -0400
committerPramukta Kumar <pramukta.kumar@gmail.com>2015-03-17 15:16:17 -0400
commit6f02d252e1dc66d67861b45c5bead8392ed822d4 (patch)
treeff9a275ecabd21f5ce3ebf120cdcd72780fd49b0
parent10cd2d2ebf6390e844c2bf59e9efd765f9b60e40 (diff)
downloadmsgpack-python-6f02d252e1dc66d67861b45c5bead8392ed822d4.tar.gz
corresponding change to cython implementation
-rw-r--r--msgpack/_packer.pyx20
1 files changed, 14 insertions, 6 deletions
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index fcd20a7..7129208 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -136,12 +136,20 @@ cdef class Packer(object):
elif PyLong_Check(o):
# PyInt_Check(long) is True for Python 3.
# Sow we should test long before int.
- if o > 0:
- ullval = o
- ret = msgpack_pack_unsigned_long_long(&self.pk, ullval)
- else:
- llval = o
- ret = msgpack_pack_long_long(&self.pk, llval)
+ try:
+ if o > 0:
+ ullval = o
+ ret = msgpack_pack_unsigned_long_long(&self.pk, ullval)
+ else:
+ llval = o
+ ret = msgpack_pack_long_long(&self.pk, llval)
+ except OverflowError, oe:
+ if not default_used and self._default is not None:
+ o = self._default(o)
+ default_used = True
+ continue
+ else:
+ raise
elif PyInt_Check(o):
longval = o
ret = msgpack_pack_long(&self.pk, longval)