-
Notifications
You must be signed in to change notification settings - Fork 245
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
Remove TMPDIR and use Win API on Windows #1416
Conversation
Okay it's been a bit of a roundabout journey but I think I have now understood the original problem in gh-1206 as well as the various changes and what effect they have on different platforms and why ultimately flintlib/python-flint#43 (comment) is not yet fixed: I think I have the fix here though. The Flint CI won't run until someone approves the workflow but the CI already runs in my fork and passes: I'll try to explain but it's difficult to do this succinctly: Firstly the In Flint 2.9.0 the temporary file is created like: #if defined (__WIN32) && !defined(__CYGWIN__)
srand((int) GetCurrentProcessId());
#else
srand((int) getpid());
#endif
nchars = sprintf(qs_inf->fname, "%d", (int) rand());
strcat(qs_inf->fname + nchars, "siqs.dat");
qs_inf->siqs = fopen(qs_inf->fname, "w"); That just creates a file in the current directory with a sort of random filename. Since the 2.9.0 behaviour is not ideal gh-1201 changed that. Instead the appropriate APIs should be used for Windows/Unix to choose a unique temporary filename which will be in e.g. if (GetTempFileNameA(temp_path, "siqs", /*uUnique*/ TRUE, qs_inf->fname) == 0) Here
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettempfilenamea So (obviously?) if you do want unique filenames then you should pass I think at the time there was no CI for MSVC which is perhaps why this was only immediately noticed for MinGW. The bug here applies equally to MSVC and MinGW but reproducing it is tricky because it only manifests when calling
The problem is that two separate processes will choose the same filename. The error can manifest in two different ways:
I haven't noticed this happening but there is a third way that is much worse: the two processes overwrite each other's data leading to incorrect results from The problem with MinGW was noticed at the time (gh-1206) and an attempt was made to fix it in gh-1279. That PR changed it so that MinGW would follow the Unix codepath rather than the Windows codepath. This would cause the MinGW job to fail in a different way because the Unix codepath assumed that The problem with MSVC I guess did not manifest until CI was added in gh-1282 at which point the MSVC codepath (since MinGW was then using the Unix codepath with
In this PR I fix all of these problems by going back to gh-1201 but with two important fixes:
The latter point is needed because there is an important constraint in Windows that does not apply in Unix: a file cannot be deleted if any process holds an open file handle. This merges the MinGW and MSVC codepaths again as in gh-1201 and ensures that the recommended APIs for temporary files are used in all cases. I also removed the |
Well done! This fix will obviously go in the next alpha or beta release. |
See #1206 (comment)
I am hoping that this will expose a CI failure on MinGW because there is a MinGW bug that currently does not show up in CI.
I have not yet tested it locally with MinGW (it takes a long time to test that with the Windows machine that I have available).