1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Attempt at fixing the windows build.

llvm-svn: 183865
This commit is contained in:
Rafael Espindola 2013-06-12 21:11:50 +00:00
parent 5b921b1aa1
commit c6aa10e44a

View File

@ -32,21 +32,8 @@ namespace {
namespace llvm { namespace llvm {
using namespace sys; using namespace sys;
Program::Program() : Data_(0) {}
Program::~Program() {
if (Data_) {
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
CloseHandle(wpi->hProcess);
delete wpi;
Data_ = 0;
}
}
// This function just uses the PATH environment variable to find the program. // This function just uses the PATH environment variable to find the program.
Path Path sys::FindProgramByName(const std::string& progName) {
Program::FindProgramByName(const std::string& progName) {
// Check some degenerate cases // Check some degenerate cases
if (progName.length() == 0) // no program if (progName.length() == 0) // no program
return Path(); return Path();
@ -181,19 +168,20 @@ static unsigned int ArgLenWithQuotes(const char *Str) {
return len; return len;
} }
}
bool static bool Execute(Void *&Data,
Program::Execute(const Path& path, const Path& path,
const char** args, const char** args,
const char** envp, const char** envp,
const Path** redirects, const Path** redirects,
unsigned memoryLimit, unsigned memoryLimit,
std::string* ErrMsg) { std::string* ErrMsg) {
if (Data_) { if (Data) {
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_); Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data);
CloseHandle(wpi->hProcess); CloseHandle(wpi->hProcess);
delete wpi; delete wpi;
Data_ = 0; Data = 0;
} }
if (!path.canExecute()) { if (!path.canExecute()) {
@ -336,7 +324,7 @@ Program::Execute(const Path& path,
Win32ProcessInfo* wpi = new Win32ProcessInfo; Win32ProcessInfo* wpi = new Win32ProcessInfo;
wpi->hProcess = pi.hProcess; wpi->hProcess = pi.hProcess;
wpi->dwProcessId = pi.dwProcessId; wpi->dwProcessId = pi.dwProcessId;
Data_ = wpi; Data = wpi;
// Make sure these get closed no matter what. // Make sure these get closed no matter what.
ScopedCommonHandle hThread(pi.hThread); ScopedCommonHandle hThread(pi.hThread);
@ -369,16 +357,15 @@ Program::Execute(const Path& path,
return true; return true;
} }
int static int WaitAux(void *&Data, const Path &path,
Program::Wait(const Path &path, unsigned secondsToWait,
unsigned secondsToWait, std::string* ErrMsg) {
std::string* ErrMsg) { if (Data == 0) {
if (Data_ == 0) {
MakeErrMsg(ErrMsg, "Process not started!"); MakeErrMsg(ErrMsg, "Process not started!");
return -1; return -1;
} }
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_); Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data);
HANDLE hProcess = wpi->hProcess; HANDLE hProcess = wpi->hProcess;
// Wait for the process to terminate. // Wait for the process to terminate.
@ -420,21 +407,35 @@ Program::Wait(const Path &path,
return 1; return 1;
} }
error_code Program::ChangeStdinToBinary(){ static int Wait(void *&Data, const Path &path,
unsigned secondsToWait,
std::string* ErrMsg) {
int Ret = WaitAux(Data, path, secondsToWait, ErrMsg);
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data);
CloseHandle(wpi->hProcess);
delete wpi;
Data = 0;
return Ret;
}
namespace llvm {
error_code ChangeStdinToBinary(){
int result = _setmode( _fileno(stdin), _O_BINARY ); int result = _setmode( _fileno(stdin), _O_BINARY );
if (result == -1) if (result == -1)
return error_code(errno, generic_category()); return error_code(errno, generic_category());
return make_error_code(errc::success); return make_error_code(errc::success);
} }
error_code Program::ChangeStdoutToBinary(){ error_code ChangeStdoutToBinary(){
int result = _setmode( _fileno(stdout), _O_BINARY ); int result = _setmode( _fileno(stdout), _O_BINARY );
if (result == -1) if (result == -1)
return error_code(errno, generic_category()); return error_code(errno, generic_category());
return make_error_code(errc::success); return make_error_code(errc::success);
} }
error_code Program::ChangeStderrToBinary(){ error_code ChangeStderrToBinary(){
int result = _setmode( _fileno(stderr), _O_BINARY ); int result = _setmode( _fileno(stderr), _O_BINARY );
if (result == -1) if (result == -1)
return error_code(errno, generic_category()); return error_code(errno, generic_category());