[llvm] e7b40c5 - [llvm] [unittest] Allow getting a C string from the TempDir helper class
Sergej Jaskiewicz via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 15:53:33 PDT 2020
Author: Sergej Jaskiewicz
Date: 2020-09-09T01:53:15+03:00
New Revision: e7b40c5492e5c4b182df421892136d2ee6868124
URL: https://github.com/llvm/llvm-project/commit/e7b40c5492e5c4b182df421892136d2ee6868124
DIFF: https://github.com/llvm/llvm-project/commit/e7b40c5492e5c4b182df421892136d2ee6868124.diff
LOG: [llvm] [unittest] Allow getting a C string from the TempDir helper class
The TempDir.path() member function returns a StringRef. We've been
calling the data() method on that StringRef, which does not guarantee
to return a null-terminated string (required by chdir and other POSIX
functions).
Introduce the c_str() method in the TempDir class, which returns the
proper string without the need to create a copy of the path at use site.
Added:
Modified:
llvm/include/llvm/Testing/Support/SupportHelpers.h
llvm/unittests/Support/LockFileManagerTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Testing/Support/SupportHelpers.h b/llvm/include/llvm/Testing/Support/SupportHelpers.h
index 3517361041b9..2419fc95d817 100644
--- a/llvm/include/llvm/Testing/Support/SupportHelpers.h
+++ b/llvm/include/llvm/Testing/Support/SupportHelpers.h
@@ -152,6 +152,9 @@ class TempDir {
/// The path to the temporary directory.
StringRef path() const { return Path; }
+ /// The null-terminated C string pointing to the path.
+ const char *c_str() { return Path.c_str(); }
+
/// Creates a new path by appending the argument to the path of the managed
/// directory using the native path separator.
SmallString<128> path(StringRef component) const {
diff --git a/llvm/unittests/Support/LockFileManagerTest.cpp b/llvm/unittests/Support/LockFileManagerTest.cpp
index 587e442be196..0b5a0d982a8f 100644
--- a/llvm/unittests/Support/LockFileManagerTest.cpp
+++ b/llvm/unittests/Support/LockFileManagerTest.cpp
@@ -81,7 +81,7 @@ TEST(LockFileManagerTest, RelativePath) {
char PathBuf[1024];
const char *OrigPath = getcwd(PathBuf, 1024);
- ASSERT_FALSE(chdir(LockFileManagerTestDir.path().data()));
+ ASSERT_FALSE(chdir(LockFileManagerTestDir.c_str()));
TempDir inner("inner");
SmallString<64> LockedFile(inner.path());
More information about the llvm-commits
mailing list