[llvm] r312646 - Minor style fixes in lib/Support/**/Program.(inc|cpp).

Alexander Kornienko via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 6 09:28:33 PDT 2017


Author: alexfh
Date: Wed Sep  6 09:28:33 2017
New Revision: 312646

URL: http://llvm.org/viewvc/llvm-project?rev=312646&view=rev
Log:
Minor style fixes in lib/Support/**/Program.(inc|cpp).

No functional changes intended.

Modified:
    llvm/trunk/include/llvm/Support/Program.h
    llvm/trunk/lib/Support/Program.cpp
    llvm/trunk/lib/Support/Unix/Program.inc
    llvm/trunk/lib/Support/Windows/Program.inc

Modified: llvm/trunk/include/llvm/Support/Program.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Program.h?rev=312646&r1=312645&r2=312646&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Program.h (original)
+++ llvm/trunk/include/llvm/Support/Program.h Wed Sep  6 09:28:33 2017
@@ -91,13 +91,13 @@ struct ProcessInfo {
   int ExecuteAndWait(
       StringRef Program, ///< Path of the program to be executed. It is
       ///< presumed this is the result of the findProgramByName method.
-      const char **args, ///< A vector of strings that are passed to the
+      const char **Args, ///< A vector of strings that are passed to the
       ///< program.  The first element should be the name of the program.
       ///< The list *must* be terminated by a null char* entry.
-      const char **env = nullptr, ///< An optional vector of strings to use for
+      const char **Env = nullptr, ///< An optional vector of strings to use for
       ///< the program's environment. If not provided, the current program's
       ///< environment will be used.
-      const StringRef **redirects = nullptr, ///< An optional array of pointers
+      const StringRef **Redirects = nullptr, ///< An optional array of pointers
       ///< to paths. If the array is null, no redirection is done. The array
       ///< should have a size of at least three. The inferior process's
       ///< stdin(0), stdout(1), and stderr(2) will be redirected to the
@@ -105,12 +105,12 @@ struct ProcessInfo {
       ///< When an empty path is passed in, the corresponding file
       ///< descriptor will be disconnected (ie, /dev/null'd) in a portable
       ///< way.
-      unsigned secondsToWait = 0, ///< If non-zero, this specifies the amount
+      unsigned SecondsToWait = 0, ///< If non-zero, this specifies the amount
       ///< of time to wait for the child process to exit. If the time
       ///< expires, the child is killed and this call returns. If zero,
       ///< this function will wait until the child finishes or forever if
       ///< it doesn't.
-      unsigned memoryLimit = 0, ///< If non-zero, this specifies max. amount
+      unsigned MemoryLimit = 0, ///< If non-zero, this specifies max. amount
       ///< of memory can be allocated by process. If memory usage will be
       ///< higher limit, the child is killed and this call returns. If zero
       ///< - no memory limit.
@@ -125,14 +125,17 @@ struct ProcessInfo {
   /// \note On Microsoft Windows systems, users will need to either call \see
   /// Wait until the process finished execution or win32 CloseHandle() API on
   /// ProcessInfo.ProcessHandle to avoid memory leaks.
-  ProcessInfo
-  ExecuteNoWait(StringRef Program, const char **args, const char **env = nullptr,
-                const StringRef **redirects = nullptr, unsigned memoryLimit = 0,
-                std::string *ErrMsg = nullptr, bool *ExecutionFailed = nullptr);
+  ProcessInfo ExecuteNoWait(StringRef Program, const char **Args,
+                            const char **Env = nullptr,
+                            const StringRef **Redirects = nullptr,
+                            unsigned MemoryLimit = 0,
+                            std::string *ErrMsg = nullptr,
+                            bool *ExecutionFailed = nullptr);
 
   /// Return true if the given arguments fit within system-specific
   /// argument length limits.
-  bool commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<const char*> Args);
+  bool commandLineFitsWithinSystemLimits(StringRef Program,
+                                         ArrayRef<const char *> Args);
 
   /// File encoding options when writing contents that a non-UTF8 tool will
   /// read (on Windows systems). For UNIX, we always use UTF-8.

Modified: llvm/trunk/lib/Support/Program.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Program.cpp?rev=312646&r1=312645&r2=312646&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Program.cpp (original)
+++ llvm/trunk/lib/Support/Program.cpp Wed Sep  6 09:28:33 2017
@@ -23,20 +23,20 @@ using namespace sys;
 //===          independent code.
 //===----------------------------------------------------------------------===//
 
-static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
-                    const char **env, const StringRef **Redirects,
-                    unsigned memoryLimit, std::string *ErrMsg);
-
-int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,
-                        const StringRef **redirects, unsigned secondsToWait,
-                        unsigned memoryLimit, std::string *ErrMsg,
+static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args,
+                    const char **Env, const StringRef **Redirects,
+                    unsigned MemoryLimit, std::string *ErrMsg);
+
+int sys::ExecuteAndWait(StringRef Program, const char **Args, const char **Envp,
+                        const StringRef **Redirects, unsigned SecondsToWait,
+                        unsigned MemoryLimit, std::string *ErrMsg,
                         bool *ExecutionFailed) {
   ProcessInfo PI;
-  if (Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg)) {
+  if (Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg)) {
     if (ExecutionFailed)
       *ExecutionFailed = false;
     ProcessInfo Result = Wait(
-        PI, secondsToWait, /*WaitUntilTerminates=*/secondsToWait == 0, ErrMsg);
+        PI, SecondsToWait, /*WaitUntilTerminates=*/SecondsToWait == 0, ErrMsg);
     return Result.ReturnCode;
   }
 
