idris-lang / Idris2

A purely functional programming language with first class types
https://idris-lang.org/
Other
2.51k stars 374 forks source link

Inconsistent Int type handling in FFI #1672

Open stepancheg opened 3 years ago

stepancheg commented 3 years ago

There are issues with integer types in FFI:

I propose this convention: Int is mapped to intptr_t in FFI, all codegen and FFI need to be adjusted.

Possible alternatives are:

Note Int is smaller than intptr_t, for example, on my mac, Chez (most-positive-fixnum) is 1152921504606846975, which is (1 << 60) - 1. So Int is not enough to store a pointer, but enough to store a pointer difference.

So there will be no overflow when passing Int to FFI, but FFI function need to be careful to not produce too large integer return values.

gallais commented 3 years ago

Is this #1048?

stepancheg commented 3 years ago

Looks like it the issue you mentioned is related but different.