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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313155 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexander Kornienko
2017-09-13 17:03:37 +00:00
parent f6e4c7d70e
commit 87e117df59
12 changed files with 60 additions and 62 deletions
+8 -5
View File
@@ -24,13 +24,14 @@ using namespace sys;
//===----------------------------------------------------------------------===//
static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args,
const char **Env, const StringRef **Redirects,
const char **Env, ArrayRef<Optional<StringRef>> Redirects,
unsigned MemoryLimit, std::string *ErrMsg);
int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp,
const StringRef **Redirects, unsigned SecondsToWait,
unsigned MemoryLimit, std::string *ErrMsg,
bool *ExecutionFailed) {
ArrayRef<Optional<StringRef>> Redirects,
unsigned SecondsToWait, unsigned MemoryLimit,
std::string *ErrMsg, bool *ExecutionFailed) {
assert(Redirects.empty() || Redirects.size() == 3);
ProcessInfo PI;
if (Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg)) {
if (ExecutionFailed)
@@ -47,9 +48,11 @@ int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp,
}
ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **Args,
const char **Envp, const StringRef **Redirects,
const char **Envp,
ArrayRef<Optional<StringRef>> Redirects,
unsigned MemoryLimit, std::string *ErrMsg,
bool *ExecutionFailed) {
assert(Redirects.empty() || Redirects.size() == 3);
ProcessInfo PI;
if (ExecutionFailed)
*ExecutionFailed = false;