[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] ThreadedFFIPlugin throws FFIErrorCoercionFailed when passing 64-bit indexable objects to 64-bit pointer arguments (#569)

Eliot Miranda notifications at github.com
Fri Jul 2 12:25:31 UTC 2021


Hi Stephan, (Hi Nicolas),

    I’ll try and fix this soon.  If you can, look at ThreadedFFIPlugin, and we would need to add slots in the specialObjectsArray for Float32Array and Float64Array so that the marshaling code can identify instances of these classes quickly. Better still, these classes could be given known class indices and then the marshaling code can identify instances of these classes even quicker :-)

_,,,^..^,,,_ (phone)

> On Jun 10, 2021, at 12:36 AM, Stephan Lutz ***@***.***> wrote:
> 
> 
> Given the external function defined by the following Squeak method:
> 
> myFunc: aFloat64Array
> 
> 	<apicall: void 'myFunc' (double*)>
> 	^ self externalCallFailed
> When passing an instance of Float64Array to this method, the FFI plugin throws error code 6 (Could not coerce arguments).
> The same can be reproduced in similar scenarios for other 64-bit indexable objects like DoubleWordArray and SignedDoubleWordArray (which ultimately share the same class format anyway).
> There were no issues when doing the same using 32-bit indexable objects.
> 
> As far as I can tell the issue seems to stem from ThreadedFFIPlugin >> ffiAtomicArgByReference:Class:in: which ends with the following code:
> 
> (atomicType <= FFITypeDoubleFloat) ifTrue:
> 	[((interpreterProxy isWords: oop) or: [oopClass = interpreterProxy classByteArray]) ifTrue:
> 		[^self ffiPushPointer: (interpreterProxy firstIndexableField: oop) in: calloutState].
> 	(oopClass = interpreterProxy classExternalAddress) ifTrue: 
> 		[^self ffiPushPointer: (self longAt: oop + interpreterProxy baseHeaderSize) in: calloutState].
> 	isAlien ifTrue:
> 		[^self ffiPushPointer: (self pointerForOop: (self startOfData: oop)) in: calloutState]].
> 
> ^FFIErrorCoercionFailed
> While the second line checks 32-bit indexable via isWords: and byte arrays, it seems to be missing a test for isLong64s:.
> 
> Just in case it's relevant for some reason:
> 
> Squeak
> latest update: #20467
> Image format 68021 (64 bit)
> Preferred bytecode set: SistaV1
> Open Smalltalk Cog[Spur] VM [CoInterpreterPrimitives VMMaker.oscog-eem.2940]
> Unix built on Jun  9 2021 14:12:17 Compiler: Clang 10.0.0 
> platform sources revision VM: 202102090434 Date: Mon Feb 8 20:34:38 2021 CommitHash: 9f1b4644e Plugins: 202102090434
> CoInterpreter VMMaker.oscog-eem.2940 uuid: 29171f50-756f-4560-8488-ced65f2d4841 Jun  9 2021
> StackToRegisterMappingCogit VMMaker.oscog-eem.2940 uuid: 29171f50-756f-4560-8488-ced65f2d4841 Jun  9 2021
>> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or unsubscribe.


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/569#issuecomment-872959044
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20210702/0c0d1091/attachment.html>


More information about the Vm-dev mailing list