[libcxx-commits] [PATCH] D122612: [libcxx] [test] Fix back-to-back use of get_temp_file_name() on Windows
Martin Storsjö via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Mar 28 14:03:28 PDT 2022
mstorsjo created this revision.
mstorsjo added a reviewer: ldionne.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.
On non-Windows platforms, get_temp_file_name() uses `mkstemp()`,
which picks a unique name and creates a file atomically. The
Windows implementation uses `_mktemp_s()`, which doesn't create the
file. The documentation of `_mktemp_s()` also says that by design,
the function uses the same pattern within a process, as long as that
file doesn't exist.
Thus previously, two consecutive calls to `get_temp_file_name()`
on Windows returned the same file name.
By creating the file (with a plain `fopen(, "w")` we mark the file
name as taken for later calls. As this isn't atomic, this could
lead to duplicates if there'd be multiple calls to
`get_temp_file_name()` in multiple threads in the same test process
in parallel, but that's probably not done in these tests.
(`_mktemp_s` does guard against clashes between parallel processes
though, so there's no risk of clashes between multiple tests
executing in paralle.)
This fixes the test failures on Windows observed in D122257 <https://reviews.llvm.org/D122257>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122612
Files:
libcxx/test/support/platform_support.h
Index: libcxx/test/support/platform_support.h
===================================================================
--- libcxx/test/support/platform_support.h
+++ libcxx/test/support/platform_support.h
@@ -55,6 +55,9 @@
#if defined(_WIN32)
char Name[] = "libcxx.XXXXXX";
if (_mktemp_s(Name, sizeof(Name)) != 0) abort();
+ FILE *File = fopen(Name, "wb");
+ if (File)
+ fclose(File);
return Name;
#else
std::string Name;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122612.418698.patch
Type: text/x-patch
Size: 452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220328/4c6feded/attachment-0001.bin>
More information about the libcxx-commits
mailing list