diff --git a/.appveyor.yml b/.appveyor.yml index 800ab685..a78f2c49 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -45,7 +45,6 @@ install: before_build: - cmd: git submodule update --init - - cmd: python scripts\compile_python_resources.py # Build config build_script: diff --git a/scripts/compile_python_resources.py b/scripts/compile_python_resources.py deleted file mode 100644 index 7c05c17e..00000000 --- a/scripts/compile_python_resources.py +++ /dev/null @@ -1,10 +0,0 @@ -import compileall -import os - -root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) -compileall.compile_dir(os.path.join(root, 'src', 'python'), legacy=True, optimize=2) -with open(os.path.join(root, 'src', 'resources.qrc'), 'r+b') as f: - data = f.read() - data = data.replace(b'.py<', b'.pyc<') - f.seek(0) - f.write(data) diff --git a/src/Cutter.pro b/src/Cutter.pro index cc26a3b5..85134534 100644 --- a/src/Cutter.pro +++ b/src/Cutter.pro @@ -100,7 +100,7 @@ CUTTER_ENABLE_PYTHON { PYTHON_EXECUTABLE = $$system("where python", lines) PYTHON_EXECUTABLE = $$first(PYTHON_EXECUTABLE) pythonpath = $$clean_path($$dirname(PYTHON_EXECUTABLE)) - LIBS += -L$${pythonpath} -L$${pythonpath}/libs -lpython3 + LIBS += -L$${pythonpath}/libs -lpython3 INCLUDEPATH += $${pythonpath}/include } diff --git a/src/common/PythonAPI.h b/src/common/PythonAPI.h index f73da892..76ad843e 100644 --- a/src/common/PythonAPI.h +++ b/src/common/PythonAPI.h @@ -3,10 +3,10 @@ #ifdef CUTTER_ENABLE_PYTHON +#define Py_LIMITED_API 0x03050000 #include PyObject *PyInit_api(); -PyObject *PyInit_api_internal(); #endif diff --git a/src/common/PythonManager.cpp b/src/common/PythonManager.cpp index 32620fc7..65d33d87 100644 --- a/src/common/PythonManager.cpp +++ b/src/common/PythonManager.cpp @@ -6,7 +6,6 @@ #include "PythonManager.h" #include "Cutter.h" -#include #include #include #include @@ -103,11 +102,14 @@ static void pySideDestructionVisitor(SbkObject* pyObj, void* data) const char *reprStr = ""; PyObject *repr = PyObject_Repr(reinterpret_cast(pyObj)); + PyObject *reprBytes; if (repr) { - reprStr = PyUnicode_AsUTF8(repr); + reprBytes = PyUnicode_AsUTF8String(repr); + reprStr = PyBytes_AsString(reprBytes); } qWarning() << "Warning: QObject from Python remaining (leaked from plugin?):" << reprStr; if (repr) { + Py_DecRef(reprBytes); Py_DecRef(repr); } @@ -139,11 +141,11 @@ void PythonManager::shutdown() PySide::runCleanupFunctions(); #endif - Py_Finalize(); - if (pythonHome) { - PyMem_RawFree(pythonHome); + PyMem_Free(pythonHome); } + + Py_Finalize(); } void PythonManager::addPythonPath(char *path) { @@ -183,4 +185,4 @@ void PythonManager::saveThread() } } -#endif \ No newline at end of file +#endif diff --git a/src/common/QtResImporter.cpp b/src/common/QtResImporter.cpp index bac04a24..6953cd36 100644 --- a/src/common/QtResImporter.cpp +++ b/src/common/QtResImporter.cpp @@ -1,53 +1,37 @@ #ifdef CUTTER_ENABLE_PYTHON +#define Py_LIMITED_API 0x03050000 #include -#include #include "QtResImporter.h" #include #include -int QtResExists(const char *name, QFile &file) +bool QtResExists(const char *name, QFile &file) { QString fname = QString::asprintf(":/python/%s.py", name); file.setFileName(fname); - if (file.exists()) - return 1; - fname.append('c'); - file.setFileName(fname); - if (file.exists()) - return 2; - return 0; + return file.exists(); } PyObject *QtResGetCode(const char *name) { QFile moduleFile; - bool isBytecode = false; - switch (QtResExists(name, moduleFile)) { - case 0: + if (!QtResExists(name, moduleFile)) { return nullptr; - case 2: - isBytecode = true; } moduleFile.open(QIODevice::ReadOnly); QByteArray data = moduleFile.readAll(); moduleFile.close(); - PyObject *codeObject; - if (isBytecode) { - codeObject = PyMarshal_ReadObjectFromString(data.constData() + 12, - data.size() - 12); - } else { - codeObject = Py_CompileString(data.constData(), - moduleFile.fileName().toLocal8Bit().constData(), - Py_file_input); - } + PyObject *codeObject = Py_CompileString(data.constData(), + moduleFile.fileName().toLocal8Bit().constData(), + Py_file_input); if (!codeObject) { - qWarning() << "Couldn't unmarshal/compile " << moduleFile.fileName(); + qWarning() << "Couldn't compile " << moduleFile.fileName(); } return codeObject; } diff --git a/src/meson.build b/src/meson.build index 8f503451..e1ef168f 100644 --- a/src/meson.build +++ b/src/meson.build @@ -101,6 +101,7 @@ cpp = meson.get_compiler('cpp') if host_machine.system() == 'windows' add_project_arguments('-D_CRT_NONSTDC_NO_DEPRECATE', language: 'cpp') add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', language: 'cpp') + add_project_link_arguments(join_paths(py3_exe.get_variable('BINDIR'), 'libs', 'python3.lib'), language: 'cpp') endif cutter_exe = executable(