aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/pythonextensions/pyutil.cpp30
1 files changed, 14 insertions, 16 deletions
diff --git a/plugins/pythonextensions/pyutil.cpp b/plugins/pythonextensions/pyutil.cpp
index 8f2728f..169c8a0 100644
--- a/plugins/pythonextensions/pyutil.cpp
+++ b/plugins/pythonextensions/pyutil.cpp
@@ -76,6 +76,17 @@ namespace PyUtil {
static State state = PythonUninitialized;
+static bool runSimpleString(const std::string &script)
+{
+ if (PyRun_SimpleString(script.c_str()) == -1) {
+ if (PyErr_Occurred())
+ PyErr_Print();
+ return false;
+ }
+
+ return true;
+}
+
static void cleanup()
{
if (state > PythonUninitialized) {
@@ -127,12 +138,8 @@ State init()
// The Python interpreter eats SIGINT, which is not what we want.
// This stops it from happening.
// See https://mail.python.org/pipermail/cplusplus-sig/2012-December/016858.html
- if (PyRun_SimpleString(std::string(
- "import signal as " privateName("signal") "\n"
- "" privateName("signal") ".signal(" privateName("signal") ".SIGINT, " privateName("signal") ".SIG_DFL)"
- ).c_str()) == -1) {
- if (PyErr_Occurred())
- PyErr_Print();
+ if (!runSimpleString("import signal as " privateName("signal") "\n"
+ "" privateName("signal") ".signal(" privateName("signal") ".SIGINT, " privateName("signal") ".SIG_DFL)")) {
qWarning("Failed to prevent SIGINT capture.");
}
@@ -222,16 +229,7 @@ bool bindSubPyObject(const QString &moduleName, const QString &name, void *obj)
bool runScript(const std::string &script)
{
- if (init() == PythonUninitialized)
- return false;
-
- if (PyRun_SimpleString(script.c_str()) == -1) {
- if (PyErr_Occurred())
- PyErr_Print();
- return false;
- }
-
- return true;
+ return (init() >= PythonInitialized && runSimpleString(script));
}
bool runScriptWithPath(const std::string &script, const std::string &path)