Skip to content

Commit b0c193f

Browse files
committed
fix long/int confusions in pyx version of unpack
1 parent 82313b7 commit b0c193f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

msgpack/unpack.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ static inline int unpack_callback_uint32(unpack_user* u, uint32_t d, msgpack_unp
6868

6969
static inline int unpack_callback_uint64(unpack_user* u, uint64_t d, msgpack_unpack_object* o)
7070
{
71-
PyObject *p = PyLong_FromUnsignedLongLong(d);
71+
PyObject *p;
72+
if (d > LONG_MAX) {
73+
p = PyLong_FromUnsignedLongLong((unsigned long)d);
74+
} else {
75+
p = PyInt_FromLong((long)d);
76+
}
7277
if (!p)
7378
return -1;
7479
*o = p;
@@ -96,9 +101,12 @@ static inline int unpack_callback_int8(unpack_user* u, int8_t d, msgpack_unpack_
96101

97102
static inline int unpack_callback_int64(unpack_user* u, int64_t d, msgpack_unpack_object* o)
98103
{
99-
PyObject *p = PyLong_FromLongLong(d);
100-
if (!p)
101-
return -1;
104+
PyObject *p;
105+
if (d > LONG_MAX || d < LONG_MIN) {
106+
p = PyLong_FromLongLong((unsigned long)d);
107+
} else {
108+
p = PyInt_FromLong((long)d);
109+
}
102110
*o = p;
103111
return 0;
104112
}

0 commit comments

Comments
 (0)