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
This commit is contained in:
Zachary Turner
2018-06-12 17:43:52 +00:00
parent 70a9e47f53
commit 08426e1f9f
20 changed files with 254 additions and 267 deletions

View File

@@ -61,11 +61,12 @@ TEST_F(ObjectFileELFTest, SectionsResolveConsistently) {
"sections-resolve-consistently-%%%%%%", "obj", obj));
llvm::FileRemover remover(obj);
const char *args[] = {YAML2OBJ, yaml.c_str(), nullptr};
llvm::StringRef args[] = {YAML2OBJ, yaml};
llvm::StringRef obj_ref = obj;
const llvm::Optional<llvm::StringRef> redirects[] = {llvm::None, obj_ref,
llvm::None};
ASSERT_EQ(0, llvm::sys::ExecuteAndWait(YAML2OBJ, args, nullptr, redirects));
ASSERT_EQ(0,
llvm::sys::ExecuteAndWait(YAML2OBJ, args, llvm::None, redirects));
uint64_t size;
ASSERT_NO_ERROR(llvm::sys::fs::file_size(obj, size));
ASSERT_GT(size, 0u);