summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>2013-05-16 12:41:02 +0900
committerYAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>2013-05-16 12:41:53 +0900
commitb0c193f3e07fdabc3d489bd5e134e3e41733f204 (patch)
tree57e7e90a3b0d6e5521c5362b4cc894c600597129
parent82313b713e83ce3fc18080bb22df99c1ae8ad914 (diff)
downloadmsgpack-python-b0c193f3e07fdabc3d489bd5e134e3e41733f204.tar.gz
fix long/int confusions in pyx version of unpack
-rw-r--r--msgpack/unpack.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/msgpack/unpack.h b/msgpack/unpack.h
index 595b8df..fb13b4e 100644
--- a/msgpack/unpack.h
+++ b/msgpack/unpack.h
@@ -68,7 +68,12 @@ static inline int unpack_callback_uint32(unpack_user* u, uint32_t d, msgpack_unp
static inline int unpack_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o)
{
- PyObject *p = PyLong_FromUnsignedLongLong(d);
+ PyObject *p;
+ if (d > LONG_MAX) {
+ p = PyLong_FromUnsignedLongLong((unsigned long)d);
+ } else {
+ p = PyInt_FromLong((long)d);
+ }
if (!p)
return -1;
*o = p;
@@ -96,9 +101,12 @@ static inline int unpack_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_
static inline int unpack_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o)
{
- PyObject *p = PyLong_FromLongLong(d);
- if (!p)
- return -1;
+ PyObject *p;
+ if (d > LONG_MAX || d < LONG_MIN) {
+ p = PyLong_FromLongLong((unsigned long)d);
+ } else {
+ p = PyInt_FromLong((long)d);
+ }
*o = p;
return 0;
}