summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Program.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2018-06-12 17:43:52 +0000
committerZachary Turner <zturner@google.com>2018-06-12 17:43:52 +0000
commit08426e1f9f76f137d6958a450b1b5febed9b2ff2 (patch)
tree03d4c0c327b4cd0f00bd250af505ad1d53a0b79f /llvm/lib/Support/Program.cpp
parent70a9e47f530089261061d5bb3192f43aad28250a (diff)
downloadbcm5719-llvm-08426e1f9f76f137d6958a450b1b5febed9b2ff2.tar.gz
bcm5719-llvm-08426e1f9f76f137d6958a450b1b5febed9b2ff2.zip
Refactor ExecuteAndWait to take StringRefs.
This simplifies some code which had StringRefs to begin with, and makes other code more complicated which had const char* to begin with. In the end, I think this makes for a more idiomatic and platform agnostic API. Not all platforms launch process with null terminated c-string arrays for the environment pointer and argv, but the api was designed that way because it allowed easy pass-through for posix-based platforms. There's a little additional overhead now since on posix based platforms we'll be takign StringRefs which were constructed from null terminated strings and then copying them to null terminate them again, but from a readability and usability standpoint of the API user, I think this API signature is strictly better. llvm-svn: 334518
Diffstat (limited to 'llvm/lib/Support/Program.cpp')
-rw-r--r--llvm/lib/Support/Program.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/llvm/lib/Support/Program.cpp b/llvm/lib/Support/Program.cpp
index 8c56fb6db2d..63cdcdaabee 100644
--- a/llvm/lib/Support/Program.cpp
+++ b/llvm/lib/Support/Program.cpp
@@ -23,17 +23,19 @@ using namespace sys;
//=== independent code.
//===----------------------------------------------------------------------===//
-static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args,
- const char **Env, ArrayRef<Optional<StringRef>> Redirects,
+static bool Execute(ProcessInfo &PI, StringRef Program,
+ ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env,
+ ArrayRef<Optional<StringRef>> Redirects,
unsigned MemoryLimit, std::string *ErrMsg);
-int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp,
+int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args,
+ Optional<ArrayRef<StringRef>> Env,
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 (Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg)) {
if (ExecutionFailed)
*ExecutionFailed = false;
ProcessInfo Result = Wait(
@@ -47,8 +49,8 @@ int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp,
return -1;
}
-ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **Args,
- const char **Envp,
+ProcessInfo sys::ExecuteNoWait(StringRef Program, ArrayRef<StringRef> Args,
+ Optional<ArrayRef<StringRef>> Env,
ArrayRef<Optional<StringRef>> Redirects,
unsigned MemoryLimit, std::string *ErrMsg,
bool *ExecutionFailed) {
@@ -56,7 +58,7 @@ ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **Args,
ProcessInfo PI;
if (ExecutionFailed)
*ExecutionFailed = false;
- if (!Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg))
+ if (!Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg))
if (ExecutionFailed)
*ExecutionFailed = true;
OpenPOWER on IntegriCloud