diff options
author | David Shah <davey1576@gmail.com> | 2018-12-14 18:29:54 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-14 18:29:54 +0000 |
commit | 7fa13295084e65c7824834094abe9c6c3122c4c8 (patch) | |
tree | 79b6bc1d50c75b6b7bb78b5d842d9c75178c4a09 /3rdparty/python-console/modified/pyinterpreter.cc | |
parent | 19cffde375fe63e36bfd880727bdc0a04a2ccf32 (diff) | |
parent | e0b4a2eeab91696e54d9ff3acc319d99ab9b96f9 (diff) | |
download | nextpnr-7fa13295084e65c7824834094abe9c6c3122c4c8.tar.gz nextpnr-7fa13295084e65c7824834094abe9c6c3122c4c8.tar.bz2 nextpnr-7fa13295084e65c7824834094abe9c6c3122c4c8.zip |
Merge pull request #180 from YosysHQ/python_execute_gui
Add GUI for executing python file
Diffstat (limited to '3rdparty/python-console/modified/pyinterpreter.cc')
-rw-r--r-- | 3rdparty/python-console/modified/pyinterpreter.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/3rdparty/python-console/modified/pyinterpreter.cc b/3rdparty/python-console/modified/pyinterpreter.cc index f53207ad..89c9b88c 100644 --- a/3rdparty/python-console/modified/pyinterpreter.cc +++ b/3rdparty/python-console/modified/pyinterpreter.cc @@ -153,3 +153,25 @@ void pyinterpreter_release() { PyEval_ReleaseThread(m_threadState); } + +std::string pyinterpreter_execute_file(const char *python_file, int *errorCode) +{ + PyEval_AcquireThread(m_threadState); + *errorCode = 0; + std::string res; + FILE *fp = fopen(python_file, "r"); + if (fp == NULL) { + *errorCode = 1; + res = "Fatal error: file not found " + std::string(python_file) + "\n"; + return res; + } + + if (PyRun_SimpleFile(fp, python_file)==-1) { + *errorCode = 1; + PyErr_Print(); + } + res = redirector_take_output(m_threadState); + + PyEval_ReleaseThread(m_threadState); + return res; +} |