Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Commit

Permalink
Search for XS in the same directory
Browse files Browse the repository at this point in the history
  • Loading branch information
tevador committed Jul 10, 2018
1 parent 5e32e28 commit 78704b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
26 changes: 24 additions & 2 deletions src-cpp/randomjs/ProgramRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ along with RandomJS. If not, see<http://www.gnu.org/licenses/>.
#include "ProgramRunner.h"
#include "Program.h"
#include <boost/process.hpp>
#include <boost/filesystem.hpp>

constexpr size_t programBufferCapacity = 256 * 1024;

namespace bp = boost::process;
namespace bf = boost::filesystem;

void ProgramRunner::startProcess() {
delete runnerStdout;
Expand All @@ -39,7 +41,27 @@ void ProgramRunner::startProcess() {
}
}

ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char* arguments)
ProgramRunner::ProgramRunner(const char* self, const char* xs)
: stream(programBufferCapacity),
arguments(nullptr),
runner(nullptr),
runnerStdout(nullptr),
runnerStdin(nullptr)
{
std::vector<bf::path> searchPaths;
auto basedir = bf::system_complete(self).parent_path();
searchPaths.push_back(basedir);
auto fullPath = bp::search_path(xs, searchPaths);
auto pathString = fullPath.string();
int allocationSize = pathString.length() + 1;
char* pathBuffer = new char[allocationSize];
std::copy(pathString.begin(), pathString.end(), pathBuffer);
pathBuffer[pathString.length()] = '\0';
this->executable = pathBuffer;
startProcess();
}

/*ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char* arguments)
: stream(programBufferCapacity),
arguments(arguments),
runner(nullptr),
Expand All @@ -56,7 +78,7 @@ ProgramRunner::ProgramRunner(const char* executable, bool searchPath, const char
this->executable = executable;
}
startProcess();
}
}*/

void ProgramRunner::writeProgram(Program* p) {
stream.clear();
Expand Down
3 changes: 2 additions & 1 deletion src-cpp/randomjs/ProgramRunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ namespace boost {
class ProgramRunner
{
public:
ProgramRunner(const char* executable, bool searchPath = false, const char* arguments = nullptr);
ProgramRunner(const char* self, const char* xs);
//ProgramRunner(const char* executable, bool searchPath = false, const char* arguments = nullptr);
void writeProgram(Program*);
const char* getProgramBuffer() const {
return stream.data();
Expand Down
2 changes: 1 addition & 1 deletion src-cpp/randomjs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ int main(int argc, char** argv) {
0xea, 0x00, 0x00, 0x00, 0x00, 0x77, 0xb2, 0x06, 0xa0, 0x2c, 0xa5, 0xb1, 0xd4, 0xce, 0x6b, 0xbf, 0xdf, 0x0a, 0xca,
0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09
};
ProgramRunner runner("./xst");
ProgramRunner runner(argv[0], "xst");
int* nonce = (int*)(blockTemplate + 39);
RandomGenerator rand;
ProgramFactory pf(rand);
Expand Down

0 comments on commit 78704b3

Please sign in to comment.