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/Windows | |
parent | f6c74c472d00467e9007dfffb26278ec053957aa (diff) | |
download | bcm5719-llvm-208eecd57fd7f2b2072f70f8fe81f1f5dd68267a.tar.gz bcm5719-llvm-208eecd57fd7f2b2072f70f8fe81f1f5dd68267a.zip |
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/Windows')
-rw-r--r-- | llvm/lib/Support/Windows/Program.inc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc index f9000d2d741..52921cd6a20 100644 --- a/llvm/lib/Support/Windows/Program.inc +++ b/llvm/lib/Support/Windows/Program.inc @@ -103,9 +103,10 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, return std::string(U8Result.begin(), U8Result.end()); } -static HANDLE RedirectIO(const StringRef *Path, int fd, std::string* ErrMsg) { +static HANDLE RedirectIO(Optional<StringRef> Path, int fd, + std::string *ErrMsg) { HANDLE h; - if (Path == 0) { + if (!Path) { if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd), GetCurrentProcess(), &h, 0, TRUE, DUPLICATE_SAME_ACCESS)) @@ -249,7 +250,7 @@ static std::unique_ptr<char[]> flattenArgs(const char **Args) { } 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 (!sys::fs::can_execute(Program)) { if (ErrMsg) @@ -299,7 +300,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args, si.hStdOutput = INVALID_HANDLE_VALUE; si.hStdError = INVALID_HANDLE_VALUE; - if (Redirects) { + if (!Redirects.empty()) { si.dwFlags = STARTF_USESTDHANDLES; si.hStdInput = RedirectIO(Redirects[0], 0, ErrMsg); |