mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-21 03:05:26 -04:00
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@334518 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user