Mantis - Squeak
Viewing Issue Advanced Details
7720 VM minor always 01-19-13 01:37 01-23-13 09:07
nicolas cellier  
assigned trunk  
0007720: FFI silently accept a 64bits argument > LLONG_MAX instead of failing
1. Create a FFI call to a function taking a signed long long (64 bits) integer
2. Call the function with (1<<63)

A well behaved FFIPlugin should fail, because 1<<63 is greater than maximal representable signed long long (presumably 1<<63-1 in two complement).

But instead of failing, FFI interpret 1<<63 as a negative int, which is a bad feature.
This is caused by FFIPlugin>>#ffiPushSignedLongLongOop: which omit to test this case of LLONG_MAX overflow...

Note that COG version (ThreadedFFIPlugin>>#ffiPushSignedLongLongOop:in:) is correct because it uses #signed64BitValueOf:
related to 0007237acknowledged lewis Make FFI work on 64 bit platforms 

nicolas cellier   
01-23-13 09:07   
Note that [^] contains an idea of correction for FFIPlugin>>ffiPushSignedLongLongOop:

signed/unsigned word agnostic could be:

((highWord bitAnd: 16r80000000) = 0 or: [negative and: [lowWord = 0 and: [(highWord
bitXor: 16r80000000) = 0]) ifFalse: [ ffi coercion failed ]