summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Windows
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-08-25 22:15:06 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-08-25 22:15:06 +0000
commitf7c3a1d25652efb02e73f5fb708788678540a776 (patch)
tree5c31ba0cc08924f72fcf899a74f8d05c7985d467 /llvm/lib/Support/Windows
parent525bf650ccc50b4b574f48875ea0429ec6ed1175 (diff)
downloadbcm5719-llvm-f7c3a1d25652efb02e73f5fb708788678540a776.tar.gz
bcm5719-llvm-f7c3a1d25652efb02e73f5fb708788678540a776.zip
Refactor argument serialization logic when executing process. NFC.
This patch refactors the argument serialization logic used in the Execute function, used to launch new Windows processes. There is a critical step that joins char** arguments into a single string, building the command line used to launch the new process, and the readability of this code is improved if this part is refactored in its own helper function. Patch by Rafael Auler! llvm-svn: 216411
Diffstat (limited to 'llvm/lib/Support/Windows')
-rw-r--r--llvm/lib/Support/Windows/Program.inc30
1 files changed, 17 insertions, 13 deletions
diff --git a/llvm/lib/Support/Windows/Program.inc b/llvm/lib/Support/Windows/Program.inc
index b2f71aed0c7..74a0066de8d 100644
--- a/llvm/lib/Support/Windows/Program.inc
+++ b/llvm/lib/Support/Windows/Program.inc
@@ -166,19 +166,7 @@ static unsigned int ArgLenWithQuotes(const char *Str) {
}
-static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
- const char **envp, const StringRef **redirects,
- unsigned memoryLimit, std::string *ErrMsg) {
- if (!sys::fs::can_execute(Program)) {
- if (ErrMsg)
- *ErrMsg = "program not executable";
- return false;
- }
-
- // Windows wants a command line, not an array of args, to pass to the new
- // process. We have to concatenate them all, while quoting the args that
- // have embedded spaces (or are empty).
-
+static std::unique_ptr<char[]> flattenArgs(const char **args) {
// First, determine the length of the command line.
unsigned len = 0;
for (unsigned i = 0; args[i]; i++) {
@@ -216,6 +204,22 @@ static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
}
*p = 0;
+ return command;
+}
+
+static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
+ const char **envp, const StringRef **redirects,
+ unsigned memoryLimit, std::string *ErrMsg) {
+ if (!sys::fs::can_execute(Program)) {
+ if (ErrMsg)
+ *ErrMsg = "program not executable";
+ return false;
+ }
+
+ // Windows wants a command line, not an array of args, to pass to the new
+ // process. We have to concatenate them all, while quoting the args that
+ // have embedded spaces (or are empty).
+ std::unique_ptr<char[]> command = flattenArgs(args);
// The pointer to the environment block for the new process.
std::vector<wchar_t> EnvBlock;
OpenPOWER on IntegriCloud