7
7
8
8
cdef tid_encode(ConnectionSettings settings, WriteBuffer buf, obj):
9
9
cdef int overflow = 0
10
- cdef long block, offset
10
+ cdef unsigned long block, offset
11
11
12
12
if not (cpython.PyTuple_Check(obj) or cpython.PyList_Check(obj)):
13
13
raise TypeError (
@@ -18,25 +18,24 @@ cdef tid_encode(ConnectionSettings settings, WriteBuffer buf, obj):
18
18
' invalid number of elements in tid tuple, expecting 2' )
19
19
20
20
try :
21
- block = cpython.PyLong_AsLong (obj[0 ])
21
+ block = cpython.PyLong_AsUnsignedLong (obj[0 ])
22
22
except OverflowError :
23
23
overflow = 1
24
24
25
25
# "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 ):
28
27
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 ]))
30
29
31
30
try :
32
- offset = cpython.PyLong_AsLong (obj[1 ])
31
+ offset = cpython.PyLong_AsUnsignedLong (obj[1 ])
33
32
overflow = 0
34
33
except OverflowError :
35
34
overflow = 1
36
35
37
- if overflow or offset < - 32768 or offset > 32767 :
36
+ if overflow or offset > 65535 :
38
37
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 ]))
40
39
41
40
buf.write_int32(6 )
42
41
buf.write_int32(< int32_t> block)
@@ -45,11 +44,11 @@ cdef tid_encode(ConnectionSettings settings, WriteBuffer buf, obj):
45
44
46
45
cdef tid_decode(ConnectionSettings settings, FastReadBuffer buf):
47
46
cdef:
48
- int32_t block
49
- int16_t offset
47
+ uint32_t block
48
+ uint16_t offset
50
49
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 ))
53
52
54
53
return (block, offset)
55
54
0 commit comments