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

Stephan Lutz notifications at github.com
Thu Jun 10 07:36:02 UTC 2021


Given the external function defined by the following Squeak method:
```smalltalk
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:
```smalltalk
(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 or view it on GitHub:
https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/569
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20210610/1c2dec96/attachment.html>


More information about the Vm-dev mailing list