Use Python stable ABI >= 3.5 (#1426)

This commit is contained in:
Paul I 2019-04-08 23:07:35 +03:00 committed by Florian Märkl
parent 65850d6aee
commit 3d454cdaa0
7 changed files with 19 additions and 43 deletions

View File

@ -45,7 +45,6 @@ install:
before_build: before_build:
- cmd: git submodule update --init - cmd: git submodule update --init
- cmd: python scripts\compile_python_resources.py
# Build config # Build config
build_script: build_script:

View File

@ -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)

View File

@ -100,7 +100,7 @@ CUTTER_ENABLE_PYTHON {
PYTHON_EXECUTABLE = $$system("where python", lines) PYTHON_EXECUTABLE = $$system("where python", lines)
PYTHON_EXECUTABLE = $$first(PYTHON_EXECUTABLE) PYTHON_EXECUTABLE = $$first(PYTHON_EXECUTABLE)
pythonpath = $$clean_path($$dirname(PYTHON_EXECUTABLE)) pythonpath = $$clean_path($$dirname(PYTHON_EXECUTABLE))
LIBS += -L$${pythonpath} -L$${pythonpath}/libs -lpython3 LIBS += -L$${pythonpath}/libs -lpython3
INCLUDEPATH += $${pythonpath}/include INCLUDEPATH += $${pythonpath}/include
} }

View File

@ -3,10 +3,10 @@
#ifdef CUTTER_ENABLE_PYTHON #ifdef CUTTER_ENABLE_PYTHON
#define Py_LIMITED_API 0x03050000
#include <Python.h> #include <Python.h>
PyObject *PyInit_api(); PyObject *PyInit_api();
PyObject *PyInit_api_internal();
#endif #endif

View File

@ -6,7 +6,6 @@
#include "PythonManager.h" #include "PythonManager.h"
#include "Cutter.h" #include "Cutter.h"
#include <marshal.h>
#include <QDebug> #include <QDebug>
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
@ -103,11 +102,14 @@ static void pySideDestructionVisitor(SbkObject* pyObj, void* data)
const char *reprStr = ""; const char *reprStr = "";
PyObject *repr = PyObject_Repr(reinterpret_cast<PyObject *>(pyObj)); PyObject *repr = PyObject_Repr(reinterpret_cast<PyObject *>(pyObj));
PyObject *reprBytes;
if (repr) { if (repr) {
reprStr = PyUnicode_AsUTF8(repr); reprBytes = PyUnicode_AsUTF8String(repr);
reprStr = PyBytes_AsString(reprBytes);
} }
qWarning() << "Warning: QObject from Python remaining (leaked from plugin?):" << reprStr; qWarning() << "Warning: QObject from Python remaining (leaked from plugin?):" << reprStr;
if (repr) { if (repr) {
Py_DecRef(reprBytes);
Py_DecRef(repr); Py_DecRef(repr);
} }
@ -139,11 +141,11 @@ void PythonManager::shutdown()
PySide::runCleanupFunctions(); PySide::runCleanupFunctions();
#endif #endif
Py_Finalize();
if (pythonHome) { if (pythonHome) {
PyMem_RawFree(pythonHome); PyMem_Free(pythonHome);
} }
Py_Finalize();
} }
void PythonManager::addPythonPath(char *path) { void PythonManager::addPythonPath(char *path) {
@ -183,4 +185,4 @@ void PythonManager::saveThread()
} }
} }
#endif #endif

View File

@ -1,53 +1,37 @@
#ifdef CUTTER_ENABLE_PYTHON #ifdef CUTTER_ENABLE_PYTHON
#define Py_LIMITED_API 0x03050000
#include <Python.h> #include <Python.h>
#include <marshal.h>
#include "QtResImporter.h" #include "QtResImporter.h"
#include <QFile> #include <QFile>
#include <QDebug> #include <QDebug>
int QtResExists(const char *name, QFile &file) bool QtResExists(const char *name, QFile &file)
{ {
QString fname = QString::asprintf(":/python/%s.py", name); QString fname = QString::asprintf(":/python/%s.py", name);
file.setFileName(fname); file.setFileName(fname);
if (file.exists()) return file.exists();
return 1;
fname.append('c');
file.setFileName(fname);
if (file.exists())
return 2;
return 0;
} }
PyObject *QtResGetCode(const char *name) PyObject *QtResGetCode(const char *name)
{ {
QFile moduleFile; QFile moduleFile;
bool isBytecode = false;
switch (QtResExists(name, moduleFile)) { if (!QtResExists(name, moduleFile)) {
case 0:
return nullptr; return nullptr;
case 2:
isBytecode = true;
} }
moduleFile.open(QIODevice::ReadOnly); moduleFile.open(QIODevice::ReadOnly);
QByteArray data = moduleFile.readAll(); QByteArray data = moduleFile.readAll();
moduleFile.close(); moduleFile.close();
PyObject *codeObject; PyObject *codeObject = Py_CompileString(data.constData(),
if (isBytecode) { moduleFile.fileName().toLocal8Bit().constData(),
codeObject = PyMarshal_ReadObjectFromString(data.constData() + 12, Py_file_input);
data.size() - 12);
} else {
codeObject = Py_CompileString(data.constData(),
moduleFile.fileName().toLocal8Bit().constData(),
Py_file_input);
}
if (!codeObject) { if (!codeObject) {
qWarning() << "Couldn't unmarshal/compile " << moduleFile.fileName(); qWarning() << "Couldn't compile " << moduleFile.fileName();
} }
return codeObject; return codeObject;
} }

View File

@ -101,6 +101,7 @@ cpp = meson.get_compiler('cpp')
if host_machine.system() == 'windows' if host_machine.system() == 'windows'
add_project_arguments('-D_CRT_NONSTDC_NO_DEPRECATE', language: 'cpp') add_project_arguments('-D_CRT_NONSTDC_NO_DEPRECATE', language: 'cpp')
add_project_arguments('-D_CRT_SECURE_NO_WARNINGS', 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 endif
cutter_exe = executable( cutter_exe = executable(