Skip to content

Commit fcf02a6

Browse files
sebastinasdsacre
authored andcommitted
don't distinguish between int and long
if no type is explicitly specified, send as int32 if possible, otherwise use int64 automatically. Py3 has no separate 'long' type anyway, and on 64 bit systems the ranges of Py2's int and C's int32_t don't match.
1 parent 54c52a9 commit fcf02a6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/liblo.pyx

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ from libc.stdlib cimport malloc, free
2020
cdef extern from 'math.h':
2121
double modf(double x, double *iptr)
2222

23+
from libc.stdint cimport int32_t, int64_t
24+
2325
from liblo cimport *
2426

2527
import inspect as _inspect
@@ -820,10 +822,11 @@ cdef class Message:
820822
lo_message_add_true(self._message)
821823
elif value is False:
822824
lo_message_add_false(self._message)
823-
elif isinstance(value, int):
824-
lo_message_add_int32(self._message, int(value))
825-
elif isinstance(value, long):
826-
lo_message_add_int64(self._message, long(value))
825+
elif isinstance(value, (int, long)):
826+
try:
827+
lo_message_add_int32(self._message, <int32_t>value)
828+
except OverflowError:
829+
lo_message_add_int64(self._message, <int64_t>value)
827830
elif isinstance(value, float):
828831
lo_message_add_float(self._message, float(value))
829832
elif isinstance(value, (bytes, unicode)):

0 commit comments

Comments
 (0)