[OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
32 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
 

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/


You can view, comment on, or merge this pull request online at:

  https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232

Commit Summary

  • FilePlugin>>primitiveFileAtEnd for non-regular files

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"DESCRIPTION","message":"FilePlugin\u003e\u003eprimitiveFileAtEnd for non-regular files (#232)"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
 

The discussion on vm-dev shows that this tries to solve a problem which rather is at image side in latest Pharo.
See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027341.html
and that we should aim at simplifying the implementation rather than complexifying
See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027343.html

About the simplification, wasn't there another effort to remove the cached file size?
And excuse the naive question, but why feof() would not work for all cases?


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice in #232: The discussion on vm-dev shows that this tries to solve a problem which rather is at image side in latest Pharo.\r\nSee http://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027341.html\r\nand that we should aim at simplifying the implementation rather than complexifying\r\nSee http://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027343.html\r\n\r\nAbout the simplification, wasn't there another effort to remove the cached file size?\r\nAnd excuse the naive question, but why feof() would not work for all cases?\r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377703216"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Hi Nicolas,

There are actually 3 or 4 issues (depending on what you want to include at the moment):

  1. ZnBufferedReadStream was doing the wrong thing (the image side issue you mentioned).
    That has been fixed.

  2. #atEnd returns the wrong information for non-regular files on Unix.
    That's what this PR will fix.
    http://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027342.html demonstrates the issue.

  3. Stdio streams are treated as a special case on Unix.
    Now that we can open streams by file descriptor we're almost at the point where we can remove special handling for stdio streams on Unix. I haven't gone through all the code to be sure though. That would obviously simplify things.

  4. Stdio streams are treated as a special case on Windows.
    I haven't looked at this at all.

And excuse the naive question, but why feof() would not work for all cases?

It might, but currently there are tests in the Pharo automated test suite which explicitly check that #atEnd returns true when the stream has returned the last character (but not past it). I don't know how important these tests are.

Cheers,
Alistair


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #232: Hi Nicolas,\r\n\r\nThere are actually 3 or 4 issues (depending on what you want to include at the moment):\r\n\r\n1. ZnBufferedReadStream was doing the wrong thing (the image side issue you mentioned).\r\nThat has been fixed.\r\n\r\n2. #atEnd returns the wrong information for non-regular files on Unix.\r\nThat's what this PR will fix.\r\nhttp://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027342.html demonstrates the issue.\r\n\r\n3. Stdio streams are treated as a special case on Unix.\r\nNow that we can open streams by file descriptor we're almost at the point where we can remove special handling for stdio streams on Unix. I haven't gone through all the code to be sure though. That would obviously simplify things.\r\n\r\n4. Stdio streams are treated as a special case on Windows.\r\nI haven't looked at this at all.\r\n\r\n\u003e And excuse the naive question, but why feof() would not work for all cases?\r\n\r\nIt might, but currently there are tests in the Pharo automated test suite which explicitly check that #atEnd returns true when the stream has returned the last character (but not past it). I don't know how important these tests are.\r\n\r\nCheers,\r\nAlistair\r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377704874"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T. Lewis
In reply to this post by David T Lewis
 
On Sat, Mar 31, 2018 at 09:01:49AM -0700, Nicolas Cellier wrote:
>  
> The discussion on vm-dev shows that this tries to solve a problem which rather is at image side in latest Pharo.
> See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027341.html
> and that we should aim at simplifying the implementation rather than complexifying
> See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-March/027343.html
>
> About the simplification, wasn't there another effort to remove the cached file size?
> And excuse the naive question, but why feof() would not work for all cases?
>

It is not naive, and it is definitely not obvious.

The answer I would give is that the feof() test has a different meaning from
"at end of file". The feof() test determines if an end of file flag was set
in some previous operation. If the flag is set, then you know that you are
at the end of file. But if it is not set, you could still be at the end of
file position, in which case the end of file flag will be set the next time
you attempt to do a read.

Thus if we want atEnd to mean "at the end now, and the next read will produce
an error", then the feof() cannot answer that.

Dave

Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 
Hi Both,
thanks for the feof() explanation, I should have known this.
So, it shows that we are not on the right track.
The right way to do it on Unix is to try to read and check if atEnd in
post-condition rather than trying to test atEnd in pre-condition.
This is exactly as suggested by Levente.
Or even better, get some end-of-file error condition directly in response
to read primitive, and handle that gracefully at image side.

IMO primitiveFileAtEnd should rather be deprecated.


2018-03-31 18:35 GMT+02:00 OpenSmalltalk-Bot <[hidden email]>:

> On Sat, Mar 31, 2018 at 09:01:49AM -0700, Nicolas Cellier wrote:
> >
> > The discussion on vm-dev shows that this tries to solve a problem which
> rather is at image side in latest Pharo.
> > See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-
> March/027341.html
> > and that we should aim at simplifying the implementation rather than
> complexifying
> > See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-
> March/027343.html
> >
> > About the simplification, wasn't there another effort to remove the
> cached file size?
> > And excuse the naive question, but why feof() would not work for all
> cases?
> >
>
> It is not naive, and it is definitely not obvious.
>
> The answer I would give is that the feof() test has a different meaning
> from
> "at end of file". The feof() test determines if an end of file flag was set
> in some previous operation. If the flag is set, then you know that you are
> at the end of file. But if it is not set, you could still be at the end of
> file position, in which case the end of file flag will be set the next time
> you attempt to do a read.
>
> Thus if we want atEnd to mean "at the end now, and the next read will
> produce
> an error", then the feof() cannot answer that.
>
> Dave
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377705650>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAscIrim1_6lcCunTBfwxNA7jtNToY5Kks5tj7BugaJpZM4S6rMa>
> .
>


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice in #232: Hi Both,\nthanks for the feof() explanation, I should have known this.\nSo, it shows that we are not on the right track.\nThe right way to do it on Unix is to try to read and check if atEnd in\npost-condition rather than trying to test atEnd in pre-condition.\nThis is exactly as suggested by Levente.\nOr even better, get some end-of-file error condition directly in response\nto read primitive, and handle that gracefully at image side.\n\nIMO primitiveFileAtEnd should rather be deprecated.\n\n\n2018-03-31 18:35 GMT+02:00 OpenSmalltalk-Bot \u003cnotifications@github.com\u003e:\n\n\u003e On Sat, Mar 31, 2018 at 09:01:49AM -0700, Nicolas Cellier wrote:\n\u003e \u003e\n\u003e \u003e The discussion on vm-dev shows that this tries to solve a problem which\n\u003e rather is at image side in latest Pharo.\n\u003e \u003e See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-\n\u003e March/027341.html\n\u003e \u003e and that we should aim at simplifying the implementation rather than\n\u003e complexifying\n\u003e \u003e See http://lists.squeakfoundation.org/pipermail/vm-dev/2018-\n\u003e March/027343.html\n\u003e \u003e\n\u003e \u003e About the simplification, wasn't there another effort to remove the\n\u003e cached file size?\n\u003e \u003e And excuse the naive question, but why feof() would not work for all\n\u003e cases?\n\u003e \u003e\n\u003e\n\u003e It is not naive, and it is definitely not obvious.\n\u003e\n\u003e The answer I would give is that the feof() test has a different meaning\n\u003e from\n\u003e \"at end of file\". The feof() test determines if an end of file flag was set\n\u003e in some previous operation. If the flag is set, then you know that you are\n\u003e at the end of file. But if it is not set, you could still be at the end of\n\u003e file position, in which case the end of file flag will be set the next time\n\u003e you attempt to do a read.\n\u003e\n\u003e Thus if we want atEnd to mean \"at the end now, and the next read will\n\u003e produce\n\u003e an error\", then the feof() cannot answer that.\n\u003e\n\u003e Dave\n\u003e\n\u003e —\n\u003e You are receiving this because you commented.\n\u003e Reply to this email directly, view it on GitHub\n\u003e \u003chttps://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377705650\u003e,\n\u003e or mute the thread\n\u003e \u003chttps://github.com/notifications/unsubscribe-auth/AAscIrim1_6lcCunTBfwxNA7jtNToY5Kks5tj7BugaJpZM4S6rMa\u003e\n\u003e .\n\u003e\n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377793153"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

For example in Squeak, we can rewrite atEnd like this:

StandardFileStream>>atEnd
"Answer whether the receiver is at its end. "
collection ifNotNil: [ position < readLimit ifTrue: [ ^false ] ].
self basicNext ifNil: [ ^true ].
self skip: -1.
^false

then entirely remove primAtEnd: which has no more sender.
I presume it should be more or less equivalent in Pharo.
Then tell about limitation and deprecation in primitiveFileAtEnd comment.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice in #232: For example in Squeak, we can rewrite atEnd like this:\r\n\r\n StandardFileStream\u003e\u003eatEnd\r\n\t\"Answer whether the receiver is at its end. \"\r\n\tcollection ifNotNil: [ position \u003c readLimit ifTrue: [ ^false ] ].\r\n\tself basicNext ifNil: [ ^true ].\r\n\tself skip: -1.\r\n\t^false\r\n\r\nthen entirely remove `primAtEnd:` which has no more sender.\r\nI presume it should be more or less equivalent in Pharo.\r\nThen tell about limitation and deprecation in `primitiveFileAtEnd` comment."}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377794428"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Hi Nicolas,

So, it shows that we are not on the right track.
The right way to do it on Unix is to try to read and check if atEnd in
post-condition rather than trying to test atEnd in pre-condition.

But that is exactly what this PR is about - it provides the ability for a post-condition check to be performed.

This is exactly as suggested by Levente.
Or even better, get some end-of-file error condition directly in response
to read primitive, and handle that gracefully at image side.

The correct usage, as you say above, is to read until there is no more data, and then check to see if the end of file has been reached. Without this (modified) primitive there's no way to perform that check.

We could change the image to handle no-more-data and end-of-file differently, but it would still require the check to be made, and I wouldn't combine the read and eof checks in to one primitive.

IMO primitiveFileAtEnd should rather be deprecated.

Based on my understanding, I disagree. Please let me know if I'm missing something.

Cheers,
Alistair


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #232: Hi Nicolas,\r\n\r\n\u003e So, it shows that we are not on the right track.\r\n\u003e The right way to do it on Unix is to try to read and check if atEnd in\r\n\u003e post-condition rather than trying to test atEnd in pre-condition.\r\n\r\nBut that is exactly what this PR is about - it provides the ability for a post-condition check to be performed.\r\n\r\n\u003e This is exactly as suggested by Levente.\r\n\u003e Or even better, get some end-of-file error condition directly in response\r\n\u003e to read primitive, and handle that gracefully at image side.\r\n\r\nThe correct usage, as you say above, is to read until there is no more data, and then check to see if the end of file has been reached. Without this (modified) primitive there's no way to perform that check.\r\n\r\nWe could change the image to handle no-more-data and end-of-file differently, but it would still require the check to be made, and I wouldn't combine the read and eof checks in to one primitive.\r\n\r\n\u003e IMO primitiveFileAtEnd should rather be deprecated.\r\n\r\nBased on my understanding, I disagree. Please let me know if I'm missing something.\r\n\r\nCheers,\r\nAlistair\r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377794834"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

For example in Squeak, we can rewrite atEnd like this:
...

I think this will return incorrect results. No-more-data is not the same is end-of-file. No-more-data just says that there isn't any data available now, but that may change.

Don't forget we are talking about non-regular files, e.g. /dev/urandom, that isn't a real stream, it is calculated and may be waiting on external resources.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #232: \u003e For example in Squeak, we can rewrite atEnd like this:\r\n\u003e ...\r\n\r\nI think this will return incorrect results. No-more-data is not the same is end-of-file. No-more-data just says that there isn't any data available now, but that may change.\r\n\r\nDon't forget we are talking about non-regular files, e.g. /dev/urandom, that isn't a real stream, it is calculated and may be waiting on external resources."}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377795132"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

I'll never learn to not reply when I'm in a hurry...

Don't forget we are talking about non-regular files, e.g. /dev/urandom, that isn't a real stream,
it is calculated and may be waiting on external resources.

It is, of course, a real stream. Just not a regular file.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #232: I'll never learn to not reply when I'm in a hurry...\r\n\r\n\u003e Don't forget we are talking about non-regular files, e.g. /dev/urandom, that isn't a real stream, \r\n\u003e it is calculated and may be waiting on external resources.\r\n\r\nIt is, of course, a real stream. Just not a regular file."}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377801495"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Hi Alistair,
OK, I see your point, my proposal would work for /dev/random but maybe not all possible kind of stream
But then primitiveFileAtEnd is trying to be too smart:

  • being able to test atEnd in pre-condition for regular files

  • being able to test atEnd in post-condition for the rest of the world (pipe socket special devices etc...).
    It's kind of brainfuck. I say we should simplify and keep only one, post-condition with a simple feof and leave smartness at image side.
    What if we add

    primitiveEncounteredEndOfFile
    "Answer true if the end of file was encountered at last read operation".

And leave current primitive only for backward compatibility with deprecation warning in the comment?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice in #232: Hi Alistair,\r\nOK, I see your point, my proposal would work for /dev/random but maybe not all possible kind of stream\r\nBut then primitiveFileAtEnd is trying to be too smart:\r\n- being able to test atEnd in pre-condition for regular files\r\n- being able to test atEnd in post-condition for the rest of the world (pipe socket special devices etc...).\r\nIt's kind of brainfuck. I say we should simplify and keep only one, post-condition with a simple feof and leave smartness at image side.\r\nWhat if we add\r\n\r\n primitiveEncounteredEndOfFile\r\n \"Answer true if the end of file was encountered at last read operation\".\r\n\r\nAnd leave current primitive only for backward compatibility with deprecation warning in the comment?\r\n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377810556"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T. Lewis
 
On Sun, Apr 01, 2018 at 12:26:56PM -0700, Nicolas Cellier wrote:

>  
> Hi Alistair,
> OK, I see your point, my proposal would work for /dev/random but maybe not all possible kind of stream
> But then primitiveFileAtEnd is trying to be too smart:
> - being able to test atEnd in pre-condition for regular files
> - being able to test atEnd in post-condition for the rest of the world (pipe socket special devices etc...).
> It's kind of brainfuck. I say we should simplify and keep only one, post-condition with a simple feof and leave smartness at image side.
> What if we add
>
>     primitiveEncounteredEndOfFile
>         "Answer true if the end of file was encountered at last read operation".
>
> And leave current primitive only for backward compatibility with deprecation warning in the comment?
>

As a point of reference, in OSProcess it is implemented as StandardFileStream>>atEndOfFile
as an extension in *OSProcess-Base, as distinct from StandardFileStream>>atEnd. The EOF
test is done in the OSProcessPlugin (not FilePlugin), and is implemented as #primitiveTestEndOfFileFlag.

The most important use case is for a file stream on an OS pipe (e.g. OSPipe new reader).

Similar to /dev/random, the stream on an OS pipe is represented as a kind of
PositionableStream, but it is a positionable stream that does not know its
position, and for which the position is not settable.

I do not know of a perfect solution to this, but if you want to experiment on
the image side with the different semantics of "at end now" versus "last operation
hit the EOF condition so do not bother asking for more" then the primitiveTestEndOfFileFlag
that is present in any VM with the UnixOSProcessPlugin will probably give you
what is needed to try out some new ideas.

Dave
 
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Hi David, I will have a look.
We still have ungetc to just skip: -1 even on a pipe, as long as called only once.
This could be used to test atEndNow in precondition, Am I wrong?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice in #232: Hi David, I will have a look.\r\nWe still have ungetc to just skip: -1 even on a pipe, as long as called only once.\r\nThis could be used to test atEndNow in precondition, Am I wrong?"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-377820660"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Hi Nicolas and Dave,

We still have ungetc to just skip: -1 even on a pipe, as long as called only once.
This could be used to test atEndNow in precondition, Am I wrong?

You're correct (as I understand it). I think it is more a matter of
what do we want to try and move to in the long term.

Right now the behaviour of #atEnd is:

  • True after moving past the end for stdio files
  • True when at the end for regular (disk) files
  • Broken for non-regular files

So we already have both behaviours.

My natural inclination is to minimise the primitive code and let the
image handle it. In this case, that means keeping the feof() behaviour
and eventually changing the definition for regular files.

The primitive should also be checking ferror(), so should be
something like (untested):

sqInt
sqFileAtEnd(SQFile f) {
sqInt status;
/
Return true if the file's read/write head is at the end of the file. */

if (!sqFileValid(f))
	return interpreterProxy->success(false);
pentry(sqFileAtEnd);
/* Regular files test based on current position vs size,
 * all other files use feof() */
if (f->isStdioStream || !S_ISREG(f->st_mode))
	status = feof(getFile(f))
else
	status = ftell(getFile(f)) >= getSize(f);
if (ferror(getFile(f)))
	primitiveFailForOSError(errno);
return pexit(status);

}

Cheers,
Alistair


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #232: Hi Nicolas and Dave,\r\n\r\n\u003e We still have ungetc to just skip: -1 even on a pipe, as long as called only once.\r\n\u003e This could be used to test atEndNow in precondition, Am I wrong?\r\n\r\nYou're correct (as I understand it). I think it is more a matter of\r\nwhat do we want to try and move to in the long term.\r\n\r\nRight now the behaviour of #atEnd is:\r\n\r\n- True after moving past the end for stdio files\r\n- True when at the end for regular (disk) files\r\n- Broken for non-regular files\r\n\r\nSo we already have both behaviours.\r\n\r\nMy natural inclination is to minimise the primitive code and let the\r\nimage handle it. In this case, that means keeping the feof() behaviour\r\nand eventually changing the definition for regular files.\r\n\r\nThe primitive should also be checking ferror(), so should be\r\nsomething like (untested):\r\n\r\n\r\nsqInt\r\nsqFileAtEnd(SQFile *f) {\r\n\tsqInt status;\r\n\t/* Return true if the file's read/write head is at the end of the file. */\r\n\r\n\tif (!sqFileValid(f))\r\n\t\treturn interpreterProxy-\u003esuccess(false);\r\n\tpentry(sqFileAtEnd);\r\n\t/* Regular files test based on current position vs size,\r\n\t * all other files use feof() */\r\n\tif (f-\u003eisStdioStream || !S_ISREG(f-\u003est_mode))\r\n\t\tstatus = feof(getFile(f))\r\n\telse\r\n\t\tstatus = ftell(getFile(f)) \u003e= getSize(f);\r\n\tif (ferror(getFile(f)))\r\n\t\tprimitiveFailForOSError(errno);\r\n\treturn pexit(status);\r\n}\r\n\r\nCheers,\r\nAlistair"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-378168866"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Alistair, you are perfectly right.
The dual pre/post condition did already exist, and you are proposing an improvement.
My only concern was about complexifying a piece that we will keep forever for compatibility reasons, while we may better maje deeper changes at the image side.
But 'the best is the enemy of the good', if you think that this change is vital for Pharo, i have no further objection.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice in #232: Alistair, you are perfectly right.\r\nThe dual pre/post condition did already exist, and you are proposing an improvement.\r\nMy only concern was about complexifying a piece that we will keep forever for compatibility reasons, while we may better maje deeper changes at the image side.\r\nBut 'the best is the enemy of the good', if you think that this change is vital for Pharo, i have no further objection."}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-378183604"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Hi Nicolas,

Thanks. I agree that this isn't simplifying the existing code, although I also think it isn't really adding complexity. It does result in an arguably correct response where before it was clearly incorrect.

Just for the record, the same incorrect behaviour currently exists in Squeak (#atEnd returns the wrong result for a non-regular file).

Cheers,
Alistair


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #232: Hi Nicolas,\r\n\r\nThanks. I agree that this isn't simplifying the existing code, although I also think it isn't really adding complexity. It does result in an arguably correct response where before it was clearly incorrect.\r\n\r\nJust for the record, the same incorrect behaviour currently exists in Squeak (#atEnd returns the wrong result for a non-regular file).\r\n\r\nCheers,\r\nAlistair"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-378215544"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 
Hi Alistair,

> On Apr 3, 2018, at 4:19 AM, akgrant43 <[hidden email]> wrote:
>
> Hi Nicolas,
>
> Thanks. I agree that this isn't simplifying the existing code, although I also think it isn't really adding complexity. It does result in an arguably correct response where before it was clearly incorrect.
>
> Just for the record, the same incorrect behaviour currently exists in Squeak (#atEnd returns the wrong result for a non-regular file).
>

Please add the gist of David's description of feof() to the code when you fix this. That's extremely important information. TIA
> Cheers,
> Alistair
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub, or mute the thread.
>


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@eliotmiranda in #232: Hi Alistair,\n\n\u003e On Apr 3, 2018, at 4:19 AM, akgrant43 \u003cnotifications@github.com\u003e wrote:\n\u003e \n\u003e Hi Nicolas,\n\u003e \n\u003e Thanks. I agree that this isn't simplifying the existing code, although I also think it isn't really adding complexity. It does result in an arguably correct response where before it was clearly incorrect.\n\u003e \n\u003e Just for the record, the same incorrect behaviour currently exists in Squeak (#atEnd returns the wrong result for a non-regular file).\n\u003e \n\nPlease add the gist of David's description of feof() to the code when you fix this. That's extremely important information. TIA\n\u003e Cheers,\n\u003e Alistair\n\u003e \n\u003e —\n\u003e You are receiving this because you are subscribed to this thread.\n\u003e Reply to this email directly, view it on GitHub, or mute the thread.\n\u003e \n"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-378252881"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

@akgrant43 pushed 1 commit.

  • 40ab0f5 21643-FilePlugin-primitiveFileAtEnd


You are receiving this because you are subscribed to this thread.
View it on GitHub or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 pushed 1 commit in #232"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232/files/c0ef4209d7db5dc017dab0efd7dbf61079a5ede4..40ab0f5982e791b05515769cb9ec379192aa15ed"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

Please add the gist of David's description of feof() to the code when you fix this. That's extremely important information. TIA

Done.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@akgrant43 in #232: \u003e Please add the gist of David's description of feof() to the code when you fix this. That's extremely important information. TIA\r\n\r\nDone."}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-378749873"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

wow, if it works, it looks good!


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice in #232: wow, if it works, it looks good!"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#issuecomment-378751460"}}}</script>
Reply | Threaded
Open this post in threaded view
|

Re: [OpenSmalltalk/opensmalltalk-vm] FilePlugin>>primitiveFileAtEnd for non-regular files (#232)

David T Lewis
In reply to this post by David T Lewis
 

@nicolas-cellier-aka-nice commented on this pull request.


In platforms/Cross/plugins/FilePlugin/FilePlugin.h:

> @@ -30,6 +31,7 @@ typedef int mode_t;
 typedef struct {
   int			 sessionID;	/* ikp: must be first */
   void			*file;
+  mode_t		st_mode;	/* from stat() */

By the way, do we still need st_mode and setMode now?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/OpenSmalltalk/opensmalltalk-vm","title":"OpenSmalltalk/opensmalltalk-vm","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm"}},"updates":{"snippets":[{"icon":"PERSON","message":"@nicolas-cellier-aka-nice commented on #232"}],"action":{"name":"View Pull Request","url":"https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/232#pullrequestreview-109509662"}}}</script>
12