Branch: refs/heads/Cog Home: https://github.com/OpenSmalltalk/opensmalltalk-vm Commit: c0ef4209d7db5dc017dab0efd7dbf61079a5ede4 https://github.com/OpenSmalltalk/opensmalltalk-vm/commit/c0ef4209d7db5dc017d... Author: AlistairGrant akgrant0710@gmail.com Date: 2018-03-26 (Mon, 26 Mar 2018)
Changed paths: M platforms/Cross/plugins/FilePlugin/FilePlugin.h M platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
Log Message: ----------- FilePlugin>>primitiveFileAtEnd for non-regular files
FilePlugin currently splits files in to two groups: 1) Stdio streams and 2) everything else.
To test for the end of file, FilePlugin>>primitiveFileAtEnd:
1) Uses feof() for stdio streams. 2) Compares the current position to the file size for everything else.
This returns the expected results for regular files, but fails for non-regular files, e.g.:
(FileSystem / 'dev' / 'urandom') binaryReadStream next: 8.
returns an empty array.
On Unix, the proper way to check is to read past the end of the file and then call feof() to confirm that it is in fact at the end.
Pharo has plenty of code that assumes that a file position >= the file size means that the file is at the end, and as stated above this generally works for regular files.
This patch modifies FilePlugin>>primitiveFileAtEnd to:
a) Keep the current behaviour of using the file position test for regular files. b) Keep the current behaviour of using feof() for stdio streams. c) Use feof() for non-regular files, e.g. /dev/urandom.
This allows existing code to continue to function, and allows non-regular files to be tested correctly.
After applying the patch, the example code above answers the expected result, e.g.:
(FileSystem / 'dev' / 'urandom') binaryReadStream next: 8. " #[179 136 227 226 28 147 197 125]"
On Windows, as far as I can tell, all files are regular, and the position test is used regularly, so no change is requried.
Fogbugz: https://pharo.fogbugz.com/f/cases/21643/
Commit: 40ab0f5982e791b05515769cb9ec379192aa15ed https://github.com/OpenSmalltalk/opensmalltalk-vm/commit/40ab0f5982e791b0551... Author: AlistairGrant akgrant0710@gmail.com Date: 2018-04-04 (Wed, 04 Apr 2018)
Changed paths: M platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
Log Message: ----------- 21643-FilePlugin-primitiveFileAtEnd
Modify sqFileAtEnd() (FilePlugin>>primitiveFileAtEnd) so that #atEnd returns true when the last character has been read.
Both Squeak and Pharo expect that #atEnd can be used to control iteration over a stream, answering true as soon as the last character has been read, and importantly not requiring #next values to be tested for an end-of-stream.
Previously, stdio streams just used feof(), which requires reading past the end of the stream, and so required the value returned by #next to be tested for nil. This causes problems with streams over other collections where nil is a valid value.
sqFileAtEnd() would also fail to return the correct value for other files such as kernel virtual files, e.g. /proc/cpuinfo, and devices like /dev/urandom, because they have a reported file size of 0.
This change also takes a step towards removing the special handling of stdio files on Unix, significantly simplifying the code base.
This change doesn't break any existing code that uses #next == nil to test for end-of-stream.
Commit: bcc644b91f2aef5b6331d71298d6f746f8832433 https://github.com/OpenSmalltalk/opensmalltalk-vm/commit/bcc644b91f2aef5b633... Author: AlistairGrant akgrant0710@gmail.com Date: 2018-04-04 (Wed, 04 Apr 2018)
Changed paths: M platforms/Cross/plugins/FilePlugin/FilePlugin.h M platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
Log Message: ----------- 21643-FilePlugin-primitiveFileAtEnd
Remove references to stat.h and st_mode that were accidentally left behind.
Commit: 3421494b43af5611420ebe229b7db3af2064e539 https://github.com/OpenSmalltalk/opensmalltalk-vm/commit/3421494b43af5611420... Author: akgrant43 akgrant@gmail.com Date: 2018-04-05 (Thu, 05 Apr 2018)
Changed paths: M platforms/Cross/plugins/FilePlugin/sqFilePluginBasicPrims.c
Log Message: ----------- Merge pull request #232 from akgrant43/21643-FilePlugin-primitiveFileAtEnd
FilePlugin currently splits files in to two groups:
1) Stdio streams and 2) everything else.
To test for the end of file, FilePlugin>>primitiveFileAtEnd:
1) Uses feof() for stdio streams. 2) Compares the current position to the file size for everything else.
This returns the expected results for regular files, but fails for non-regular files, e.g.:
``` (FileSystem / 'dev' / 'urandom') binaryReadStream next: 8. '/proc/cpuinfo' asFileReference contents ```
both return empty collections.
Modify sqFileAtEnd() (FilePlugin>>primitiveFileAtEnd) so that #atEnd returns true when the last character has been read.
Both Squeak and Pharo expect that #atEnd can be used to control iteration over a stream, answering true as soon as the last character has been read, and importantly not requiring #next values to be tested for an end-of-stream.
Previously, stdio streams just used feof(), which requires reading past the end of the stream, and so required the value returned by #next to be tested for nil. This causes problems with streams over other collections where nil is a valid value.
sqFileAtEnd() would also fail to return the correct value for other files such as kernel virtual files, e.g. /proc/cpuinfo, and devices like /dev/urandom, because they have a reported file size of 0.
This change also takes a step towards removing the special handling of stdio files on Unix, significantly simplifying the code base.
This change doesn't break any existing code that uses #next == nil to test for end-of-stream.
Compare: https://github.com/OpenSmalltalk/opensmalltalk-vm/compare/0ce1378d23d0...342...
vm-dev@lists.squeakfoundation.org