for Chez Int type is mapped to C int. On some systems (like 64 bit Linux) int is 32-bit, so it is not enough to handle for example array offset
some native functions (like idris2_writeBufferData) declare Int parameter in Idris (thus, int in C), but accept size_t in C code. Which kinda works with current C calling conventions, but generally it is incorrect
I propose this convention: Int is mapped to intptr_t in FFI, all codegen and FFI need to be adjusted.
Possible alternatives are:
size_t is not signed
ssize_t is not in C standard
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.
There are issues with integer types in FFI:
Int
type is mapped to Cint
. On some systems (like 64 bit Linux)int
is 32-bit, so it is not enough to handle for example array offsetidris2_writeBufferData
) declareInt
parameter in Idris (thus,int
in C), but acceptsize_t
in C code. Which kinda works with current C calling conventions, but generally it is incorrectI propose this convention:
Int
is mapped tointptr_t
in FFI, all codegen and FFI need to be adjusted.Possible alternatives are:
size_t
is not signedssize_t
is not in C standardNote
Int
is smaller thanintptr_t
, for example, on my mac, Chez(most-positive-fixnum)
is 1152921504606846975, which is(1 << 60) - 1
. SoInt
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.