<p></p>
<p>In an FFI plugin that supports the new integer primitives, <code>maxVal</code> is wrong for unsigned types other than "uint8_t":</p>
<p><a target="_blank" rel="noopener noreferrer" href="https://user-images.githubusercontent.com/5765308/128748244-322f9952-c19c-4c8b-8970-290c38b04b2e.png"><img src="https://user-images.githubusercontent.com/5765308/128748244-322f9952-c19c-4c8b-8970-290c38b04b2e.png" alt="grafik" style="max-width:100%;"></a></p>
<p>This issue can be reproduced in any "FFI-Kernel" that supports those primitives such as "FFI-Kernel-mt.187" and newer:</p>
<div class="highlight highlight-source-smalltalk"><pre><span class="pl-c1">#( int8_t uint8_t int16_t uint16_t int32_t uint32_t int64_t uint64_t )</span> 
<span class="pl-c1">collect:</span> [<span class="pl-en">:typeName</span> | | <span class="pl-c1">type</span> |
        type <span class="pl-k">:=</span> <span class="pl-c1">ExternalType</span> <span class="pl-c1">typeNamed:</span> typeName.
        typeName <span class="pl-k">-</span><span class="pl-k">></span> (type minVal <span class="pl-c1">to:</span> type maxVal)]
<span class="pl-c1">as:</span> <span class="pl-c1">OrderedDictionary</span></pre></div>
<p><strong>The older primitives "primitiveFFIIntegerAt" and "primitiveFFIIntegerAtPut" worked as expected.</strong> The <code>maxVal</code> implementation writes single bytes but reads as much as the type demands. Here is an excerpt for the "unsigned" case:</p>
<div class="highlight highlight-source-smalltalk"><pre>| <span class="pl-c1">data</span> <span class="pl-c1">bytes</span> |
bytes <span class="pl-k">:=</span> <span class="pl-c1">ByteArray</span> <span class="pl-k">new</span>: <span class="pl-k">self</span> byteSize.
data <span class="pl-k">:=</span> <span class="pl-c1">ExternalData</span> <span class="pl-c1">fromHandle:</span> bytes <span class="pl-c1">type:</span> <span class="pl-k">self</span> <span class="pl-c1">size:</span> <span class="pl-c1">1</span>.
        
bytes <span class="pl-c1">atAllPut:</span> 16rFF. <span class="pl-c"><span class="pl-c">"</span>Set all bits for maxVal of an unsigned integer. Uses older primitive 145.<span class="pl-c">"</span></span>
<span class="pl-k">^</span> data value. <span class="pl-c"><span class="pl-c">"</span>-> ends up calling the new primitive in ByteArray such as uint16At:<span class="pl-c">"</span></span></pre></div>
<p>Note that "int8_t" and "uint8_t" work as expected.</p>

<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/584">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AIJPEW2C242WVL27SDKUXK3T4AHIHANCNFSM5B2PJG7A">unsubscribe</a>.<br />Triage notifications on the go with GitHub Mobile for <a href="https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675">iOS</a> or <a href="https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email">Android</a>.<img src="https://github.com/notifications/beacon/AIJPEW6NHPAG6D6U5XOSBC3T4AHIHA5CNFSM5B2PJG7KYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4OLY26FA.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/584",
"url": "https://github.com/OpenSmalltalk/opensmalltalk-vm/issues/584",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>