[Vm-dev] Possible bug in #primAtEnd: on MacOS and Linux

Juan Vuletich JuanVuletich at zoho.com
Thu Jul 7 15:44:23 UTC 2022


Hi Folks,

A Cuis user, Nicola Mingotti, in some app specific code, needed to read 
stuff from a file while some other process writes to it. This Squeak 
snippet simulates what he did, and a problem I found:

     StandardFileStream forceNewFileNamed: 'test.txt' do: [ :fs | ].
     reader := StandardFileStream fileNamed: 'test.txt'.
     Transcript cr; print: reader atEnd.
     StandardFileStream fileNamed: 'test.txt' do: [ :fs | fs nextPutAll: 
'stuff'].
     Transcript cr; print: reader atEnd.
     reader close.
     Transcript cr; flush

This is the equivalent code for Cuis.

     path := 'test.txt'.
     path asFileEntry fileContents: ''.
     fs := path asFileEntry readStream .
     fs atEnd print.
     path asFileEntry appendContents: 'stuff'.
     fs atEnd print.
     nil

Evaluating any of these, in Windows I get printed 'true' then 'false', 
the correct answer.

But on Ubuntu and MacOS, I get 'true' then 'true'.

If I modify #atEnd not to call #primAtEnd:

atEnd
     "Answer whether the receiver is at its end."
     collection ifNotNil: [
         position < readLimit ifTrue: [ ^false ] ].
     "^self primAtEnd: fileID"
     ^self position = self size

I get the correct answer in all three platforms.

This is a bug in the primitive, right?

Thanks,

-- 
Juan Vuletich
www.cuis-smalltalk.org
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
https://github.com/jvuletich
https://www.linkedin.com/in/juan-vuletich-75611b3
https://independent.academia.edu/JuanVuletich
https://www.researchgate.net/profile/Juan-Vuletich
https://patents.justia.com/inventor/juan-manuel-vuletich
https://twitter.com/JuanVuletich



More information about the Vm-dev mailing list