Closed xlongshu closed 2 weeks ago
This seems to be due to the C int32's range. If I make a copy of "bencode.py" and import bencode from it, the result will be correct.
from bencode import bencode
print(bencode(2147483647))
print(bencode(2147483648))
print(bencode(11856280181))
Result:
b'i2147483647e' b'i-2147483648e' b'i-1028621707e'
Result from the copied "bencode.py":
b'i2147483647e' b'i2147483648e' b'i11856280181e'
Sorry for the late reply. It seems PyOS_snprintf does not take very large int into account. or should we just use PyLongObject instead of c int?
How about this one?
How about this one?
Thanks a lot, it works great for me. (I tried it in Python 3.11, on Windows 10 22H2 x64)
Ok, I'll release a new version later.
1.1.7 is ready.
Windows
b'd4:intAi2147483647e4:intBi-2147483648ee'
Linux
b'd4:intAi2147483647e4:intBi2147483648ee'