From d6a7efc26698fbc9f789dedab49398f4cff53af1 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Sun, 5 Dec 2021 03:42:45 -0600 Subject: [PATCH] Changes to compile with Qt6 + Boost 1.77 --- src/runner/converters.h | 22 +++++------ src/runner/pythonrunner.cpp | 2 +- src/runner/sipapiaccess.cpp | 79 +------------------------------------ 3 files changed, 13 insertions(+), 90 deletions(-) diff --git a/src/runner/converters.h b/src/runner/converters.h index 3700503..b83d218 100644 --- a/src/runner/converters.h +++ b/src/runner/converters.h @@ -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*)data)->storage.bytes; new (storage) Enum(static_cast(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>*)data)->storage.bytes; new (storage) QFlags(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(objPtr)(), data); } - else if (SIPBytes_Check(objPtr) || PyUnicode_Check(objPtr)) { + else if (PyBytes_Check(objPtr) || PyUnicode_Check(objPtr)) { constructVariant(bpy::extract(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(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(objPtr)(), data); diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 83dc9e7..4c6dc01 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -112,7 +112,7 @@ BOOST_PYTHON_MODULE(mobase) utils::register_sequence_container>(); utils::register_sequence_container>(); utils::register_sequence_container>(); - utils::register_sequence_container>(); + //utils::register_sequence_container>(); utils::register_sequence_container(); utils::register_sequence_container>(); utils::register_sequence_container>(); diff --git a/src/runner/sipapiaccess.cpp b/src/runner/sipapiaccess.cpp index b93d6f3..b2bceee 100644 --- a/src/runner/sipapiaccess.cpp +++ b/src/runner/sipapiaccess.cpp @@ -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 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 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); } \ No newline at end of file