[llvm] r311174 - [Support] env vars with empty values on windows
Ben Dunbobbin via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 18 09:55:44 PDT 2017
Author: bd1976llvm
Date: Fri Aug 18 09:55:44 2017
New Revision: 311174
URL: http://llvm.org/viewvc/llvm-project?rev=311174&view=rev
Log:
[Support] env vars with empty values on windows
An environment variable can be in one of three states:
1. undefined.
2. defined with a non-empty value.
3. defined but with an empty value.
The windows implementation did not support case 3
(it was not handling errors). The Linux implementation
is already correct.
Differential Revision: https://reviews.llvm.org/D36394
Modified:
llvm/trunk/lib/Support/Windows/Process.inc
llvm/trunk/unittests/Support/ProcessTest.cpp
Modified: llvm/trunk/lib/Support/Windows/Process.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Process.inc?rev=311174&r1=311173&r2=311174&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Process.inc (original)
+++ llvm/trunk/lib/Support/Windows/Process.inc Fri Aug 18 09:55:44 2017
@@ -129,9 +129,10 @@ Optional<std::string> Process::GetEnv(St
size_t Size = MAX_PATH;
do {
Buf.reserve(Size);
+ SetLastError(NO_ERROR);
Size =
- GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.capacity());
- if (Size == 0)
+ GetEnvironmentVariableW(NameUTF16.data(), Buf.data(), Buf.capacity());
+ if (Size == 0 && GetLastError() == ERROR_ENVVAR_NOT_FOUND)
return None;
// Try again with larger buffer.
Modified: llvm/trunk/unittests/Support/ProcessTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/ProcessTest.cpp?rev=311174&r1=311173&r2=311174&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/ProcessTest.cpp (original)
+++ llvm/trunk/unittests/Support/ProcessTest.cpp Fri Aug 18 09:55:44 2017
@@ -42,10 +42,18 @@ TEST(ProcessTest, None) {
Optional<std::string> val(
Process::GetEnv("__LLVM_TEST_ENVIRON_NO_SUCH_VAR__"));
EXPECT_FALSE(val.hasValue());
-}
+}
#endif
#ifdef LLVM_ON_WIN32
+
+TEST(ProcessTest, EmptyVal) {
+ SetEnvironmentVariableA("__LLVM_TEST_ENVIRON_VAR__", "");
+ Optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
+ EXPECT_TRUE(val.hasValue());
+ EXPECT_STREQ("", val->c_str());
+}
+
TEST(ProcessTest, Wchar) {
SetEnvironmentVariableW(L"__LLVM_TEST_ENVIRON_VAR__", L"abcdefghijklmnopqrs");
Optional<std::string> val(Process::GetEnv("__LLVM_TEST_ENVIRON_VAR__"));
More information about the llvm-commits
mailing list