diff options
author | Alexander Kornienko <alexfh@google.com> | 2017-09-13 17:03:37 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2017-09-13 17:03:37 +0000 |
commit | 208eecd57fd7f2b2072f70f8fe81f1f5dd68267a (patch) | |
tree | 54617190d336acb1f3cc7764bb91d9b785abfd25 /llvm/lib/Support/Unix/Program.inc | |
parent | f6c74c472d00467e9007dfffb26278ec053957aa (diff) | |
download | llvm-208eecd57fd7f2b2072f70f8fe81f1f5dd68267a.zip llvm-208eecd57fd7f2b2072f70f8fe81f1f5dd68267a.tar.gz llvm-208eecd57fd7f2b2072f70f8fe81f1f5dd68267a.tar.bz2 |
Convenience/safety fix for llvm::sys::Execute(And|No)Wait
Summary:
Change the type of the Redirects parameter of llvm::sys::ExecuteAndWait,
ExecuteNoWait and other APIs that wrap them from `const StringRef **` to
`ArrayRef<Optional<StringRef>>`, which is safer and simplifies the use of these
APIs (no more local StringRef variables just to get a pointer to).
Corresponding clang changes will be posted as a separate patch.
Reviewers: bkramer
Reviewed By: bkramer
Subscribers: vsk, llvm-commits
Differential Revision: https://reviews.llvm.org/D37563
llvm-svn: 313155
Diffstat (limited to 'llvm/lib/Support/Unix/Program.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Program.inc | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/Support/Unix/Program.inc b/llvm/lib/Support/Unix/Program.inc index db7f16a..4f79199 100644 --- a/llvm/lib/Support/Unix/Program.inc +++ b/llvm/lib/Support/Unix/Program.inc @@ -93,7 +93,7 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, return errc::no_such_file_or_directory; } -static bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) { +static bool RedirectIO(Optional<StringRef> Path, int FD, std::string* ErrMsg) { if (!Path) // Noop return false; std::string File; @@ -165,7 +165,7 @@ static void SetMemoryLimits(unsigned size) { } static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, - const char **Envp, const StringRef **Redirects, + const char **Envp, ArrayRef<Optional<StringRef>> Redirects, unsigned MemoryLimit, std::string *ErrMsg) { if (!llvm::sys::fs::exists(Program)) { if (ErrMsg) @@ -186,7 +186,8 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, // so we copy any StringRefs into this variable. std::string RedirectsStorage[3]; - if (Redirects) { + if (!Redirects.empty()) { + assert(Redirects.size() == 3); std::string *RedirectsStr[3] = {nullptr, nullptr, nullptr}; for (int I = 0; I < 3; ++I) { if (Redirects[I]) { @@ -202,8 +203,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, if (RedirectIO_PS(RedirectsStr[0], 0, ErrMsg, FileActions) || RedirectIO_PS(RedirectsStr[1], 1, ErrMsg, FileActions)) return false; - if (Redirects[1] == nullptr || Redirects[2] == nullptr || - *Redirects[1] != *Redirects[2]) { + if (!Redirects[1] || !Redirects[2] || *Redirects[1] != *Redirects[2]) { // Just redirect stderr if (RedirectIO_PS(RedirectsStr[2], 2, ErrMsg, FileActions)) return false; @@ -253,7 +253,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, // Child process: Execute the program. case 0: { // Redirect file descriptors... - if (Redirects) { + if (!Redirects.empty()) { // Redirect stdin if (RedirectIO(Redirects[0], 0, ErrMsg)) { return false; } // Redirect stdout |