rtyler / py-yajl

py-yajl provides Python bindings for the Yajl JSON encoder/decoder library
http://rtyler.github.com/py-yajl
74 stars 18 forks source link

Large numbers don't work #16

Closed runeh closed 14 years ago

runeh commented 14 years ago

Dealing with large numbers either throw OverflowError or returns -1. Twitter's tweet IDs are currently large enough to trigger this, so there are some real world use cases.

>>> yajl.dumps([11889582081])
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: long int too large to convert to int
>>> yajl.dumps([11889582082])
'[-1]'
runeh commented 14 years ago

Did another quick test. Seems that there is some state maintained between the calls, as trying to dump the same value twice gives different results:

>>> yajl.dumps(1233333333333)
'-1'
>>> yajl.dumps(1233333333333)
Traceback (most recent call last):
  File "", line 1, in 
OverflowError: long int too large to convert to int
>>> yajl.dumps(1233333333333)
'-1'
rtyler commented 14 years ago

Are you running this with the latest HEAD? I've added a test to try this and it's working properly for me:

>>> yajl.dumps([11889582081])
'[11889582081]'
>>> yajl.dumps([11889582082])
'[11889582082]'
rtyler commented 14 years ago

Also, are you on a 32-bit architecture per-chance? I'm on Linux/amd64 so I'm wondering if that could be related

rtyler commented 14 years ago

Aha! This is very much a 32-bit machine problem, see Hudson build 73, which was run against only 32-bit machines.

I'll see what I can do :)

rtyler commented 14 years ago

Corrected with SHA: 1c276f4366746c973b0e92061e528dda87403f13

runeh commented 14 years ago

Verified fixed in master. Thanks!