-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid bgzf EOF check on modern MinGW releases. #1601
Conversation
0952899
to
ba89d9d
Compare
I think this is treating the symptom rather than the cause. The MinGW-w64 I think the full solution might be an |
Undefined doesn't mean it never worked. It just means they're free to change their mind on implementation. The official posix definition of lseek though is clear, and MinGW has attempted to implement POSIX semantics even when the underlying microsoft interface doesn't. Obviously it can't catch all scenarios though. My fix was the minimal and most simple solution to get bcftools CI working once more, so I think it's still worth doing for now. A more invasive change to htslib will inevitably mean a longer development and testing time, especially given other commitments this week. Would you consider doing both? Edit: also see samtools/bcftools#1901 (comment) last paragraph. Firstly, this worked with gcc 11 but not with 12. Upgrading gcc also upgrades all sorts of other associated stuff, so it's unclear if it's compiler or the libc which has the change, but regardless it demonstrates my comment about about mingw normally working around windows posix breakages, which is why we use it. Your alternative is also basically what I outlined too, although I hadn't thought of using |
It's not minimal though: having There's an example of the sort of static off_t fd_seek(hFILE *fpv, off_t offset, int whence)
{
hFILE_fd *fp = (hFILE_fd *) fpv;
+#ifdef _WIN32
+ if (GetFileType((HANDLE)_get_osfhandle(fp->fd)) == FILE_TYPE_PIPE) { errno = ESPIPE; return -1; }
+#endif
return lseek(fp->fd, offset, whence);
} That's equivalent to Rob's suggestion, except on Windows it does the check on every seek instead of doing it just once on Windows when opening the file and recording the answer. |
Yes, that would be a simpler fix albeit less efficient as the check really only needs to be done once. I'd prefer to look for I don't think MinGW has ever claimed to implement POSIX semantics. It's I expect |
I meant minimal in code. Obviously it had the side effect of not checking, but that was the whole point - the check no longer works due to mingw changes. I wasn't aware of how to do this using windows native API, but that code snippet shows the way. Thanks. |
The irony of this statement is, those lines of code were written by myself! Haha. Apparently I once did know how to do this, or managed somewhat better on search terms in google and/or stackoverflow to set the ball rolling. :) Anyway I've confirmed it's fixing (again) my local mingw build of bcftools (glacially), so will work on getting this PR revised. |
ba89d9d
to
83a6f14
Compare
MinGW 12.x started returning non-zero values from lseek when the fd is a pipe. This is unhelpful and it breaks bgzf_check_EOF as seeking to the end is actually seeking to the end of the pipe memory buffer, causing invalid EOFs. (This breaks bcftools CI tests.) Fixes samtools/bcftools#1901 Co-authored-by: John Marshall <jmarshall@hey.com>
83a6f14
to
6efa19d
Compare
I've managed to reproduce the bug on Windows server 2019 using MinGW-w64 in both MINGW64 and UCRT64 modes, and can confirm that the revised patch fixes both. An easy way to reproduce the problem was this:
At some point we may want to look into making file access on Windows use the more native APIs. The POSIX-like ones seem to have some quirks, e.g. msvcrt Meanwhile I'll merge this so that bcftools' tests will become more reliable again. |
Unfortunately this test is proving unreliable now following a change to lseek so that it no longer returns -1 on pipes.
Fixes samtools/bcftools#1901