<div dir="ltr"><div>Hi Levente,</div><div><br></div><div>    I just wanted to note a potential problem with Collections-ul.667</div><div><br></div><div>Name: Collections-ul.667</div><div>Author: ul</div><div>Time: 10 October 2015, 3:40:46.732 pm</div><div>UUID: 7cd785ff-1839-4075-ac56-4b71054529d8</div><div>Ancestors: Collections-topa.666</div><div><br></div><div>Added the missing methods of ByteArray&#39;s platform independent access category: #signedByteAt: #signedByteAt:put: #long64At:put:bigEndian: and #long64At:bigEndian:. The 64-bit methods are not optimized.</div><div><br></div><div><br></div><div>In this version you provided ByteArray&gt;&gt;#signedByteAt:[put:] which conflicts with FFI-Kernel&#39;s methods of the same name.  There&#39;s a difference in semantics.  If you look at ExternalStructure&#39;s class comment it points out that</div><div><br></div><div>&quot;This class provides an abstract base for all structures that can be used by external functions. ExternalStructures have two possible handle types:</div><div><span class="" style="white-space:pre">        </span>- ExternalAddress</div><div><span class="" style="white-space:pre">                </span>If the handle is an external address then the object described does not reside in the Smalltalk object memory.</div><div><span class="" style="white-space:pre">        </span>- ByteArray</div><div><span class="" style="white-space:pre">                </span>If the handle is a byte array then the object described resides in Smalltalk memory.</div><div>Useful methods should be implemented by subclasses of ExternalStructure using the common ByteArray/ExternalAddress platform dependent access protocol which will transparently access the correct memory location.&quot;</div><div><br></div><div>i.e. the primitives used automatically differentiate between an ExternalAddress holding a pointer to external memory, in which case the datum is accessed via that location, or a ByteArray, in which case the datum is accessed in the ByteArray.  Your versions only do the latter and would hence misinterpret data in ExternalAdderss instances.  Here&#39;s the FFI code:</div><div><br></div><div>ByteArray&gt;&gt;signedByteAt: byteOffset</div><div><span class="" style="white-space:pre">        </span>&quot;Return a 8bit signed integer starting at the given byte offset&quot;</div><div><span class="" style="white-space:pre">        </span>^self integerAt: byteOffset size: 1 signed: true</div><div><br></div><div>ByteArray&gt;&gt;integerAt: byteOffset size: nBytes signed: aBoolean</div><div><span class="" style="white-space:pre">        </span>&quot;Primitive. Return an integer of nBytes size from the receiver.</div><div><span class="" style="white-space:pre">        </span>Note: This primitive will access memory in the outer space if</div><div><span class="" style="white-space:pre">        </span>invoked from ExternalAddress.&quot;</div><div><span class="" style="white-space:pre">        </span>&lt;primitive: &#39;primitiveFFIIntegerAt&#39; module:&#39;SqueakFFIPrims&#39;&gt;</div><div><span class="" style="white-space:pre">        </span>^self primitiveFailed</div><div><br></div><div>And here&#39;s yours:</div><div>ByteArray&gt;&gt;signedByteAt: index</div><div><span class="" style="white-space:pre">        </span>&quot;Return an 8-bit signed integer quantity from the given byte index.&quot;</div><div><span class="" style="white-space:pre">        </span></div><div><span class="" style="white-space:pre">        </span>| byte |</div><div><span class="" style="white-space:pre">        </span>(byte := self at: index) &lt;= 16r7F ifTrue: [ ^byte ].</div><div><span class="" style="white-space:pre">        </span>^byte - 16r100</div><div><br></div><div>Now of course this isn&#39;t an issue in builds that load the FFI after Collections, but it does affect images in which FFI-Kernel was loaded and then the image was updated to instal Collections-ul.667.</div><div><br></div><div>I&#39;m not sure what the right fix is, but I thought I&#39;d better mention it.  One obvious one is to implement the FFI methods in ExternalAddress&gt;&gt;#signedByteAt:[put:], and if folks agree I can do this.  Let me know.  Pharoers, if I do this, you&#39;ll need to make sure that the Pharo base includes ByteArray&gt;&gt;#signedByteAt:[put:].</div><div><br></div><div class="gmail_signature"><div dir="ltr"><div><span style="font-size:small;border-collapse:separate"><div>_,,,^..^,,,_<br></div><div>best, Eliot</div></span></div></div></div>
</div>