Changes to compile with Qt6 + Boost 1.77

This commit is contained in:
Jeremy Rimpo
2021-12-05 03:42:45 -06:00
parent 071498f305
commit d6a7efc266
3 changed files with 13 additions and 90 deletions
+11 -11
View File
@@ -29,7 +29,7 @@ namespace utils {
// It's safer to explicitly convert to unicode as if we don't, this can return
// either str or unicode without it being easy to know which to expect
bpy::object pyStr = bpy::object(qUtf8Printable(str));
if (SIPBytes_Check(pyStr.ptr()))
if (PyBytes_Check(pyStr.ptr()))
pyStr = pyStr.attr("decode")("utf-8");
return bpy::incref(pyStr.ptr());
}
@@ -39,7 +39,7 @@ namespace utils {
{
static void* convertible(PyObject* objPtr) {
return SIPBytes_Check(objPtr) || PyUnicode_Check(objPtr) ? objPtr : nullptr;
return PyBytes_Check(objPtr) || PyUnicode_Check(objPtr) ? objPtr : nullptr;
}
static void construct(PyObject* objPtr, bpy::converter::rvalue_from_python_stage1_data* data) {
@@ -47,7 +47,7 @@ namespace utils {
PyObject* strPtr = PyUnicode_Check(objPtr) ? PyUnicode_AsUTF8String(objPtr) : objPtr;
// Extract the character data from the python string
const char* value = SIPBytes_AsString(strPtr);
const char* value = PyBytes_AsString(strPtr);
assert(value != nullptr);
// allocate storage
@@ -84,11 +84,11 @@ namespace utils {
{
static void* convertible(PyObject* objPtr) {
return SIPLong_Check(objPtr) ? objPtr : nullptr;
return PyLong_Check(objPtr) ? objPtr : nullptr;
}
static void construct(PyObject* objPtr, bpy::converter::rvalue_from_python_stage1_data* data) {
int intVersion = (int)SIPLong_AsLong(objPtr);
int intVersion = (int)PyLong_AsLong(objPtr);
void* storage = ((bpy::converter::rvalue_from_python_storage<Enum>*)data)->storage.bytes;
new (storage) Enum(static_cast<Enum>(intVersion));
data->convertible = storage;
@@ -115,11 +115,11 @@ namespace utils {
{
static void* convertible(PyObject* objPtr) {
return SIPLong_Check(objPtr) ? objPtr : nullptr;
return PyLong_Check(objPtr) ? objPtr : nullptr;
}
static void construct(PyObject* objPtr, bpy::converter::rvalue_from_python_stage1_data* data) {
int intVersion = (int)SIPLong_AsLong(objPtr);
int intVersion = (int)PyLong_AsLong(objPtr);
T tVersion = (T)intVersion;
void* storage = ((bpy::converter::rvalue_from_python_storage<QFlags<T>>*)data)->storage.bytes;
new (storage) QFlags<T>(tVersion);
@@ -137,7 +137,7 @@ namespace utils {
static PyObject* convert(const QVariant& var) {
switch (var.type()) {
case QVariant::Invalid: return bpy::incref(Py_None);
case QVariant::Int: return SIPLong_FromLong(var.toInt());
case QVariant::Int: return PyLong_FromLong(var.toInt());
case QVariant::UInt: return PyLong_FromUnsignedLong(var.toUInt());
case QVariant::Bool: return PyBool_FromLong(var.toBool());
case QVariant::String: return bpy::incref(bpy::object(var.toString()).ptr());
@@ -162,7 +162,7 @@ namespace utils {
{
static void* convertible(PyObject* objPtr) {
if (!SIPBytes_Check(objPtr) && !PyUnicode_Check(objPtr) && !PyLong_Check(objPtr) &&
if (!PyBytes_Check(objPtr) && !PyUnicode_Check(objPtr) && !PyLong_Check(objPtr) &&
!PyBool_Check(objPtr) && !PyList_Check(objPtr) && !PyDict_Check(objPtr) &&
objPtr != Py_None) {
return nullptr;
@@ -199,7 +199,7 @@ namespace utils {
else if (PyDict_Check(objPtr)) {
constructVariant(bpy::extract<QVariantMap>(objPtr)(), data);
}
else if (SIPBytes_Check(objPtr) || PyUnicode_Check(objPtr)) {
else if (PyBytes_Check(objPtr) || PyUnicode_Check(objPtr)) {
constructVariant(bpy::extract<QString>(objPtr)(), data);
}
// PyBools will also return true for SIPLong_Check but not the other way around, so the order
@@ -207,7 +207,7 @@ namespace utils {
else if (PyBool_Check(objPtr)) {
constructVariant(bpy::extract<bool>(objPtr)(), data);
}
else if (SIPLong_Check(objPtr)) {
else if (PyLong_Check(objPtr)) {
// QVariant doesn't have long. It has int or long long. Given that on m/s,
// long is 32 bits for 32- and 64- bit code...
constructVariant(bpy::extract<int>(objPtr)(), data);
+1 -1
View File
@@ -112,7 +112,7 @@ BOOST_PYTHON_MODULE(mobase)
utils::register_sequence_container<QList<ExecutableInfo>>();
utils::register_sequence_container<QList<ExecutableForcedLoadSetting>>();
utils::register_sequence_container<QList<PluginSetting>>();
utils::register_sequence_container<QList<ModRepositoryFileInfo>>();
//utils::register_sequence_container<QList<ModRepositoryFileInfo>>();
utils::register_sequence_container<QStringList>();
utils::register_sequence_container<QList<QString>>();
utils::register_sequence_container<QList<QFileInfo>>();
+1 -78
View File
@@ -5,82 +5,5 @@
const sipAPIDef* sipAPIAccess::sipAPI()
{
QString exception;
static const sipAPIDef* sipApi = nullptr;
if (sipApi == nullptr) {
#if defined(SIP_USE_PYCAPSULE)
PyImport_ImportModule("PyQt5.sip");
auto errorObj = PyErr_Occurred();
if (errorObj != NULL) {
PyObject* type, * value, * traceback;
PyErr_Fetch(&type, &value, &traceback);
PyErr_NormalizeException(&type, &value, &traceback);
if (traceback != NULL) {
boost::python::handle<> h_type(type);
boost::python::handle<> h_val(value);
boost::python::handle<> h_tb(traceback);
boost::python::object tb(boost::python::import("traceback"));
boost::python::object fmt_exp(tb.attr("format_exception"));
boost::python::object exp_list(fmt_exp(h_type, h_val, h_tb));
boost::python::object exp_str(boost::python::str("\n").join(exp_list));
boost::python::extract<std::string> returned(exp_str);
exception = QString::fromStdString(returned());
}
PyErr_Restore(type, value, traceback);
throw MOBase::Exception(QString("Failed to load PyQt5: %1").arg(exception));
}
sipApi = (const sipAPIDef*)PyCapsule_Import("PyQt5.sip._C_API", 0);
if (sipApi == NULL) {
auto errorObj = PyErr_Occurred();
if (errorObj != NULL) {
PyObject* type, * value, * traceback;
PyErr_Fetch(&type, &value, &traceback);
PyErr_NormalizeException(&type, &value, &traceback);
if (traceback != NULL) {
boost::python::handle<> h_type(type);
boost::python::handle<> h_val(value);
boost::python::handle<> h_tb(traceback);
boost::python::object tb(boost::python::import("traceback"));
boost::python::object fmt_exp(tb.attr("format_exception"));
boost::python::object exp_list(fmt_exp(h_type, h_val, h_tb));
boost::python::object exp_str(boost::python::str("\n").join(exp_list));
boost::python::extract<std::string> returned(exp_str);
exception = QString::fromStdString(returned());
}
PyErr_Restore(type, value, traceback);
}
throw MOBase::Exception(QString("Failed to load SIP API: %1").arg(exception));
}
#else
PyObject* sip_module;
PyObject* sip_module_dict;
PyObject* c_api;
/* Import the SIP module. */
sip_module = PyImport_ImportModule("PyQt5.sip");
if (sip_module == NULL)
return NULL;
/* Get the module's dictionary. */
sip_module_dict = PyModule_GetDict(sip_module);
/* Get the "_C_API" attribute. */
c_api = PyDict_GetItemString(sip_module_dict, "_C_API");
if (c_api == NULL)
return NULL;
/* Sanity check that it is the right type. */
if (!PyCObject_Check(c_api))
return NULL;
/* Get the actual pointer from the object. */
sipApi = (const sipAPIDef*)PyCObject_AsVoidPtr(c_api);
#endif
}
return sipApi;
return (const sipAPIDef*)PyCapsule_Import("sip._C_API", 0);
}