<p></p>
<p>Given the external function defined by the following Squeak method:</p>
<div class="highlight highlight-source-smalltalk"><pre><span class="pl-c1">myFunc:</span> aFloat64Array

        <span class="pl-k"><</span><span class="pl-c1">apicall:</span> void <span class="pl-s"><span class="pl-pds">'</span>myFunc<span class="pl-pds">'</span></span> (double<span class="pl-k">*</span>)<span class="pl-k">></span>
        <span class="pl-k">^</span> <span class="pl-k">self</span> externalCallFailed</pre></div>
<p>When passing an instance of <code>Float64Array</code> to this method, the FFI plugin throws error code 6 (<code>Could not coerce arguments</code>).<br>
The same can be reproduced in similar scenarios for other 64-bit indexable objects like <code>DoubleWordArray</code> and <code>SignedDoubleWordArray</code> (which ultimately share the same class format anyway).<br>
There were no issues when doing the same using 32-bit indexable objects.</p>
<hr>
<p>As far as I can tell the issue seems to stem from <code>ThreadedFFIPlugin >> ffiAtomicArgByReference:Class:in:</code> which ends with the following code:</p>
<div class="highlight highlight-source-smalltalk"><pre>(atomicType <span class="pl-k"><=</span> <span class="pl-c1">FFITypeDoubleFloat</span>) <span class="pl-k">ifTrue:</span>
        [((interpreterProxy <span class="pl-c1">isWords:</span> oop) <span class="pl-k">or</span>: [oopClass <span class="pl-k">=</span> interpreterProxy classByteArray]) <span class="pl-k">ifTrue:</span>
                [<span class="pl-k">^</span><span class="pl-k">self</span> <span class="pl-c1">ffiPushPointer:</span> (interpreterProxy <span class="pl-c1">firstIndexableField:</span> oop) <span class="pl-c1">in:</span> calloutState].
        (oopClass <span class="pl-k">=</span> interpreterProxy classExternalAddress) <span class="pl-k">ifTrue:</span> 
                [<span class="pl-k">^</span><span class="pl-k">self</span> <span class="pl-c1">ffiPushPointer:</span> (<span class="pl-k">self</span> <span class="pl-c1">longAt:</span> oop <span class="pl-k">+</span> interpreterProxy baseHeaderSize) <span class="pl-c1">in:</span> calloutState].
        isAlien <span class="pl-k">ifTrue:</span>
                [<span class="pl-k">^</span><span class="pl-k">self</span> <span class="pl-c1">ffiPushPointer:</span> (<span class="pl-k">self</span> <span class="pl-c1">pointerForOop:</span> (<span class="pl-k">self</span> <span class="pl-c1">startOfData:</span> oop)) <span class="pl-c1">in:</span> calloutState]].

<span class="pl-k">^</span><span class="pl-c1">FFIErrorCoercionFailed</span></pre></div>
<p>While the second line checks 32-bit indexable via <code>isWords:</code> and byte arrays, it seems to be missing a test for <code>isLong64s:</code>.</p>
<hr>
<p>Just in case it's relevant for some reason:</p>
<pre><code>Squeak
latest update: #20467
Image format 68021 (64 bit)
Preferred bytecode set: SistaV1
</code></pre>
<pre><code>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
</code></pre>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/569">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AIJPEW7FLSJPNYJXEPNBHE3TSBTOFANCNFSM46NQWGBA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AIJPEW2RQIKGANKD6LJODFDTSBTOFA5CNFSM46NQWGBKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4NVIRO3Q.gif" height="1" width="1" alt="" /></p>
<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>