Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Integer overflow on 32 bit system #518

Open
nooga opened this issue Aug 11, 2016 · 0 comments
Open

Integer overflow on 32 bit system #518

nooga opened this issue Aug 11, 2016 · 0 comments

Comments

@nooga
Copy link
Contributor

nooga commented Aug 11, 2016

I'm using pixie on 32 bit armhf.

Take (pixie.uv/uv_hrtime) for instance. It returns CUInt64.
Then, ffi_get_value unpacks the value by casting it to signed rffi.LONG, which is pixie's Integer value.

user => (uv_hrtime)
-1474318557
user => (type (uv_hrtime))
pixie.stdlib.Integer

See: ffi.py#L289

It seems that all numeric types are cast to Integer, which seems to be signed long equivalent and it's 32 bit wide on 32-bit system. long long should be used to express 64 bit wide numbers on 32-bit systems.

Moreover, literals are also affected. For instance:

user => 10000000000
1410065408
user => -10000000000
-1410065408
user => (type 10000000000)
pixie.stdlib.Integer

Not suprisingly, similar overflow occurs on 64-bit systems but the literal must be significantly larger.
One might use BigInteger literal defensively here, but it's not necessary on 64-bit systems and introduces performance hit.

First obvious solution would be to auto promote wider numeric types to BigInteger on 32-bit systems in ffi and reader. I imagine that this would increase apparent compatibility between 32-bit and 64-bit systems. On the other hand, it will cause significant performance hit and may, eventually, cause different compatibility issues because huge integers on 32-bit will become 'wider' than on 64-bit.

The other solution would be to implement LongInteger that'd represent 64-bit numbers on 32-bit machines and on 64-bit machines it would be same as Integer. Again, I'm not sure if there are any problems associated with this approach and how will it affect the interpreter.

I'm not sure how to proceed and what solution would be the most beneficial for the language.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant