From 08426e1f9f76f137d6958a450b1b5febed9b2ff2 Mon Sep 17 00:00:00 2001 From: Zachary Turner Date: Tue, 12 Jun 2018 17:43:52 +0000 Subject: 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 --- llvm/lib/Support/Program.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'llvm/lib/Support/Program.cpp') 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> Redirects, +static bool Execute(ProcessInfo &PI, StringRef Program, + ArrayRef Args, Optional> Env, + ArrayRef> Redirects, unsigned MemoryLimit, std::string *ErrMsg); -int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp, +int sys::ExecuteAndWait(StringRef Program, ArrayRef Args, + Optional> Env, ArrayRef> 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 Args, + Optional> Env, ArrayRef> 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; -- cgit v1.2.3