mirror of
https://github.com/YosysHQ/nextpnr.git
synced 2026-04-25 03:44:35 +00:00
Add GUI for executing python file
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -33,4 +33,5 @@ void pyinterpreter_initialize();
|
||||
void pyinterpreter_finalize();
|
||||
void pyinterpreter_aquire();
|
||||
void pyinterpreter_release();
|
||||
std::string pyinterpreter_execute_file(const char *python_file, int *errorCode);
|
||||
#endif // PYINTERPRETER_H
|
||||
|
||||
Reference in New Issue
Block a user