<div dir="ltr"><div style>I was looking at the following primitiveFileRead because I wanted to extract some code. I do not see why objects should move during the primitive execution... And I do not see why is this check only made in this primitive (and the threadedFFI ones...).</div>
<div style><br></div><div style>Does someone have a clue?</div><div style><br></div><div style>Thanks,</div><div style>Guille</div><div><br></div><div>primitiveFileRead</div><div><span class="" style="white-space:pre">        </span><export: true></div>
<div><span class="" style="white-space:pre">        </span>| retryCount count startIndex array file elementSize bytesRead |</div><div><span class="" style="white-space:pre">        </span><var: 'file' type: #'SQFile *'></div>
<div><span class="" style="white-space:pre">        </span><var: 'count' type: #'size_t'></div><div><span class="" style="white-space:pre">        </span><var: 'startIndex' type: #'size_t'></div>
<div><span class="" style="white-space:pre">        </span><var: 'elementSize' type: #'size_t'></div><div><br></div><div><span class="" style="white-space:pre">        </span>retryCount<span class="" style="white-space:pre">        </span>:= 0.</div>
<div><span class="" style="white-space:pre">        </span>count<span class="" style="white-space:pre">                </span>:= interpreterProxy positive32BitValueOf: (interpreterProxy stackValue: 0).</div><div><span class="" style="white-space:pre">        </span>startIndex<span class="" style="white-space:pre">        </span>:= interpreterProxy positive32BitValueOf: (interpreterProxy stackValue: 1).</div>
<div> </div><div><span class="" style="white-space:pre">        </span>[array<span class="" style="white-space:pre">                </span>:= interpreterProxy stackValue: 2.</div><div><span class="" style="white-space:pre">        </span> file<span class="" style="white-space:pre">                        </span>:= self fileValueOf: (interpreterProxy stackValue: 3).</div>
<div><br></div><div><span class="" style="white-space:pre">        </span> (interpreterProxy failed</div><div><span class="" style="white-space:pre">        </span> "buffer can be any indexable words or bytes object except CompiledMethod"</div>
<div><span class="" style="white-space:pre">        </span> or: [(interpreterProxy isWordsOrBytes: array) not]) ifTrue:</div><div><span class="" style="white-space:pre">                </span>[^interpreterProxy primitiveFailFor: PrimErrBadArgument].</div>
<div><br></div><div><span class="" style="white-space:pre">        </span> elementSize := (interpreterProxy isWords: array) ifTrue: [4] ifFalse: [1].</div><div><span class="" style="white-space:pre">        </span> (startIndex >= 1</div>
<div><span class="" style="white-space:pre">        </span> and: [(startIndex + count - 1) <= (interpreterProxy slotSizeOf: array)]) ifFalse:</div><div><span class="" style="white-space:pre">                </span>[^interpreterProxy primitiveFailFor: PrimErrBadIndex].</div>
<div><br></div><div><span class="" style="white-space:pre">        </span> "Note: adjust startIndex for zero-origin indexing"</div><div><span class="" style="white-space:pre">        </span> bytesRead := self</div><div><span class="" style="white-space:pre">                                        </span>sqFile: file</div>
<div><span class="" style="white-space:pre">                                        </span>Read: count * elementSize</div><div><span class="" style="white-space:pre">                                        </span>Into: (self cCoerce: (interpreterProxy firstIndexableField: array) to: #'char *')</div>
<div><span class="" style="white-space:pre">                                        </span>At: (startIndex - 1) * elementSize.</div><div><span class="" style="white-space:pre">        </span> <b>interpreterProxy primitiveFailureCode = PrimErrObjectMayMove</b></div>
<div><b><span class="" style="white-space:pre">        </span> and: [(retryCount := retryCount + 1) <= 2] "Two objects, the file and the array can move"</b>] whileTrue:</div><div><span class="" style="white-space:pre">                </span>[interpreterProxy</div>
<div><span class="" style="white-space:pre">                        </span>tenuringIncrementalGC;</div><div><span class="" style="white-space:pre">                        </span>primitiveFailFor: PrimNoErr].</div><div><span class="" style="white-space:pre">        </span>interpreterProxy failed ifFalse:</div>
<div><span class="" style="white-space:pre">                </span>[interpreterProxy</div><div><span class="" style="white-space:pre">                        </span>pop: 5 "pop rcvr, file, array, startIndex, count"</div><div><span class="" style="white-space:pre">                        </span>thenPush:(interpreterProxy integerObjectOf: bytesRead // elementSize) "push # of elements read"]</div>
</div>