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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

David T Lewis
 

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.

<script type="application/ld+json">[ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/569", "url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/569", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } } ]</script>