Repository navigation
gh-159677: fix FileIO.seekable incorrectly returning false - #159678
KowalskiThomas wants to merge 4 commits into
Conversation
|
Seems like the Docs check has flaked :| |
| Py_END_ALLOW_THREADS | ||
|
|
||
| if (self->seekable < 0) { | ||
| if (self->seekable < 0 && (res >= 0 || errno == ESPIPE || posobj == NULL)) { |
There was a problem hiding this comment.
Not sure across the set of OS + kernel + version which Python runs on this is correct... Can work on evaluating that thoroughly but my leaning would be just making it so specific returns we know about that indicate "bad argument" pass through.
For instance EBADF should probably still mark seekable as False / I could see code relying on that. Something like: EINVAL, ENXIO, EOVERFLOW for Linux; EBADF and EINVAL for OpenBSD.
There was a problem hiding this comment.
The idea here was that only in the following cases we're 100% sure we know for sure what seekable should be:
res >= 0i.e. it succeedederrno == ESPIPEi.e. Illegal seekposobj == NULLi.e.offset == 0in which case a failure would indicate a seek forSEEK_CUR/SEEK_ENDfailed (so the problem is the file itself) => it's OK to cache the result of seeking directly
If we don't set the cache, "someone else" hopefully will later, but at least we're sure we never store a false value here.
Does that sound reasonable?
There was a problem hiding this comment.
(Thinking, will get back later this week)
There was a problem hiding this comment.
I'm not comfortable inverting this logic.
That ESPIPE and EBADFD "coalesce" into "seeking isn't supported" I could see code relying on. I'm okay with making more specific errors not mark "seekable false" (EINVAL, EOVERFLOW) but not moving across all the platforms for anything other than ESPIPE. Too much risk of breaking something (Python runs a lot of places and has for a long time)
There was a problem hiding this comment.
Okay, that makes sense to me, let's not break anything that relies on this behaviour today.
What I ended up doing (from the proposals of your two comments) is skip caching only for codes EINVAL/EOVERFLOW/ENXIO.
ching logic
FileIO.seekable incorrectly returning falseFileIO.seekable incorrectly returning false
FileIO.seekable incorrectly returning falseFileIO.seekable incorrectly returning false
Fixes gh-159677.