77
88cdef tid_encode(ConnectionSettings settings, WriteBuffer buf, obj):
99 cdef int overflow = 0
10- cdef long block, offset
10+ cdef unsigned long block, offset
1111
1212 if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
1313 raise TypeError (
@@ -18,25 +18,24 @@ cdef tid_encode(ConnectionSettings settings, WriteBuffer buf, obj):
1818 ' invalid number of elements in tid tuple, expecting 2' )
1919
2020 try :
21- block = cpython.PyLong_AsLong (obj[0 ])
21+ block = cpython.PyLong_AsUnsignedLong (obj[0 ])
2222 except OverflowError :
2323 overflow = 1
2424
2525 # "long" and "long long" have the same size for x86_64, need an extra check
26- if overflow or (sizeof(block) > 4 and (block < - 2147483648 or
27- block > 2147483647 )):
26+ if overflow or (sizeof(block) > 4 and block > 4294967295 ):
2827 raise OverflowError (
29- ' block too big to be encoded as INT4 : {!r}' .format(obj[0 ]))
28+ ' block too big to be encoded as UINT4 : {!r}' .format(obj[0 ]))
3029
3130 try :
32- offset = cpython.PyLong_AsLong (obj[1 ])
31+ offset = cpython.PyLong_AsUnsignedLong (obj[1 ])
3332 overflow = 0
3433 except OverflowError :
3534 overflow = 1
3635
37- if overflow or offset < - 32768 or offset > 32767 :
36+ if overflow or offset > 65535 :
3837 raise OverflowError (
39- ' offset too big to be encoded as INT2 : {!r}' .format(obj[1 ]))
38+ ' offset too big to be encoded as UINT2 : {!r}' .format(obj[1 ]))
4039
4140 buf.write_int32(6 )
4241 buf.write_int32(< int32_t> block)
@@ -45,11 +44,11 @@ cdef tid_encode(ConnectionSettings settings, WriteBuffer buf, obj):
4544
4645cdef tid_decode(ConnectionSettings settings, FastReadBuffer buf):
4746 cdef:
48- int32_t block
49- int16_t offset
47+ uint32_t block
48+ uint16_t offset
5049
51- block = hton.unpack_int32(buf.read(4 ))
52- offset = hton.unpack_int16(buf.read(2 ))
50+ block = < uint32_t > hton.unpack_int32(buf.read(4 ))
51+ offset = < uint16_t > hton.unpack_int16(buf.read(2 ))
5352
5453 return (block, offset)
5554
0 commit comments