@@ -46,14 +46,14 @@ int sys::ExecuteAndWait(StringRef Progra
   return -1;
 }
 
-ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **args,
-                               const char **envp, const StringRef **redirects,
-                               unsigned memoryLimit, std::string *ErrMsg,
+ProcessInfo sys::ExecuteNoWait(StringRef Program, const char **Args,
+                               const char **Envp, const StringRef **Redirects,
+                               unsigned MemoryLimit, std::string *ErrMsg,
                                bool *ExecutionFailed) {
   ProcessInfo PI;
   if (ExecutionFailed)
     *ExecutionFailed = false;
-  if (!Execute(PI, Program, args, envp, redirects, memoryLimit, ErrMsg))
+  if (!Execute(PI, Program, Args, Envp, Redirects, MemoryLimit, ErrMsg))
     if (ExecutionFailed)
       *ExecutionFailed = true;
 

Modified: llvm/trunk/lib/Support/Unix/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc?rev=312646&r1=312645&r2=312646&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Program.inc (original)
+++ llvm/trunk/lib/Support/Unix/Program.inc Wed Sep  6 09:28:33 2017
@@ -144,8 +144,7 @@ static bool RedirectIO_PS(const std::str
 static void TimeOutHandler(int Sig) {
 }
 
-static void SetMemoryLimits (unsigned size)
-{
+static void SetMemoryLimits(unsigned size) {
 #if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT
   struct rlimit r;
   __typeof__ (r.rlim_cur) limit = (__typeof__ (r.rlim_cur)) (size) * 1048576;
@@ -165,9 +164,9 @@ static void SetMemoryLimits (unsigned si
 
 }
 
-static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
-                    const char **envp, const StringRef **redirects,
-                    unsigned memoryLimit, std::string *ErrMsg) {
+static bool Execute(ProcessInfo &PI, StringRef Program, const char **Args,
+                    const char **Envp, const StringRef **Redirects,
+                    unsigned MemoryLimit, std::string *ErrMsg) {
   if (!llvm::sys::fs::exists(Program)) {
     if (ErrMsg)
       *ErrMsg = std::string("Executable \"") + Program.str() +
@@ -178,7 +177,7 @@ static bool Execute(ProcessInfo &PI, Str
   // If this OS has posix_spawn and there is no memory limit being implied, use
   // posix_spawn.  It is more efficient than fork/exec.
 #ifdef HAVE_POSIX_SPAWN
-  if (memoryLimit == 0) {
+  if (MemoryLimit == 0) {
     posix_spawn_file_actions_t FileActionsStore;
     posix_spawn_file_actions_t *FileActions = nullptr;
 
@@ -187,11 +186,11 @@ static bool Execute(ProcessInfo &PI, Str
     // so we copy any StringRefs into this variable.
     std::string RedirectsStorage[3];
 
-    if (redirects) {
+    if (Redirects) {
       std::string *RedirectsStr[3] = {nullptr, nullptr, nullptr};
       for (int I = 0; I < 3; ++I) {
-        if (redirects[I]) {
-          RedirectsStorage[I] = *redirects[I];
+        if (Redirects[I]) {
+          RedirectsStorage[I] = *Redirects[I];
           RedirectsStr[I] = &RedirectsStorage[I];
         }
       }
@@ -203,8 +202,8 @@ static bool Execute(ProcessInfo &PI, Str
       if (RedirectIO_PS(RedirectsStr[0], 0, ErrMsg, FileActions) ||
           RedirectIO_PS(RedirectsStr[1], 1, ErrMsg, FileActions))
         return false;
-      if (redirects[1] == nullptr || redirects[2] == nullptr ||
-          *redirects[1] != *redirects[2]) {
+      if (Redirects[1] == nullptr || Redirects[2] == nullptr ||
+          *Redirects[1] != *Redirects[2]) {
         // Just redirect stderr
         if (RedirectIO_PS(RedirectsStr[2], 2, ErrMsg, FileActions))
           return false;
@@ -216,20 +215,20 @@ static bool Execute(ProcessInfo &PI, Str
       }
     }
 
-    if (!envp)
+    if (!Envp)
 #if !USE_NSGETENVIRON
-      envp = const_cast<const char **>(environ);
+      Envp = const_cast<const char **>(environ);
 #else
       // environ is missing in dylibs.
-      envp = const_cast<const char **>(*_NSGetEnviron());
+      Envp = const_cast<const char **>(*_NSGetEnviron());
 #endif
 
     // Explicitly initialized to prevent what appears to be a valgrind false
     // positive.
     pid_t PID = 0;
     int Err = posix_spawn(&PID, Program.str().c_str(), FileActions,
-                          /*attrp*/nullptr, const_cast<char **>(args),
-                          const_cast<char **>(envp));
+                          /*attrp*/nullptr, const_cast<char **>(Args),
+                          const_cast<char **>(Envp));
 
     if (FileActions)
       posix_spawn_file_actions_destroy(FileActions);
@@ -254,13 +253,12 @@ static bool Execute(ProcessInfo &PI, Str
     // Child process: Execute the program.
     case 0: {
       // Redirect file descriptors...
-      if (redirects) {
+      if (Redirects) {
         // Redirect stdin
-        if (RedirectIO(redirects[0], 0, ErrMsg)) { return false; }
+        if (RedirectIO(Redirects[0], 0, ErrMsg)) { return false; }
         // Redirect stdout
-        if (RedirectIO(redirects[1], 1, ErrMsg)) { return false; }
-        if (redirects[1] && redirects[2] &&
-            *(redirects[1]) == *(redirects[2])) {
+        if (RedirectIO(Redirects[1], 1, ErrMsg)) { return false; }
+        if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) {
           // If stdout and stderr should go to the same place, redirect stderr
           // to the FD already open for stdout.
           if (-1 == dup2(1,2)) {
@@ -269,24 +267,24 @@ static bool Execute(ProcessInfo &PI, Str
           }
         } else {
           // Just redirect stderr
-          if (RedirectIO(redirects[2], 2, ErrMsg)) { return false; }
+          if (RedirectIO(Redirects[2], 2, ErrMsg)) { return false; }
         }
       }
 
       // Set memory limits
-      if (memoryLimit!=0) {
-        SetMemoryLimits(memoryLimit);
+      if (MemoryLimit!=0) {
+        SetMemoryLimits(MemoryLimit);
       }
 
       // Execute!
       std::string PathStr = Program;
-      if (envp != nullptr)
+      if (Envp != nullptr)
         execve(PathStr.c_str(),
-               const_cast<char **>(args),
-               const_cast<char **>(envp));
+               const_cast<char **>(Args),
+               const_cast<char **>(Envp));
       else
         execv(PathStr.c_str(),
-              const_cast<char **>(args));
+              const_cast<char **>(Args));
       // If the execve() failed, we should exit. Follow Unix protocol and
       // return 127 if the executable was not found, and 126 otherwise.
       // Use _exit rather than exit so that atexit functions and static
@@ -433,7 +431,8 @@ llvm::sys::writeFileWithEncoding(StringR
   return EC;
 }
 
-bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<const char*> Args) {
+bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
+                                                  ArrayRef<const char *> Args) {
   static long ArgMax = sysconf(_SC_ARG_MAX);
 
   // System says no practical limit.
@@ -444,9 +443,8 @@ bool llvm::sys::commandLineFitsWithinSys
   long HalfArgMax = ArgMax / 2;
 
   size_t ArgLength = Program.size() + 1;
-  for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end();
-       I != E; ++I) {
-    size_t length = strlen(*I);
+  for (const char* Arg : Args) {
+    size_t length = strlen(Arg);
 
     // Ensure that we do not exceed the MAX_ARG_STRLEN constant on Linux, which
     // does not have a constant unlike what the man pages would have you

Modified: llvm/trunk/lib/Support/Windows/Program.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Program.inc?rev=312646&r1=312645&r2=312646&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Program.inc (original)
+++ llvm/trunk/lib/Support/Windows/Program.inc Wed Sep  6 09:28:33 2017
@@ -103,9 +103,9 @@ ErrorOr<std::string> sys::findProgramByN
   return std::string(U8Result.begin(), U8Result.end());
 }
 
-static HANDLE RedirectIO(const StringRef *path, int fd, std::string* ErrMsg) {
+static HANDLE RedirectIO(const StringRef *Path, int fd, std::string* ErrMsg) {
   HANDLE h;
-  if (path == 0) {
+  if (Path == 0) {
     if (!DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd),
                          GetCurrentProcess(), &h,
                          0, TRUE, DUPLICATE_SAME_ACCESS))
@@ -114,10 +114,10 @@ static HANDLE RedirectIO(const StringRef
   }
 
   std::string fname;
-  if (path->empty())
+  if (Path->empty())
     fname = "NUL";
   else
-    fname = *path;
+    fname = *Path;
 
   SECURITY_ATTRIBUTES sa;
   sa.nLength = sizeof(sa);
@@ -125,7 +125,7 @@ static HANDLE RedirectIO(const StringRef
   sa.bInheritHandle = TRUE;
 
   SmallVector<wchar_t, 128> fnameUnicode;
-  if (path->empty()) {
+  if (Path->empty()) {
     // Don't play long-path tricks on "NUL".
     if (windows::UTF8ToUTF16(fname, fnameUnicode))
       return INVALID_HANDLE_VALUE;
@@ -207,19 +207,19 @@ static unsigned int ArgLenWithQuotes(con
 
 }
 
-static std::unique_ptr<char[]> flattenArgs(const char **args) {
+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++) {
-    len += ArgLenWithQuotes(args[i]) + 1;
+  for (unsigned i = 0; Args[i]; i++) {
+    len += ArgLenWithQuotes(Args[i]) + 1;
   }
 
   // Now build the command line.
   std::unique_ptr<char[]> command(new char[len+1]);
   char *p = command.get();
 
-  for (unsigned i = 0; args[i]; i++) {
-    const char *arg = args[i];
+  for (unsigned i = 0; Args[i]; i++) {
+    const char *arg = Args[i];
     const char *start = arg;
 
     bool needsQuoting = ArgNeedsQuotes(arg);
@@ -248,9 +248,9 @@ static std::unique_ptr<char[]> flattenAr
   return command;
 }
 
-static bool Execute(ProcessInfo &PI, StringRef Program, const char **args,
-                    const char **envp, const StringRef **redirects,
-                    unsigned memoryLimit, std::string *ErrMsg) {
+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";
@@ -268,18 +268,18 @@ static bool Execute(ProcessInfo &PI, Str
   // 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);
+  std::unique_ptr<char[]> command = flattenArgs(Args);
 
   // The pointer to the environment block for the new process.
   std::vector<wchar_t> EnvBlock;
 
-  if (envp) {
+  if (Envp) {
     // An environment block consists of a null-terminated block of
     // null-terminated strings. Convert the array of environment variables to
     // an environment block by concatenating them.
-    for (unsigned i = 0; envp[i]; ++i) {
+    for (unsigned i = 0; Envp[i]; ++i) {
       SmallVector<wchar_t, MAX_PATH> EnvString;
-      if (std::error_code ec = windows::UTF8ToUTF16(envp[i], EnvString)) {
+      if (std::error_code ec = windows::UTF8ToUTF16(Envp[i], EnvString)) {
         SetLastError(ec.value());
         MakeErrMsg(ErrMsg, "Unable to convert environment variable to UTF-16");
         return false;
@@ -299,21 +299,21 @@ static bool Execute(ProcessInfo &PI, Str
   si.hStdOutput = INVALID_HANDLE_VALUE;
   si.hStdError = INVALID_HANDLE_VALUE;
 
-  if (redirects) {
+  if (Redirects) {
     si.dwFlags = STARTF_USESTDHANDLES;
 
-    si.hStdInput = RedirectIO(redirects[0], 0, ErrMsg);
+    si.hStdInput = RedirectIO(Redirects[0], 0, ErrMsg);
     if (si.hStdInput == INVALID_HANDLE_VALUE) {
       MakeErrMsg(ErrMsg, "can't redirect stdin");
       return false;
     }
-    si.hStdOutput = RedirectIO(redirects[1], 1, ErrMsg);
+    si.hStdOutput = RedirectIO(Redirects[1], 1, ErrMsg);
     if (si.hStdOutput == INVALID_HANDLE_VALUE) {
       CloseHandle(si.hStdInput);
       MakeErrMsg(ErrMsg, "can't redirect stdout");
       return false;
     }
-    if (redirects[1] && redirects[2] && *(redirects[1]) == *(redirects[2])) {
+    if (Redirects[1] && Redirects[2] && *Redirects[1] == *Redirects[2]) {
       // If stdout and stderr should go to the same place, redirect stderr
       // to the handle already open for stdout.
       if (!DuplicateHandle(GetCurrentProcess(), si.hStdOutput,
@@ -326,7 +326,7 @@ static bool Execute(ProcessInfo &PI, Str
       }
     } else {
       // Just redirect stderr
-      si.hStdError = RedirectIO(redirects[2], 2, ErrMsg);
+      si.hStdError = RedirectIO(Redirects[2], 2, ErrMsg);
       if (si.hStdError == INVALID_HANDLE_VALUE) {
         CloseHandle(si.hStdInput);
         CloseHandle(si.hStdOutput);
@@ -386,14 +386,14 @@ static bool Execute(ProcessInfo &PI, Str
 
   // Assign the process to a job if a memory limit is defined.
   ScopedJobHandle hJob;
-  if (memoryLimit != 0) {
+  if (MemoryLimit != 0) {
     hJob = CreateJobObjectW(0, 0);
     bool success = false;
     if (hJob) {
       JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli;
       memset(&jeli, 0, sizeof(jeli));
       jeli.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_PROCESS_MEMORY;
-      jeli.ProcessMemoryLimit = uintptr_t(memoryLimit) * 1048576;
+      jeli.ProcessMemoryLimit = uintptr_t(MemoryLimit) * 1048576;
       if (SetInformationJobObject(hJob, JobObjectExtendedLimitInformation,
                                   &jeli, sizeof(jeli))) {
         if (AssignProcessToJobObject(hJob, pi.hProcess))
@@ -534,16 +534,16 @@ llvm::sys::writeFileWithEncoding(StringR
   return EC;
 }
 
-bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program, ArrayRef<const char*> Args) {
+bool llvm::sys::commandLineFitsWithinSystemLimits(StringRef Program,
+                                                  ArrayRef<const char *> Args) {
   // The documented max length of the command line passed to CreateProcess.
   static const size_t MaxCommandStringLength = 32768;
   // Account for the trailing space for the program path and the
   // trailing NULL of the last argument.
   size_t ArgLength = ArgLenWithQuotes(Program.str().c_str()) + 2;
-  for (ArrayRef<const char*>::iterator I = Args.begin(), E = Args.end();
-       I != E; ++I) {
+  for (const char* Arg : Args) {
     // Account for the trailing space for every arg
-    ArgLength += ArgLenWithQuotes(*I) + 1;
+    ArgLength += ArgLenWithQuotes(Arg) + 1;
     if (ArgLength > MaxCommandStringLength) {
       return false;
     }




More information about the llvm-commits mailing list