<div dir="ltr">On Fri, Jun 14, 2013 at 9:38 PM, Rafael Espindola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><div class="gmail_extra">
<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: rafael<br>
Date: Fri Jun 14 14:38:45 2013<br>
New Revision: 183996<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=183996&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=183996&view=rev</a><br>
Log:<br>
Replace use of PathV1.h in Program.cpp.<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/Support/FileSystem.h<br>
llvm/trunk/lib/Support/Program.cpp<br>
llvm/trunk/lib/Support/Unix/PathV2.inc<br>
llvm/trunk/lib/Support/Unix/Program.inc<br>
llvm/trunk/lib/Support/Windows/PathV2.inc<br>
llvm/trunk/lib/Support/Windows/Program.inc<br>
<br>
Modified: llvm/trunk/include/llvm/Support/FileSystem.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=183996&r1=183995&r2=183996&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=183996&r1=183995&r2=183996&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)<br>
+++ llvm/trunk/include/llvm/Support/FileSystem.h Fri Jun 14 14:38:45 2013<br>
@@ -342,6 +342,12 @@ inline bool exists(const Twine &path) {<br>
return !exists(path, result) && result;<br>
}<br>
<br>
+/// @brief Can we execute this file?<br>
+///<br>
+/// @param Path Input path.<br>
+/// @returns True if we can execute it, false otherwise.<br>
+bool can_execute(const Twine &Path);<br>
+<br>
/// @brief Do file_status's represent the same thing?<br>
///<br>
/// @param A Input file_status.<br>
<br>
Modified: llvm/trunk/lib/Support/Program.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Program.cpp?rev=183996&r1=183995&r2=183996&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Program.cpp?rev=183996&r1=183995&r2=183996&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Program.cpp (original)<br>
+++ llvm/trunk/lib/Support/Program.cpp Fri Jun 14 14:38:45 2013<br>
@@ -12,7 +12,6 @@<br>
//===----------------------------------------------------------------------===//<br>
<br>
#include "llvm/Support/Program.h"<br>
-#include "llvm/Support/PathV1.h"<br>
#include "llvm/Config/config.h"<br>
#include "llvm/Support/system_error.h"<br>
using namespace llvm;<br>
@@ -23,39 +22,12 @@ using namespace sys;<br>
//=== independent code.<br>
//===----------------------------------------------------------------------===//<br>
<br>
-static bool Execute(void **Data, const Path &path, const char **args,<br>
- const char **env, const sys::Path **redirects,<br>
- unsigned memoryLimit, std::string *ErrMsg);<br>
-<br>
-static int Wait(void *&Data, const Path &path, unsigned secondsToWait,<br>
- std::string *ErrMsg);<br>
-<br>
-<br>
static bool Execute(void **Data, StringRef Program, const char **args,<br>
const char **env, const StringRef **Redirects,<br>
- unsigned memoryLimit, std::string *ErrMsg) {<br>
- Path P(Program);<br>
- if (!Redirects)<br>
- return Execute(Data, P, args, env, 0, memoryLimit, ErrMsg);<br>
- Path IO[3];<br>
- const Path *IOP[3];<br>
- for (int I = 0; I < 3; ++I) {<br>
- if (Redirects[I]) {<br>
- IO[I] = *Redirects[I];<br>
- IOP[I] = &IO[I];<br>
- } else {<br>
- IOP[I] = 0;<br>
- }<br>
- }<br>
-<br>
- return Execute(Data, P, args, env, IOP, memoryLimit, ErrMsg);<br>
-}<br>
+ unsigned memoryLimit, std::string *ErrMsg);<br>
<br>
static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,<br>
- std::string *ErrMsg) {<br>
- Path P(Program);<br>
- return Wait(Data, P, secondsToWait, ErrMsg);<br>
-}<br>
+ std::string *ErrMsg);<br>
<br>
int sys::ExecuteAndWait(StringRef Program, const char **args, const char **envp,<br>
const StringRef **redirects, unsigned secondsToWait,<br>
<br>
Modified: llvm/trunk/lib/Support/Unix/PathV2.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=183996&r1=183995&r2=183996&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=183996&r1=183995&r2=183996&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)<br>
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Fri Jun 14 14:38:45 2013<br>
@@ -292,6 +292,13 @@ error_code exists(const Twine &path, boo<br>
return error_code::success();<br>
}<br>
<br>
+bool can_execute(const Twine &Path) {<br>
+ SmallString<128> PathStorage;<br>
+ StringRef P = Path.toNullTerminatedStringRef(PathStorage);<br>
+<br>
+ return ::access(P.begin(), X_OK) != -1;<br></blockquote><div><br></div><div style>This regressed from PathV1. I fixed that in r184074 - let me know if you see problems there...</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+}<br>
+<br>
bool equivalent(file_status A, file_status B) {<br>
assert(status_known(A) && status_known(B));<br>
return A.fs_st_dev == B.fs_st_dev &&<br>
<br>
Modified: llvm/trunk/lib/Support/Unix/Program.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc?rev=183996&r1=183995&r2=183996&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Program.inc?rev=183996&r1=183995&r2=183996&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Unix/Program.inc (original)<br>
+++ llvm/trunk/lib/Support/Unix/Program.inc Fri Jun 14 14:38:45 2013<br>
@@ -54,13 +54,11 @@ sys::FindProgramByName(const std::string<br>
// Check some degenerate cases<br>
if (progName.length() == 0) // no program<br>
return "";<br>
- Path temp;<br>
- if (!temp.set(progName)) // invalid name<br>
- return "";<br>
+ std::string temp = progName;<br>
// Use the given path verbatim if it contains any slashes; this matches<br>
// the behavior of sh(1) and friends.<br>
if (progName.find('/') != std::string::npos)<br>
- return temp.str();<br>
+ return temp;<br>
<br>
// At this point, the file name is valid and does not contain slashes. Search<br>
// for it through the directories specified in the PATH environment variable.<br>
@@ -77,12 +75,10 @@ sys::FindProgramByName(const std::string<br>
const char *Colon = std::find(PathStr, PathStr+PathLen, ':');<br>
<br>
// Check to see if this first directory contains the executable...<br>
- Path FilePath;<br>
- if (FilePath.set(std::string(PathStr,Colon))) {<br>
- FilePath.appendComponent(progName);<br>
- if (FilePath.canExecute())<br>
- return FilePath.str(); // Found the executable!<br>
- }<br>
+ SmallString<128> FilePath(PathStr,Colon);<br>
+ sys::path::append(FilePath, progName);<br>
+ if (sys::fs::can_execute(Twine(FilePath)))<br>
+ return FilePath.str(); // Found the executable!<br>
<br>
// Nope it wasn't in this directory, check the next path in the list!<br>
PathLen -= Colon-PathStr;<br>
@@ -97,20 +93,20 @@ sys::FindProgramByName(const std::string<br>
return "";<br>
}<br>
<br>
-static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {<br>
+static bool RedirectIO(const StringRef *Path, int FD, std::string* ErrMsg) {<br>
if (Path == 0) // Noop<br>
return false;<br>
- const char *File;<br>
- if (Path->isEmpty())<br>
+ std::string File;<br>
+ if (Path->empty())<br>
// Redirect empty paths to /dev/null<br>
File = "/dev/null";<br>
else<br>
- File = Path->c_str();<br>
+ File = *Path;<br>
<br>
// Open the file<br>
- int InFD = open(File, FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666);<br>
+ int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666);<br>
if (InFD == -1) {<br>
- MakeErrMsg(ErrMsg, "Cannot open file '" + std::string(File) + "' for "<br>
+ MakeErrMsg(ErrMsg, "Cannot open file '" + File + "' for "<br>
+ (FD == 0 ? "input" : "output"));<br>
return true;<br>
}<br>
@@ -126,19 +122,20 @@ static bool RedirectIO(const Path *Path,<br>
}<br>
<br>
#ifdef HAVE_POSIX_SPAWN<br>
-static bool RedirectIO_PS(const Path *Path, int FD, std::string *ErrMsg,<br>
+static bool RedirectIO_PS(const StringRef *Path, int FD, std::string *ErrMsg,<br>
posix_spawn_file_actions_t *FileActions) {<br>
if (Path == 0) // Noop<br>
return false;<br>
- const char *File;<br>
- if (Path->isEmpty())<br>
+ std::string File;<br>
+ if (Path->empty())<br>
// Redirect empty paths to /dev/null<br>
File = "/dev/null";<br>
else<br>
- File = Path->c_str();<br>
+ File = *Path;<br>
<br>
- if (int Err = posix_spawn_file_actions_addopen(FileActions, FD,<br>
- File, FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666))<br>
+ if (int Err = posix_spawn_file_actions_addopen(<br>
+ FileActions, FD, File.c_str(),<br>
+ FD == 0 ? O_RDONLY : O_WRONLY | O_CREAT, 0666))<br>
return MakeErrMsg(ErrMsg, "Cannot dup2", Err);<br>
return false;<br>
}<br>
@@ -178,8 +175,8 @@ static void SetMemoryLimits (unsigned si<br>
<br>
}<br>
<br>
-static bool Execute(void **Data, const Path &path, const char **args,<br>
- const char **envp, const Path **redirects,<br>
+static bool Execute(void **Data, StringRef Program, const char **args,<br>
+ const char **envp, const StringRef **redirects,<br>
unsigned memoryLimit, std::string *ErrMsg) {<br>
// If this OS has posix_spawn and there is no memory limit being implied, use<br>
// posix_spawn. It is more efficient than fork/exec.<br>
@@ -219,7 +216,7 @@ static bool Execute(void **Data, const P<br>
// Explicitly initialized to prevent what appears to be a valgrind false<br>
// positive.<br>
pid_t PID = 0;<br>
- int Err = posix_spawn(&PID, path.c_str(), FileActions, /*attrp*/0,<br>
+ int Err = posix_spawn(&PID, Program.str().c_str(), FileActions, /*attrp*/0,<br>
const_cast<char **>(args), const_cast<char **>(envp));<br>
<br>
if (FileActions)<br>
@@ -270,12 +267,13 @@ static bool Execute(void **Data, const P<br>
}<br>
<br>
// Execute!<br>
+ std::string PathStr = Program;<br>
if (envp != 0)<br>
- execve(path.c_str(),<br>
+ execve(PathStr.c_str(),<br>
const_cast<char **>(args),<br>
const_cast<char **>(envp));<br>
else<br>
- execv(path.c_str(),<br>
+ execv(PathStr.c_str(),<br>
const_cast<char **>(args));<br>
// If the execve() failed, we should exit. Follow Unix protocol and<br>
// return 127 if the executable was not found, and 126 otherwise.<br>
@@ -297,7 +295,7 @@ static bool Execute(void **Data, const P<br>
return true;<br>
}<br>
<br>
-static int Wait(void *&Data, const sys::Path &path, unsigned secondsToWait,<br>
+static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,<br>
std::string *ErrMsg) {<br>
#ifdef HAVE_SYS_WAIT_H<br>
struct sigaction Act, Old;<br>
@@ -356,7 +354,7 @@ static int Wait(void *&Data, const sys::<br>
// itself apparently does not), check to see if the failure was due to some<br>
// reason other than the file not existing, and return 126 in this case.<br>
bool Exists;<br>
- if (result == 127 && !llvm::sys::fs::exists(path.str(), Exists) && Exists)<br>
+ if (result == 127 && !llvm::sys::fs::exists(Program, Exists) && Exists)<br>
result = 126;<br>
#endif<br>
if (result == 127) {<br>
<br>
Modified: llvm/trunk/lib/Support/Windows/PathV2.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=183996&r1=183995&r2=183996&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=183996&r1=183995&r2=183996&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)<br>
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Fri Jun 14 14:38:45 2013<br>
@@ -362,6 +362,17 @@ error_code exists(const Twine &path, boo<br>
return error_code::success();<br>
}<br>
<br>
+bool can_execute(const Twine &Path) {<br>
+ SmallString<128> PathStorage;<br>
+ SmallVector<wchar_t, 128> PathUtf16;<br>
+<br>
+ if (UTF8ToUTF16(Path.toStringRef(PathStorage), PathUtf16))<br>
+ return false;<br>
+<br>
+ DWORD Attr = ::GetFileAttributesW(PathUtf16.begin());<br>
+ return Attr != INVALID_FILE_ATTRIBUTES;<br>
+}<br>
+<br>
bool equivalent(file_status A, file_status B) {<br>
assert(status_known(A) && status_known(B));<br>
return A.FileIndexHigh == B.FileIndexHigh &&<br>
<br>
Modified: llvm/trunk/lib/Support/Windows/Program.inc<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Program.inc?rev=183996&r1=183995&r2=183996&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Program.inc?rev=183996&r1=183995&r2=183996&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/Windows/Program.inc (original)<br>
+++ llvm/trunk/lib/Support/Windows/Program.inc Fri Jun 14 14:38:45 2013<br>
@@ -12,6 +12,7 @@<br>
//===----------------------------------------------------------------------===//<br>
<br>
#include "Windows.h"<br>
+#include "llvm/Support/FileSystem.h"<br>
#include <cstdio><br>
#include <fcntl.h><br>
#include <io.h><br>
@@ -37,13 +38,11 @@ std::string sys::FindProgramByName(const<br>
// Check some degenerate cases<br>
if (progName.length() == 0) // no program<br>
return "";<br>
- Path temp;<br>
- if (!temp.set(progName)) // invalid name<br>
- return "";<br>
+ std::string temp = progName;<br>
// Return paths with slashes verbatim.<br>
if (progName.find('\\') != std::string::npos ||<br>
progName.find('/') != std::string::npos)<br>
- return temp.str();<br>
+ return temp;<br>
<br>
// At this point, the file name is valid and does not contain slashes.<br>
// Let Windows search for it.<br>
@@ -76,7 +75,7 @@ std::string sys::FindProgramByName(const<br>
}<br>
}<br>
<br>
-static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) {<br>
+static HANDLE RedirectIO(const StringRef *path, int fd, std::string* ErrMsg) {<br>
HANDLE h;<br>
if (path == 0) {<br>
DuplicateHandle(GetCurrentProcess(), (HANDLE)_get_osfhandle(fd),<br>
@@ -85,19 +84,19 @@ static HANDLE RedirectIO(const Path *pat<br>
return h;<br>
}<br>
<br>
- const char *fname;<br>
- if (path->isEmpty())<br>
+ std::string fname;<br>
+ if (path->empty())<br>
fname = "NUL";<br>
else<br>
- fname = path->c_str();<br>
+ fname = *path;<br>
<br>
SECURITY_ATTRIBUTES sa;<br>
sa.nLength = sizeof(sa);<br>
sa.lpSecurityDescriptor = 0;<br>
sa.bInheritHandle = TRUE;<br>
<br>
- h = CreateFile(fname, fd ? GENERIC_WRITE : GENERIC_READ, FILE_SHARE_READ,<br>
- &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS,<br>
+ h = CreateFile(fname.c_str(), fd ? GENERIC_WRITE : GENERIC_READ,<br>
+ FILE_SHARE_READ, &sa, fd == 0 ? OPEN_EXISTING : CREATE_ALWAYS,<br>
FILE_ATTRIBUTE_NORMAL, NULL);<br>
if (h == INVALID_HANDLE_VALUE) {<br>
MakeErrMsg(ErrMsg, std::string(fname) + ": Can't open file for " +<br>
@@ -171,13 +170,13 @@ static unsigned int ArgLenWithQuotes(con<br>
}<br>
<br>
static bool Execute(void **Data,<br>
- const Path& path,<br>
+ StringRef Program,<br>
const char** args,<br>
const char** envp,<br>
- const Path** redirects,<br>
+ const StringRef** redirects,<br>
unsigned memoryLimit,<br>
std::string* ErrMsg) {<br>
- if (!path.canExecute()) {<br>
+ if (!sys::fs::can_execute(Program)) {<br>
if (ErrMsg)<br>
*ErrMsg = "program not executable";<br>
return false;<br>
@@ -297,7 +296,8 @@ static bool Execute(void **Data,<br>
<br>
fflush(stdout);<br>
fflush(stderr);<br>
- BOOL rc = CreateProcess(path.c_str(), command, NULL, NULL, TRUE, 0,<br>
+ std::string ProgramStr = Program;<br>
+ BOOL rc = CreateProcess(ProgramStr.c_str(), command, NULL, NULL, TRUE, 0,<br>
envblock, NULL, &si, &pi);<br>
DWORD err = GetLastError();<br>
<br>
@@ -311,7 +311,7 @@ static bool Execute(void **Data,<br>
if (!rc) {<br>
SetLastError(err);<br>
MakeErrMsg(ErrMsg, std::string("Couldn't execute program '") +<br>
- path.str() + "'");<br>
+ ProgramStr + "'");<br>
return false;<br>
}<br>
if (Data) {<br>
@@ -398,7 +398,7 @@ static int WaitAux(Win32ProcessInfo *wpi<br>
return 1;<br>
}<br>
<br>
-static int Wait(void *&Data, const Path &path, unsigned secondsToWait,<br>
+static int Wait(void *&Data, StringRef Program, unsigned secondsToWait,<br>
std::string *ErrMsg) {<br>
Win32ProcessInfo *wpi = reinterpret_cast<Win32ProcessInfo *>(Data);<br>
int Ret = WaitAux(wpi, secondsToWait, ErrMsg);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>