From 7edf591515e81be767ee1d0d073b9b32e6ebe0be Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sun, 1 Jan 2023 18:04:40 +0100 Subject: [PATCH 1/8] Replace NULL with nullptr --- src/PythonQt.cpp | 159 +++++++++--------- src/PythonQt.h | 24 +-- src/PythonQtBoolResult.cpp | 134 ++++++++-------- src/PythonQtClassInfo.cpp | 63 ++++---- src/PythonQtClassInfo.h | 30 ++-- src/PythonQtClassWrapper.cpp | 134 ++++++++-------- src/PythonQtConversion.cpp | 48 +++--- src/PythonQtConversion.h | 24 +-- src/PythonQtImporter.cpp | 150 +++++++++-------- src/PythonQtInstanceWrapper.cpp | 232 +++++++++++++-------------- src/PythonQtInstanceWrapper.h | 2 +- src/PythonQtMethodInfo.cpp | 6 +- src/PythonQtMethodInfo.h | 16 +- src/PythonQtMisc.cpp | 10 +- src/PythonQtObjectPtr.cpp | 6 +- src/PythonQtObjectPtr.h | 34 ++-- src/PythonQtProperty.cpp | 98 +++++------ src/PythonQtProperty.h | 12 +- src/PythonQtSignal.cpp | 120 +++++++------- src/PythonQtSignalReceiver.cpp | 8 +- src/PythonQtSignalReceiver.h | 4 +- src/PythonQtSlot.cpp | 146 +++++++++-------- src/PythonQtSlot.h | 2 +- src/PythonQtSlotDecorator.cpp | 86 +++++----- src/PythonQtStdDecorators.cpp | 18 +-- src/PythonQtStdDecorators.h | 4 +- src/PythonQtStdIn.cpp | 78 ++++----- src/PythonQtStdOut.cpp | 76 ++++----- src/PythonQtThreadSupport.h | 2 +- src/gui/PythonQtScriptingConsole.cpp | 2 +- 30 files changed, 860 insertions(+), 868 deletions(-) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 3c091bd0b..cd1001ff4 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -61,7 +61,7 @@ #include #include -PythonQt* PythonQt::_self = NULL; +PythonQt* PythonQt::_self = nullptr; int PythonQt::_uniqueModuleCount = 0; void PythonQt_init_QtGuiBuiltin(PyObject*); @@ -196,11 +196,11 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName) PythonQtRegisterIntegerMapConverter(QHash, QString); PythonQtMethodInfo::addParameterTypeAlias("QHash", "QHash"); - PythonQt_init_QtCoreBuiltin(NULL); - PythonQt_init_QtGuiBuiltin(NULL); + PythonQt_init_QtCoreBuiltin(nullptr); + PythonQt_init_QtGuiBuiltin(nullptr); PythonQt::self()->addDecorators(new PythonQtStdDecorators()); - PythonQt::self()->registerCPPClass("QMetaObject",0, "QtCore", PythonQtCreateObject); + PythonQt::self()->registerCPPClass("QMetaObject",nullptr, "QtCore", PythonQtCreateObject); PythonQtRegisterToolClassesTemplateConverterForKnownClass(QByteArray); PythonQtRegisterToolClassesTemplateConverterForKnownClass(QDate); @@ -289,7 +289,7 @@ void PythonQt::cleanup() { if (_self) { delete _self; - _self = NULL; + _self = nullptr; } } @@ -378,12 +378,12 @@ PythonQt::PythonQt(int flags, const QByteArray& pythonQtModuleName) PythonQt::~PythonQt() { delete _p; - _p = NULL; + _p = nullptr; } PythonQtPrivate::~PythonQtPrivate() { delete _defaultImporter; - _defaultImporter = NULL; + _defaultImporter = nullptr; { QHashIterator i(_knownClassInfos); @@ -412,7 +412,7 @@ void PythonQt::setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * PyObject_SetAttrString(sys.object(), "pythonqt_original_stdin", PyObject_GetAttrString(sys.object(), "stdin")); } - in = PythonQtStdInRedirectType.tp_new(&PythonQtStdInRedirectType, NULL, NULL); + in = PythonQtStdInRedirectType.tp_new(&PythonQtStdInRedirectType, nullptr, nullptr); ((PythonQtStdInRedirect*)in.object())->_cb = callback; ((PythonQtStdInRedirect*)in.object())->_callData = callbackData; // replace the built in file objects with our own objects @@ -448,7 +448,7 @@ void PythonQt::qObjectNoLongerWrappedCB(QObject* o) { if (_self->_p->_noLongerWrappedCB) { (*_self->_p->_noLongerWrappedCB)(o); - }; + } } void PythonQt::setQObjectMissingAttributeCallback(PythonQtQObjectMissingAttributeCB* cb) @@ -548,12 +548,12 @@ PyObject* PythonQtPrivate::wrapQObject(QObject* obj) // address, so probably that C++ wrapper has been deleted earlier and // now we see a QObject with the same address. // Do not use the old wrapper anymore. - wrap = NULL; + wrap = nullptr; } if (!wrap) { // smuggling it in... PythonQtClassInfo* classInfo = _knownClassInfos.value(obj->metaObject()->className()); - if (!classInfo || classInfo->pythonQtClassWrapper()==NULL) { + if (!classInfo || classInfo->pythonQtClassWrapper()==nullptr) { registerClass(obj->metaObject()); classInfo = _knownClassInfos.value(obj->metaObject()->className()); } @@ -574,7 +574,7 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO } PythonQtInstanceWrapper* wrap = findWrapperAndRemoveUnused(ptr); - PythonQtInstanceWrapper* possibleStillAliveWrapper = NULL; + PythonQtInstanceWrapper* possibleStillAliveWrapper = nullptr; if (wrap && wrap->_wrappedPtr) { // we have a previous C++ wrapper... if the wrapper is for a C++ object, // we are not sure if it may have been deleted earlier and we just see the same C++ @@ -582,7 +582,7 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO // we compare the classInfo() pointer and only reuse the wrapper if it has the same // info. This is only needed for non-QObjects, since we know it when a QObject gets deleted. possibleStillAliveWrapper = wrap; - wrap = NULL; + wrap = nullptr; } if (!wrap) { PythonQtClassInfo* info = getClassInfo(name); @@ -607,7 +607,7 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO // if the object is a derived object, we want to switch the class info to the one of the derived class: if (name!=(qptr->metaObject()->className())) { info = _knownClassInfos.value(qptr->metaObject()->className()); - if (!info || (info->pythonQtClassWrapper() == NULL)) { + if (!info || (info->pythonQtClassWrapper() == nullptr)) { registerClass(qptr->metaObject()); info = _knownClassInfos.value(qptr->metaObject()->className()); } @@ -619,7 +619,7 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO } // not a known QObject, try to wrap via foreign wrapper factories - PyObject* foreignWrapper = NULL; + PyObject* foreignWrapper = nullptr; for (int i=0; i<_foreignWrapperFactories.size(); i++) { foreignWrapper = _foreignWrapperFactories.at(i)->wrap(name, ptr); if (foreignWrapper) { @@ -628,7 +628,7 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO } // not a known QObject, so try our wrapper factory: - QObject* wrapper = NULL; + QObject* wrapper = nullptr; for (int i=0; i<_cppWrapperFactories.size(); i++) { wrapper = _cppWrapperFactories.at(i)->create(name, ptr); if (wrapper) { @@ -656,7 +656,7 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO } } - if (!info || info->pythonQtClassWrapper()==NULL) { + if (!info || info->pythonQtClassWrapper()==nullptr) { // still unknown, register as CPP class registerCPPClass(name.constData()); info = _knownClassInfos.value(name); @@ -682,8 +682,8 @@ PyObject* PythonQtPrivate::wrapPtr(void* ptr, const QByteArray& name, bool passO } PyObject* PythonQtPrivate::dummyTuple() { - static PyObject* dummyTuple = NULL; - if (dummyTuple==NULL) { + static PyObject* dummyTuple = nullptr; + if (dummyTuple==nullptr) { dummyTuple = PyTuple_New(1); PyTuple_SET_ITEM(dummyTuple, 0 , PyString_FromString("dummy")); } @@ -693,7 +693,7 @@ PyObject* PythonQtPrivate::dummyTuple() { PythonQtInstanceWrapper* PythonQtPrivate::createNewPythonQtInstanceWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr) { // call the associated class type to create a new instance... - PythonQtInstanceWrapper* result = (PythonQtInstanceWrapper*)PyObject_Call(info->pythonQtClassWrapper(), dummyTuple(), NULL); + PythonQtInstanceWrapper* result = (PythonQtInstanceWrapper*)PyObject_Call(info->pythonQtClassWrapper(), dummyTuple(), nullptr); result->setQObject(obj); result->_wrappedPtr = wrappedPtr; @@ -712,7 +712,7 @@ PythonQtInstanceWrapper* PythonQtPrivate::createNewPythonQtInstanceWrapper(QObje _wrappedObjects.insert(wrappedPtr, result); } else { _wrappedObjects.insert(obj, result); - if (obj->parent()== NULL && _wrappedCB) { + if (obj->parent()== nullptr && _wrappedCB) { // tell someone who is interested that the qobject is wrapped the first time, if it has no parent (*_wrappedCB)(obj); } @@ -739,7 +739,7 @@ PythonQtClassWrapper* PythonQtPrivate::createNewPythonQtClassWrapper(PythonQtCla // set the class info so that PythonQtClassWrapper_new can read it _currentClassInfoForClassWrapperCreation = info; // create the new type object by calling the type - result = (PythonQtClassWrapper *)PyObject_Call((PyObject *)&PythonQtClassWrapper_Type, args, NULL); + result = (PythonQtClassWrapper *)PyObject_Call((PyObject *)&PythonQtClassWrapper_Type, args, nullptr); Py_DECREF(baseClasses); Py_DECREF(typeDict); @@ -752,7 +752,7 @@ PythonQtClassWrapper* PythonQtPrivate::createNewPythonQtClassWrapper(PythonQtCla PyObject* PythonQtPrivate::createEnumValueInstance(PyObject* enumType, unsigned int enumValue) { PyObject* args = Py_BuildValue("(i)", enumValue); - PyObject* result = PyObject_Call(enumType, args, NULL); + PyObject* result = PyObject_Call(enumType, args, nullptr); Py_DECREF(args); return result; } @@ -773,7 +773,7 @@ PyObject* PythonQtPrivate::createNewPythonQtEnumWrapper(const char* enumName, Py PyObject* args = Py_BuildValue("OOO", className, baseClasses, typeDict); // create the new int derived type object by calling the core type - result = PyObject_Call((PyObject *)&PyType_Type, args, NULL); + result = PyObject_Call((PyObject *)&PyType_Type, args, nullptr); Py_DECREF(baseClasses); Py_DECREF(typeDict); @@ -853,7 +853,7 @@ PythonQtObjectPtr PythonQt::lookupCallable(PyObject* module, const QString& name } } PyErr_Clear(); - return NULL; + return nullptr; } PythonQtObjectPtr PythonQt::lookupObject(PyObject* module, const QString& name) @@ -893,8 +893,8 @@ QVariant PythonQt::evalCode(PyObject* object, PyObject* pycode) { QVariant result; clearError(); if (pycode) { - PyObject* dict = NULL; - PyObject* globals = NULL; + PyObject* dict = nullptr; + PyObject* globals = nullptr; if (PyModule_Check(object)) { dict = PyModule_GetDict(object); globals = dict; @@ -905,7 +905,7 @@ QVariant PythonQt::evalCode(PyObject* object, PyObject* pycode) { dict = PyObject_GetAttrString(object, "__dict__"); globals = PyObject_GetAttrString(PyImport_ImportModule(PyString_AS_STRING(PyObject_GetAttrString(object, "__module__"))),"__dict__"); } - PyObject* r = NULL; + PyObject* r = nullptr; if (dict) { #ifdef PY3K r = PyEval_EvalCode(pycode, globals, dict); @@ -929,7 +929,7 @@ QVariant PythonQt::evalScript(PyObject* object, const QString& script, int start { QVariant result; PythonQtObjectPtr p; - PyObject* dict = NULL; + PyObject* dict = nullptr; clearError(); if (PyModule_Check(object)) { dict = PyModule_GetDict(object); @@ -990,7 +990,7 @@ PythonQtObjectPtr PythonQt::parseFileWithPythonLoaders(const QString& file) { PythonQtObjectPtr result; QString filename = file; - PyObject* loaderClass = NULL; + PyObject* loaderClass = nullptr; if (QFile::exists(filename)) { loaderClass = _p->_pySourceFileLoader; } else { @@ -1159,7 +1159,7 @@ QStringList PythonQt::introspectObject(PyObject* object, ObjectType type) } } } else { - PyObject* keys = NULL; + PyObject* keys = nullptr; bool isDict = false; if (PyDict_Check(object)) { keys = PyDict_Keys(object); @@ -1253,7 +1253,7 @@ PyObject* PythonQt::getObjectByType(const QString& typeName) QString simpleTypeName = tmp.takeLast(); QString moduleName = tmp.join("."); - PyObject* object = NULL; + PyObject* object = nullptr; PyObject* moduleObject = PyDict_GetItemString(modules, QStringToPythonCharPointer(moduleName)); if (moduleObject) { object = PyObject_GetAttrString(moduleObject, QStringToPythonCharPointer(simpleTypeName)); @@ -1324,7 +1324,7 @@ QVariant PythonQt::call(PyObject* callable, const QVariantList& args, const QVar PyObject* PythonQt::callAndReturnPyObject(PyObject* callable, const QVariantList& args, const QVariantMap& kwargs) { - PyObject* result = NULL; + PyObject* result = nullptr; if (callable) { bool err = false; PythonQtObjectPtr pargs; @@ -1424,13 +1424,13 @@ void PythonQt::addWrapperFactory( PythonQtForeignWrapperFactory* factory ) //--------------------------------------------------------------------------------------------------- PythonQtPrivate::PythonQtPrivate() { - _importInterface = NULL; + _importInterface = nullptr; _defaultImporter = new PythonQtQFileImporter; - _noLongerWrappedCB = NULL; - _wrappedCB = NULL; - _qObjectMissingAttribCB = NULL; - _currentClassInfoForClassWrapperCreation = NULL; - _profilingCB = NULL; + _noLongerWrappedCB = nullptr; + _wrappedCB = nullptr; + _qObjectMissingAttribCB = nullptr; + _currentClassInfoForClassWrapperCreation = nullptr; + _profilingCB = nullptr; _hadError = false; _systemExitExceptionHandlerEnabled = false; _debugAPI = new PythonQtDebugAPI(this); @@ -1465,7 +1465,7 @@ void PythonQtPrivate::setupSharedLibrarySuffixes() PythonQtClassInfo* PythonQtPrivate::currentClassInfoForClassWrapperCreation() { PythonQtClassInfo* info = _currentClassInfoForClassWrapperCreation; - _currentClassInfoForClassWrapperCreation = NULL; + _currentClassInfoForClassWrapperCreation = nullptr; return info; } @@ -1480,12 +1480,12 @@ void PythonQtPrivate::addDecorators(QObject* o, int decoTypes) m.methodType() == QMetaMethod::Slot) && m.access() == QMetaMethod::Public) { if (signature.startsWith("new_")) { if ((decoTypes & ConstructorDecorator) == 0) continue; - const PythonQtMethodInfo* info = PythonQtMethodInfo::getCachedMethodInfo(m, NULL); + const PythonQtMethodInfo* info = PythonQtMethodInfo::getCachedMethodInfo(m, nullptr); if (info->parameters().at(0).pointerCount == 1) { QByteArray nameOfClass = signature.mid(4); nameOfClass.replace("__", "::"); PythonQtClassInfo* classInfo = lookupClassInfoAndCreateIfNotPresent(nameOfClass); - PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(NULL, m, i, o, PythonQtSlotInfo::ClassDecorator); + PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(nullptr, m, i, o, PythonQtSlotInfo::ClassDecorator); classInfo->addConstructor(newSlot); } } else if (signature.startsWith("delete_")) { @@ -1493,23 +1493,23 @@ void PythonQtPrivate::addDecorators(QObject* o, int decoTypes) QByteArray nameOfClass = signature.mid(7); nameOfClass.replace("__", "::"); PythonQtClassInfo* classInfo = lookupClassInfoAndCreateIfNotPresent(nameOfClass); - PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(NULL, m, i, o, PythonQtSlotInfo::ClassDecorator); + PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(nullptr, m, i, o, PythonQtSlotInfo::ClassDecorator); classInfo->setDestructor(newSlot); } else if (signature.startsWith("static_")) { if ((decoTypes & StaticDecorator) == 0) continue; QByteArray nameOfClass = signature.mid(7); nameOfClass = nameOfClass.mid(0, nameOfClass.indexOf('_')); PythonQtClassInfo* classInfo = lookupClassInfoAndCreateIfNotPresent(nameOfClass); - PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(NULL, m, i, o, PythonQtSlotInfo::ClassDecorator); + PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(nullptr, m, i, o, PythonQtSlotInfo::ClassDecorator); classInfo->addDecoratorSlot(newSlot); } else { if ((decoTypes & InstanceDecorator) == 0) continue; - const PythonQtMethodInfo* info = PythonQtMethodInfo::getCachedMethodInfo(m, NULL); + const PythonQtMethodInfo* info = PythonQtMethodInfo::getCachedMethodInfo(m, nullptr); if (info->parameters().count()>1) { PythonQtMethodInfo::ParameterInfo p = info->parameters().at(1); if (p.pointerCount==1) { PythonQtClassInfo* classInfo = lookupClassInfoAndCreateIfNotPresent(p.name); - PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(NULL, m, i, o, PythonQtSlotInfo::InstanceDecorator); + PythonQtSlotInfo* newSlot = new PythonQtSlotInfo(nullptr, m, i, o, PythonQtSlotInfo::InstanceDecorator); classInfo->addDecoratorSlot(newSlot); } } @@ -1566,7 +1566,7 @@ int custom_system_exit_exception_handler() // TODO: unclear what to do, since Py_FlushLine is gone... #endif fflush(stdout); - if (value == NULL || value == Py_None) + if (value == nullptr || value == Py_None) goto done; if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ @@ -1584,7 +1584,7 @@ int custom_system_exit_exception_handler() exitcode = (int)PyInt_AsLong(value); else { PyObject *sys_stderr = PySys_GetObject(const_cast("stderr")); - if (sys_stderr != NULL && sys_stderr != Py_None) { + if (sys_stderr != nullptr && sys_stderr != Py_None) { PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW); } else { PyObject_Print(value, stderr, Py_PRINT_RAW); @@ -1625,7 +1625,7 @@ bool PythonQt::handleError(bool printStack) PyErr_Fetch(&ptype, &pvalue, &ptraceback); PyErr_NormalizeException(&ptype, &pvalue, &ptraceback); // we leave out the traceback: - PyErr_Display(ptype, pvalue, NULL); + PyErr_Display(ptype, pvalue, nullptr); PyErr_Restore(ptype, pvalue, ptraceback); PyErr_Clear(); } @@ -1725,20 +1725,20 @@ void PythonQt::setEnableThreadSupport(bool flag) } static PyMethodDef PythonQtMethods[] = { - {NULL, NULL, 0, NULL} + {nullptr, nullptr, 0, nullptr} }; #ifdef PY3K static PyModuleDef PythonQtModuleDef = { PyModuleDef_HEAD_INIT, "", - NULL, + nullptr, -1, PythonQtMethods, - NULL, - NULL, - NULL, - NULL + nullptr, + nullptr, + nullptr, + nullptr }; #endif @@ -1765,9 +1765,9 @@ void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQ PythonQtObjectPtr out; PythonQtObjectPtr err; // create a redirection object for stdout and stderr - out = PythonQtStdOutRedirectType.tp_new(&PythonQtStdOutRedirectType,NULL, NULL); + out = PythonQtStdOutRedirectType.tp_new(&PythonQtStdOutRedirectType,nullptr, nullptr); ((PythonQtStdOutRedirect*)out.object())->_cb = stdOutRedirectCB; - err = PythonQtStdOutRedirectType.tp_new(&PythonQtStdOutRedirectType,NULL, NULL); + err = PythonQtStdOutRedirectType.tp_new(&PythonQtStdOutRedirectType,nullptr, nullptr); ((PythonQtStdOutRedirect*)err.object())->_cb = stdErrRedirectCB; // replace the built in file objects with our own objects PyModule_AddObject(sys, "stdout", out); @@ -1954,7 +1954,7 @@ void PythonQtPrivate::registerCPPClass(const char* typeName, const char* parentT PyObject* PythonQtPrivate::packageByName(const char* name) { - if (name==NULL || name[0]==0) { + if (name==nullptr || name[0]==0) { name = "private"; } PyObject* v = _packages.value(name); @@ -2015,13 +2015,13 @@ void PythonQtPrivate::addWrapperPointer(void* obj, PythonQtInstanceWrapper* wrap PythonQtInstanceWrapper* PythonQtPrivate::findWrapperAndRemoveUnused(void* obj) { PythonQtInstanceWrapper* wrap = _wrappedObjects.value(obj); - if (wrap && !wrap->_wrappedPtr && wrap->_obj == NULL) { + if (wrap && !wrap->_wrappedPtr && wrap->_obj == nullptr) { // this is a wrapper whose QObject was already removed due to destruction // so the obj pointer has to be a new QObject with the same address... // we remove the old one and set the copy to NULL - wrap->_objPointerCopy = NULL; + wrap->_objPointerCopy = nullptr; removeWrapperPointer(obj); - wrap = NULL; + wrap = nullptr; } return wrap; } @@ -2040,14 +2040,14 @@ PythonQtObjectPtr PythonQtPrivate::createModule(const QString& name, PyObject* p void* PythonQtPrivate::unwrapForeignWrapper( const QByteArray& classname, PyObject* obj ) { - void* foreignObject = NULL; + void* foreignObject = nullptr; for (int i=0; i<_foreignWrapperFactories.size(); i++) { foreignObject = _foreignWrapperFactories.at(i)->unwrap(classname, obj); if (foreignObject) { return foreignObject; } } - return NULL; + return nullptr; } bool PythonQtPrivate::isMethodDescriptor(PyObject* object) const @@ -2105,9 +2105,9 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper* builder.setClassName(((PyTypeObject*)type)->tp_name); PyObject* dict = ((PyTypeObject*)type)->tp_dict; - Py_ssize_t pos = NULL; - PyObject* value = NULL; - PyObject* key = NULL; + Py_ssize_t pos = 0; + PyObject* value = nullptr; + PyObject* key = nullptr; static PyObject* qtSlots = PyString_FromString("_qtSlots"); bool needsMetaObject = false; @@ -2126,9 +2126,9 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper* } } } - pos = NULL; - value = NULL; - key = NULL; + pos = 0; + value = nullptr; + key = nullptr; // Now look for slots: (this is a bug in QMetaObjectBuilder, all signals need to be added first) while (PyDict_Next(dict, &pos, &key, &value)) { if (PythonQtProperty_Check(value)) { @@ -2136,8 +2136,8 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper* PythonQtProperty* prop = (PythonQtProperty*)value; QMetaPropertyBuilder newProp = builder.addProperty(PyString_AsString(key), prop->data->cppType); newProp.setReadable(true); - newProp.setWritable(prop->data->fset != NULL); - newProp.setResettable(prop->data->freset != NULL); + newProp.setWritable(prop->data->fset != nullptr); + newProp.setResettable(prop->data->freset != nullptr); newProp.setDesignable(prop->data->designable); newProp.setScriptable(prop->data->scriptable); newProp.setStored(prop->data->stored); @@ -2207,7 +2207,7 @@ int PythonQtPrivate::handleMetaCall(QObject* object, PythonQtInstanceWrapper* wr if (!metaProp.isValid()) { return id - methodCount; } - PythonQtProperty* prop = NULL; + PythonQtProperty* prop = nullptr; // Get directly from the Python class, since we don't want to get the value of the property PyObject* maybeProp = PyBaseObject_Type.tp_getattro((PyObject*)wrapper, PyString_FromString(metaProp.name())); if (maybeProp && PythonQtProperty_Check(maybeProp)) { @@ -2228,9 +2228,9 @@ int PythonQtPrivate::handleMetaCall(QObject* object, PythonQtInstanceWrapper* wr PyObject* value = prop->data->callGetter((PyObject*)wrapper); if (value) { - void* result = PythonQtConv::ConvertPythonToQt(info, value, false, NULL, args[0]); + void* result = PythonQtConv::ConvertPythonToQt(info, value, false, nullptr, args[0]); Py_DECREF(value); - return (result == NULL ? -1 : 0); + return (result == nullptr ? -1 : 0); } else { return -1; } @@ -2244,13 +2244,12 @@ int PythonQtPrivate::handleMetaCall(QObject* object, PythonQtInstanceWrapper* wr void PythonQtPrivate::callMethodInPython(QMetaMethod &method, PythonQtInstanceWrapper* wrapper, void** args) { - QByteArray methodSig = method.methodSignature(); PyObject* func = PyObject_GetAttrString((PyObject*)wrapper, method.name()); if (func) { - const PythonQtMethodInfo* methodInfo = PythonQtMethodInfo::getCachedMethodInfo(method, NULL); + const PythonQtMethodInfo* methodInfo = PythonQtMethodInfo::getCachedMethodInfo(method, nullptr); PyObject* result = PythonQtSignalTarget::call(func, methodInfo, args, false); if (result) { - PythonQtConv::ConvertPythonToQt(methodInfo->parameters().at(0), result, false, NULL, args[0]); + PythonQtConv::ConvertPythonToQt(methodInfo->parameters().at(0), result, false, nullptr, args[0]); // TODO: handle error? //PythonQt::priv()->handleVirtualOverloadReturnError("devType", methodInfo, result); } @@ -2264,8 +2263,8 @@ QString PythonQtPrivate::getSignature(PyObject* object) QString signature; if (object) { - PyMethodObject* method = NULL; - PyFunctionObject* func = NULL; + PyMethodObject* method = nullptr; + PyFunctionObject* func = nullptr; bool decrefMethod = false; @@ -2401,7 +2400,7 @@ void PythonQtPrivate::shellClassDeleted( void* shellClass ) if (wrap->_wrappedPtr) { // this is a pure C++ wrapper and the shell has gone, so we need // to set the _wrappedPtr to NULL on the wrapper - wrap->_wrappedPtr = NULL; + wrap->_wrappedPtr = nullptr; // and then we remove the wrapper, since the wrapped class is gone _wrappedObjects.remove(shellClass); } diff --git a/src/PythonQt.h b/src/PythonQt.h index 93e62c30d..0e54a66b1 100644 --- a/src/PythonQt.h +++ b/src/PythonQt.h @@ -144,7 +144,7 @@ template int PythonQtUpcastingOffset() { typedef QObject* PythonQtQObjectCreatorFunctionCB(); //! helper template to create a derived QObject class -template QObject* PythonQtCreateObject() { return new T(); }; +template QObject* PythonQtCreateObject() { return new T(); } //! Helper define to convert from QString to Python C-API #ifdef PY3K @@ -260,7 +260,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { //! Overwrite default handling of stdin using a custom callback. It internally backup //! the original 'sys.stdin' into 'sys.pythonqt_original_stdin' - void setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * callbackData = 0); + void setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * callbackData = nullptr); //! Enable or disable stdin custom callback. It resets 'sys.stdin' using either 'sys.pythonqt_stdin' //! or 'sys.pythonqt_original_stdin' @@ -319,7 +319,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { //! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well) /* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject, you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */ - void registerClass(const QMetaObject* metaobject, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL); + void registerClass(const QMetaObject* metaobject, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr); //! add a wrapper object for the given QMetaType typeName, also does an addClassDecorators() to add constructors for variants //! (ownership of wrapper is passed to PythonQt) @@ -329,7 +329,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { All slots that take a pointer to typeName as the first argument will be callable from Python on a variant object that contains such a type. */ - void registerCPPClass(const char* typeName, const char* parentTypeName = NULL, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL); + void registerCPPClass(const char* typeName, const char* parentTypeName = nullptr, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr); //! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes //! and it will register the classes when it first sees a pointer to such a derived class @@ -365,7 +365,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { //! evaluates the given script code and returns the result value QVariant evalScript(PyObject* object, const QString& script, int start = Py_file_input); - + //! evaluates the given script code in context of given globals and locals and returns the result value QVariant evalScript(const QString& script, PyObject* globals, PyObject* locals, int start); @@ -536,7 +536,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { //! the default importer allows to import files from anywhere QFile can read from, //! including the Qt resource system using ":". Keep in mind that you need to extend //! "sys.path" with ":" to be able to import from the Qt resources. - void installDefaultImporter() { setImporter(NULL); } + void installDefaultImporter() { setImporter(nullptr); } //! set paths that the importer should ignore void setImporterIgnorePaths(const QStringList& paths); @@ -719,7 +719,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { //! registers a QObject derived class to PythonQt (this is implicitly called by addObject as well) /* Since Qt4 does not offer a way to detect if a given classname is derived from QObject and thus has a QMetaObject, you MUST register all your QObject derived classes here when you want them to be detected in signal and slot calls */ - void registerClass(const QMetaObject* metaobject, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL, PyObject* module = NULL, int typeSlots = 0); + void registerClass(const QMetaObject* metaobject, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr, PyObject* module = nullptr, int typeSlots = 0); //! add a wrapper object for the given QMetaType typeName, also does an addClassDecorators() to add constructors for variants //! (ownership of wrapper is passed to PythonQt) @@ -729,7 +729,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { All slots that take a pointer to typeName as the first argument will be callable from Python on a variant object that contains such a type. */ - void registerCPPClass(const char* typeName, const char* parentTypeName = NULL, const char* package = NULL, PythonQtQObjectCreatorFunctionCB* wrapperCreator = NULL, PythonQtShellSetInstanceWrapperCB* shell = NULL, PyObject* module = NULL, int typeSlots = 0); + void registerCPPClass(const char* typeName, const char* parentTypeName = nullptr, const char* package = nullptr, PythonQtQObjectCreatorFunctionCB* wrapperCreator = nullptr, PythonQtShellSetInstanceWrapperCB* shell = nullptr, PyObject* module = nullptr, int typeSlots = 0); //! as an alternative to registerClass, you can tell PythonQt the names of QObject derived classes //! and it will register the classes when it first sees a pointer to such a derived class @@ -748,7 +748,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { static PyObject* createNewPythonQtEnumWrapper(const char* enumName, PyObject* parentObject); //! helper method that creates a PythonQtInstanceWrapper object and registers it in the object map - PythonQtInstanceWrapper* createNewPythonQtInstanceWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr = NULL); + PythonQtInstanceWrapper* createNewPythonQtInstanceWrapper(QObject* obj, PythonQtClassInfo* info, void* wrappedPtr = nullptr); //! get the class info for a meta object (if available) PythonQtClassInfo* getClassInfo(const QMetaObject* meta); @@ -787,13 +787,13 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { //! get the dynamic meta object for the given wrapper. It will contain the signals/slots that have been added in Python const QMetaObject* getDynamicMetaObject(PythonQtInstanceWrapper* wrapper, const QMetaObject* prototypeMetaObject); - //! recursively creates the dynamic meta object chain down to the Qt class wrapper. + //! recursively creates the dynamic meta object chain down to the Qt class wrapper. const QMetaObject* setupDynamicMetaObjectChain(PythonQtClassWrapper* type, const QMetaObject* prototypeMetaObject); //! builds and returns the dynamic meta object for the given type, derived from prototypeMetaObject. const QMetaObject* buildDynamicMetaObject(PythonQtClassWrapper* type, const QMetaObject* prototypeMetaObject); - //! redirected from shell classes, tries to call the given meta call on the Python wrapper. + //! redirected from shell classes, tries to call the given meta call on the Python wrapper. int handleMetaCall(QObject* object, PythonQtInstanceWrapper* wrapper, QMetaObject::Call call, int id, void** args); //! calls the given method on Python function with same name. @@ -804,7 +804,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { void setupSharedLibrarySuffixes(); //! create a new pythonqt class wrapper and place it in the pythonqt module - void createPythonQtClassWrapper(PythonQtClassInfo* info, const char* package, PyObject* module = NULL); + void createPythonQtClassWrapper(PythonQtClassInfo* info, const char* package, PyObject* module = nullptr); //! get/create new package module (the returned object is a borrowed reference) PyObject* packageByName(const char* name); diff --git a/src/PythonQtBoolResult.cpp b/src/PythonQtBoolResult.cpp index 4d4ac1859..57c450576 100644 --- a/src/PythonQtBoolResult.cpp +++ b/src/PythonQtBoolResult.cpp @@ -66,54 +66,54 @@ static int PythonQtBoolResult_nonzero(PyObject *obj) // we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr static PyNumberMethods PythonQtBoolResult_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ + nullptr, /* nb_add */ + nullptr, /* nb_subtract */ + nullptr, /* nb_multiply */ #ifndef PY3K - 0, /* nb_divide */ + nullptr, /* nb_divide */ #endif - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ + nullptr, /* nb_remainder */ + nullptr, /* nb_divmod */ + nullptr, /* nb_power */ + nullptr, /* nb_negative */ + nullptr, /* nb_positive */ + nullptr, /* nb_absolute */ PythonQtBoolResult_nonzero, /* nb_nonzero / nb_bool in Py3K */ - 0, /* nb_invert */ - 0, /* nb_lshift */ - 0, /* nb_rshift */ - 0, /* nb_and */ - 0, /* nb_xor */ - 0, /* nb_or */ -#ifndef PY3K - 0, /* nb_coerce */ + nullptr, /* nb_invert */ + nullptr, /* nb_lshift */ + nullptr, /* nb_rshift */ + nullptr, /* nb_and */ + nullptr, /* nb_xor */ + nullptr, /* nb_or */ +#ifndef PY3K + nullptr, /* nb_coerce */ #endif - 0, /* nb_int */ - 0, /* nb_long / nb_reserved in Py3K */ - 0, /* nb_float */ + nullptr, /* nb_int */ + nullptr, /* nb_long / nb_reserved in Py3K */ + nullptr, /* nb_float */ #ifndef PY3K - 0, /* nb_oct */ - 0, /* nb_hex */ + nullptr, /* nb_oct */ + nullptr, /* nb_hex */ #endif - 0, /* nb_inplace_add */ - 0, /* nb_inplace_subtract */ - 0, /* nb_inplace_multiply */ + nullptr, /* nb_inplace_add */ + nullptr, /* nb_inplace_subtract */ + nullptr, /* nb_inplace_multiply */ #ifndef PY3K - 0, /* nb_inplace_divide */ + nullptr, /* nb_inplace_divide */ #endif - 0, /* nb_inplace_remainder */ - 0, /* nb_inplace_power */ - 0, /* nb_inplace_lshift */ - 0, /* nb_inplace_rshift */ - 0, /* nb_inplace_and */ - 0, /* nb_inplace_xor */ - 0, /* nb_inplace_or */ - 0, /* nb_floor_divide */ - 0, /* nb_true_divide */ - 0, /* nb_inplace_floor_divide */ - 0, /* nb_inplace_true_divide */ + nullptr, /* nb_inplace_remainder */ + nullptr, /* nb_inplace_power */ + nullptr, /* nb_inplace_lshift */ + nullptr, /* nb_inplace_rshift */ + nullptr, /* nb_inplace_and */ + nullptr, /* nb_inplace_xor */ + nullptr, /* nb_inplace_or */ + nullptr, /* nb_floor_divide */ + nullptr, /* nb_true_divide */ + nullptr, /* nb_inplace_floor_divide */ + nullptr, /* nb_inplace_true_divide */ #ifdef PY3K - 0, /* nb_index in Py3K */ + nullptr, /* nb_index in Py3K */ #endif }; @@ -122,37 +122,37 @@ PyTypeObject PythonQtBoolResult_Type = { "BoolResult", sizeof(PythonQtBoolResultObject), 0, - 0, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, + nullptr, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ + nullptr, /* tp_getattr */ + nullptr, /* tp_setattr */ + nullptr, (reprfunc)PythonQtBoolResult_repr, /* tp_repr */ &PythonQtBoolResult_as_number, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ + nullptr, /* tp_as_sequence */ + nullptr, /* tp_as_mapping */ + nullptr, /* tp_hash */ + nullptr, /* tp_call */ + nullptr, /* tp_str */ + nullptr, /* tp_getattro */ + nullptr, /* tp_setattro */ + nullptr, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT,/* tp_flags */ - "Result object that is useful for bool* arguments", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - 0, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ + "Result object that is useful for bool* arguments", /* tp_doc */ + nullptr, /* tp_traverse */ + nullptr, /* tp_clear */ + nullptr, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ + nullptr, /* tp_methods */ + nullptr, /* tp_members */ + nullptr, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + nullptr, /* tp_descr_get */ + nullptr, /* tp_descr_set */ + 0, /* tp_dictoffset */ (initproc)&PythonQtBoolResult_init, /* tp_init */ }; diff --git a/src/PythonQtClassInfo.cpp b/src/PythonQtClassInfo.cpp index 9909f7a19..35eb0adb5 100644 --- a/src/PythonQtClassInfo.cpp +++ b/src/PythonQtClassInfo.cpp @@ -50,13 +50,13 @@ QHash PythonQtMethodInfo::_parameterTypeDict; PythonQtClassInfo::PythonQtClassInfo() { - _meta = NULL; - _constructors = NULL; - _destructor = NULL; - _decoratorProvider = NULL; - _decoratorProviderCB = NULL; - _pythonQtClassWrapper = NULL; - _shellSetInstanceWrapperCB = NULL; + _meta = nullptr; + _constructors = nullptr; + _destructor = nullptr; + _decoratorProvider = nullptr; + _decoratorProviderCB = nullptr; + _pythonQtClassWrapper = nullptr; + _shellSetInstanceWrapperCB = nullptr; _metaTypeId = -1; _typeSlots = 0; _isQObject = false; @@ -64,8 +64,8 @@ PythonQtClassInfo::PythonQtClassInfo() { _richCompareDetectionDone = false; _searchPolymorphicHandlerOnParent = true; _searchRefCountCB = true; - _refCallback = NULL; - _unrefCallback = NULL; + _refCallback = nullptr; + _unrefCallback = nullptr; } PythonQtClassInfo::~PythonQtClassInfo() @@ -256,7 +256,7 @@ PythonQtSlotInfo* PythonQtClassInfo::findDecoratorSlotsFromDecoratorProvider(con bool PythonQtClassInfo::lookForMethodAndCache(const char* memberName) { bool found = false; - PythonQtSlotInfo* tail = NULL; + PythonQtSlotInfo* tail = nullptr; // look for dynamic decorators in this class and in derived classes // (do this first to allow overloading of existing slots with generated wrappers, @@ -496,7 +496,6 @@ QStringList PythonQtClassInfo::memberList() decorator(); QStringList l; - QString h; // normal slots of QObject (or wrapper QObject) if (_meta) { int numMethods = _meta->methodCount(); @@ -563,8 +562,8 @@ const QByteArray& PythonQtClassInfo::className() const void* PythonQtClassInfo::castTo(void* ptr, const char* classname) { - if (ptr==NULL) { - return NULL; + if (ptr==nullptr) { + return nullptr; } if (_wrappedClassName == classname) { return ptr; @@ -575,7 +574,7 @@ void* PythonQtClassInfo::castTo(void* ptr, const char* classname) return result; } } - return NULL; + return nullptr; } bool PythonQtClassInfo::inherits(const char* name) @@ -768,7 +767,7 @@ void* PythonQtClassInfo::recursiveCastDownIfPossible(void* ptr, const char** res } } } - return NULL; + return nullptr; } void* PythonQtClassInfo::castDownIfPossible(void* ptr, PythonQtClassInfo** resultClassInfo) @@ -795,14 +794,14 @@ void* PythonQtClassInfo::castDownIfPossible(void* ptr, PythonQtClassInfo** resul if (parent->_parentClasses.count()>0) { parent = parent->_parentClasses[0]._parent; } else { - parent = NULL; + parent = nullptr; } } } } // we only do downcasting on the base object, not on the whole inheritance tree... - void* resultPtr = NULL; + void* resultPtr = nullptr; if (!_polymorphicHandlers.isEmpty()) { Q_FOREACH(PythonQtPolymorphicHandlerCB* cb, _polymorphicHandlers) { resultPtr = (*cb)(ptr, &className); @@ -837,13 +836,13 @@ PyObject* PythonQtClassInfo::findEnumWrapper(const QByteArray& name, PythonQtCla if (info) { return info->findEnumWrapper(enumName); } else{ - return NULL; + return nullptr; } } if (localScope) { return localScope->findEnumWrapper(name); } else { - return NULL; + return nullptr; } } @@ -892,13 +891,13 @@ PyObject* PythonQtClassInfo::findEnumWrapper(const char* name) { PyObject* p = info._parent->findEnumWrapper(name); if (p) return p; } - return NULL; + return nullptr; } void PythonQtClassInfo::setDecoratorProvider( PythonQtQObjectCreatorFunctionCB* cb ) { _decoratorProviderCB = cb; - _decoratorProvider = NULL; + _decoratorProvider = nullptr; _enumsCreated = false; } @@ -959,7 +958,7 @@ PyObject* PythonQtClassInfo::copyObject( void* cppObject ) std::cerr << "PythonQt: Can't create a copy of '" << info->_wrappedClassName.constData() << "', either use qRegisterMetaType() or add a copy constructor to the decorator/wrapper." << std::endl; } } - return NULL; + return nullptr; } PythonQtSlotInfo* PythonQtClassInfo::getCopyConstructor() @@ -973,7 +972,7 @@ PythonQtSlotInfo* PythonQtClassInfo::getCopyConstructor() } construc = construc->nextInfo(); } - return NULL; + return nullptr; } void PythonQtClassInfo::setReferenceCounting( PythonQtVoidPtrCB* refCB, PythonQtVoidPtrCB* unrefCB ) @@ -1019,7 +1018,7 @@ PyObject* PythonQtClassInfo::getPythonTypeForProperty( const QString& name ) if (classInfo) { return classInfo->pythonQtClassWrapper(); } else { - return NULL; + return nullptr; } } @@ -1042,7 +1041,7 @@ PythonQtClassInfo* PythonQtClassInfo::getClassInfoForProperty( const QString& na PythonQtClassInfo* classInfo = PythonQt::priv()->getClassInfo(typeName); return classInfo; } - return NULL; + return nullptr; } bool PythonQtClassInfo::supportsRichCompare() @@ -1082,25 +1081,25 @@ PythonQtMemberInfo::PythonQtMemberInfo( PythonQtSlotInfo* info ) _type = Slot; } _slot = info; - _enumValue = NULL; - _pythonType = NULL; + _enumValue = nullptr; + _pythonType = nullptr; } PythonQtMemberInfo::PythonQtMemberInfo( const PythonQtObjectPtr& enumValue ) { _type = EnumValue; - _slot = NULL; + _slot = nullptr; _enumValue = enumValue; - _pythonType = NULL; + _pythonType = nullptr; } PythonQtMemberInfo::PythonQtMemberInfo( const QMetaProperty& prop ) { _type = Property; - _slot = NULL; + _slot = nullptr; _property = prop; - _enumValue = NULL; - _pythonType = NULL; + _enumValue = nullptr; + _pythonType = nullptr; } PythonQtDynamicClassInfo::~PythonQtDynamicClassInfo() diff --git a/src/PythonQtClassInfo.h b/src/PythonQtClassInfo.h index 7e8638bc5..5e3faf54a 100644 --- a/src/PythonQtClassInfo.h +++ b/src/PythonQtClassInfo.h @@ -46,7 +46,7 @@ class PythonQtClassInfo; struct PythonQtDynamicClassInfo { - PythonQtDynamicClassInfo() { _dynamicMetaObject = NULL; _classInfo = NULL; } + PythonQtDynamicClassInfo() { _dynamicMetaObject = nullptr; _classInfo = nullptr; } ~PythonQtDynamicClassInfo(); const QMetaObject* _dynamicMetaObject; @@ -55,11 +55,11 @@ struct PythonQtDynamicClassInfo struct PythonQtMemberInfo { enum Type { - Invalid, Slot, Signal, EnumValue, EnumWrapper, Property, NestedClass, NotFound + Invalid, Slot, Signal, EnumValue, EnumWrapper, Property, NestedClass, NotFound }; - PythonQtMemberInfo():_type(Invalid),_slot(NULL),_pythonType(NULL),_enumValue(0) { } - + PythonQtMemberInfo():_type(Invalid),_slot(nullptr),_pythonType(nullptr),_enumValue(nullptr) { } + PythonQtMemberInfo(PythonQtSlotInfo* info); PythonQtMemberInfo(const PythonQtObjectPtr& enumValue); @@ -110,7 +110,7 @@ class PYTHONQT_EXPORT PythonQtClassInfo { //! get access to the constructor slot (which may be overloaded if there are multiple constructors) PythonQtSlotInfo* constructors(); - + //! get access to the destructor slot PythonQtSlotInfo* destructor(); @@ -146,7 +146,7 @@ class PYTHONQT_EXPORT PythonQtClassInfo { //! returns if this class inherits from the given classname bool inherits(const char* classname); - + //! returns if this class inherits from the given classinfo bool inherits(PythonQtClassInfo* info); @@ -167,12 +167,12 @@ class PYTHONQT_EXPORT PythonQtClassInfo { //! get the meta type id of this class (only valid for isCPPWrapper() == true) int metaTypeId() { return _metaTypeId; } - //! set an additional decorator provider that offers additional decorator slots for this class + //! set an additional decorator provider that offers additional decorator slots for this class void setDecoratorProvider(PythonQtQObjectCreatorFunctionCB* cb); //! get the decorator qobject instance QObject* decorator(); - + //! add the parent class info of a CPP object void addParentClass(const ParentClassInfo& info) { _parentClasses.append(info); } @@ -186,7 +186,7 @@ class PYTHONQT_EXPORT PythonQtClassInfo { void setShellSetInstanceWrapperCB(PythonQtShellSetInstanceWrapperCB* cb) { _shellSetInstanceWrapperCB = cb; } - + //! get the shell set instance wrapper cb PythonQtShellSetInstanceWrapperCB* shellSetInstanceWrapperCB() { return _shellSetInstanceWrapperCB; @@ -199,7 +199,7 @@ class PYTHONQT_EXPORT PythonQtClassInfo { void* castDownIfPossible(void* ptr, PythonQtClassInfo** resultClassInfo); //! returns if the localScope has an enum of that type name or if the enum contains a :: scope, if that class contails the enum - static PyObject* findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool* isLocalEnum = NULL); + static PyObject* findEnumWrapper(const QByteArray& name, PythonQtClassInfo* localScope, bool* isLocalEnum = nullptr); //! clear all members that where cached as "NotFound" void clearNotFoundCachedMembers(); @@ -262,7 +262,7 @@ class PYTHONQT_EXPORT PythonQtClassInfo { PythonQtSlotInfo* findDecoratorSlots(const char* memberName, PythonQtSlotInfo* tail, bool &found, QHash& memberCache, int upcastingOffset); int findCharOffset(const char* sigStart, char someChar); - + QHash _cachedMembers; PythonQtSlotInfo* _constructors; @@ -286,11 +286,11 @@ class PYTHONQT_EXPORT PythonQtClassInfo { QObject* _decoratorProvider; PythonQtQObjectCreatorFunctionCB* _decoratorProviderCB; - + PyObject* _pythonQtClassWrapper; - + PythonQtShellSetInstanceWrapperCB* _shellSetInstanceWrapperCB; - + int _metaTypeId; int _typeSlots; @@ -299,7 +299,7 @@ class PYTHONQT_EXPORT PythonQtClassInfo { bool _richCompareDetectionDone; bool _searchPolymorphicHandlerOnParent; bool _searchRefCountCB; - + }; //--------------------------------------------------------------- diff --git a/src/PythonQtClassWrapper.cpp b/src/PythonQtClassWrapper.cpp index 6a5ddccc6..7edd2bc6d 100644 --- a/src/PythonQtClassWrapper.cpp +++ b/src/PythonQtClassWrapper.cpp @@ -51,34 +51,34 @@ static PyObject* PythonQtInstanceWrapper_invert(PythonQtInstanceWrapper* wrapper) { - PyObject* result = NULL; + PyObject* result = nullptr; static QByteArray memberName = "__invert__"; PythonQtMemberInfo opSlot = wrapper->classInfo()->member(memberName); if (opSlot._type == PythonQtMemberInfo::Slot) { - result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, NULL, NULL, wrapper->_wrappedPtr); + result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, nullptr, nullptr, wrapper->_wrappedPtr); } return result; } static PyObject* PythonQtInstanceWrapper_negative(PythonQtInstanceWrapper* wrapper) { - PyObject* result = NULL; + PyObject* result = nullptr; static QByteArray memberName = "__sub__"; PythonQtMemberInfo opSlot = wrapper->classInfo()->member(memberName); if (opSlot._type == PythonQtMemberInfo::Slot) { - result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, NULL, NULL, wrapper->_wrappedPtr); + result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, nullptr, nullptr, wrapper->_wrappedPtr); } return result; } static int PythonQtInstanceWrapper_nonzero(PythonQtInstanceWrapper* wrapper) { - int result = (wrapper->_wrappedPtr == NULL && wrapper->_obj == NULL)?0:1; + int result = (wrapper->_wrappedPtr == nullptr && wrapper->_obj == nullptr)?0:1; if (result) { static QByteArray memberName = "__nonzero__"; PythonQtMemberInfo opSlot = wrapper->classInfo()->member(memberName); if (opSlot._type == PythonQtMemberInfo::Slot) { - PyObject* resultObj = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, NULL, NULL, wrapper->_wrappedPtr); + PyObject* resultObj = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, nullptr, nullptr, wrapper->_wrappedPtr); if (resultObj == Py_False) { result = 0; } @@ -91,11 +91,11 @@ static int PythonQtInstanceWrapper_nonzero(PythonQtInstanceWrapper* wrapper) static Py_ssize_t PythonQtInstanceWrapper_length(PythonQtInstanceWrapper* wrapper) { qint64 result = -1; - if (wrapper->_wrappedPtr != NULL || wrapper->_obj != NULL) { + if (wrapper->_wrappedPtr != nullptr || wrapper->_obj != nullptr) { static QByteArray memberName = "__len__"; PythonQtMemberInfo opSlot = wrapper->classInfo()->member(memberName); if (opSlot._type == PythonQtMemberInfo::Slot) { - PyObject* resultObj = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, NULL, NULL, wrapper->_wrappedPtr); + PyObject* resultObj = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, nullptr, nullptr, wrapper->_wrappedPtr); bool ok; result = PythonQtConv::PyObjGetLongLong(resultObj, false, ok); if (!ok) { @@ -126,7 +126,7 @@ static int PythonQtInstanceWrapper_setitem(PyObject* self, PyObject* index, PyOb Py_INCREF(value); PyTuple_SET_ITEM(args, 1, value); } - PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, NULL, wrapper->_wrappedPtr); + PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, nullptr, wrapper->_wrappedPtr); if (result) { Py_DECREF(result); } @@ -144,16 +144,16 @@ static PyObject* PythonQtInstanceWrapper_binaryfunc(PyObject* self, PyObject* ot if (!PyObject_TypeCheck(self, &PythonQtInstanceWrapper_Type)) { QString error = "Unsupported operation " + opName + "(" + self->ob_type->tp_name + ", " + other->ob_type->tp_name + ")"; PyErr_SetString(PyExc_ArithmeticError, QStringToPythonCharPointer(error)); - return NULL; + return nullptr; } PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)self; - PyObject* result = NULL; + PyObject* result = nullptr; PythonQtMemberInfo opSlot = wrapper->classInfo()->member(opName); if (opSlot._type == PythonQtMemberInfo::Slot) { PyObject* args = PyTuple_New(1); Py_INCREF(other); PyTuple_SET_ITEM(args, 0, other); - result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, NULL, wrapper->_wrappedPtr); + result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, nullptr, wrapper->_wrappedPtr); Py_DECREF(args); if (!result && !fallbackOpName.isEmpty()) { // try fallback if we did not get a result @@ -174,13 +174,13 @@ static PyObject* PythonQtInstanceWrapper_mul(PyObject* self, PyObject* other) other = tmp; } PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)self; - PyObject* result = NULL; + PyObject* result = nullptr; PythonQtMemberInfo opSlot = wrapper->classInfo()->member("__mul__"); if (opSlot._type == PythonQtMemberInfo::Slot) { PyObject* args = PyTuple_New(1); Py_INCREF(other); PyTuple_SET_ITEM(args, 0, other); - result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, NULL, wrapper->_wrappedPtr); + result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, nullptr, wrapper->_wrappedPtr); Py_DECREF(args); } return result; @@ -343,7 +343,7 @@ static int PythonQtClassWrapper_init(PythonQtClassWrapper* self, PyObject* args, if (PyType_Type.tp_init((PyObject *)self, args, kwds) < 0) { return -1; } - self->_dynamicClassInfo = NULL; + self->_dynamicClassInfo = nullptr; // if we have no CPP class information, try our base class if (!self->classInfo()) { @@ -403,16 +403,16 @@ PyObject *PythonQtClassWrapper_delete(PythonQtClassWrapper *type, PyObject *args return PythonQtInstanceWrapper_delete((PythonQtInstanceWrapper*)self); } } - return NULL; + return nullptr; } PyObject *PythonQtClassWrapper_inherits(PythonQtClassWrapper *type, PyObject *args) { Q_UNUSED(type); - PythonQtInstanceWrapper* wrapper = NULL; - char *name = NULL; + PythonQtInstanceWrapper* wrapper = nullptr; + char *name = nullptr; if (!PyArg_ParseTuple(args, "O!s:PythonQtClassWrapper.inherits",&PythonQtInstanceWrapper_Type, &wrapper, &name)) { - return NULL; + return nullptr; } return PythonQtConv::GetPyBool(wrapper->classInfo()->inherits(name)); } @@ -431,14 +431,14 @@ static PyMethodDef PythonQtClassWrapper_methods[] = { {"delete", (PyCFunction)PythonQtClassWrapper_delete, METH_VARARGS, "Deletes the given C++ object" }, - {NULL, NULL, 0 , NULL} /* Sentinel */ + {nullptr, nullptr, 0 , nullptr} /* Sentinel */ }; static PyObject* PythonQtClassWrapper_getDummyInstanceForProperty(PythonQtClassWrapper* wrapper, const QString& property) { PythonQtClassInfo* info = wrapper->classInfo()->getClassInfoForProperty(property); if (info) { - return (PyObject*)PythonQt::priv()->createNewPythonQtInstanceWrapper(NULL, info); + return (PyObject*)PythonQt::priv()->createNewPythonQtInstanceWrapper(nullptr, info); } Py_INCREF(Py_None); return Py_None; @@ -449,8 +449,8 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name) const char *attributeName; PythonQtClassWrapper *wrapper = (PythonQtClassWrapper *)obj; - if ((attributeName = PyString_AsString(name)) == NULL) { - return NULL; + if ((attributeName = PyString_AsString(name)) == nullptr) { + return nullptr; } if (obj == (PyObject*)&PythonQtInstanceWrapper_Type) { // if we are called as PythonQtInstanceWrapper_Type, we need to get the properties from the type... @@ -491,7 +491,7 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name) PyDict_SetItemString(dict, "__init__", func); Py_DECREF(func); } - for (int i = 0; PythonQtClassWrapper_methods[i].ml_name != NULL; i++) { + for (int i = 0; PythonQtClassWrapper_methods[i].ml_name != nullptr; i++) { PyObject* func = PyCFunction_New(&PythonQtClassWrapper_methods[i], obj); PyDict_SetItemString(dict, PythonQtClassWrapper_methods[i].ml_name, func); Py_DECREF(func); @@ -527,15 +527,15 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name) PythonQtMemberInfo qualifiedMember = wrapper->classInfo()->member(qualifiedMemberName); if (qualifiedMember._type == PythonQtMemberInfo::Slot) { // return the qualified member, so that virtual calls on classes call the qualified member - return PythonQtSlotFunction_New(qualifiedMember._slot, obj, NULL); + return PythonQtSlotFunction_New(qualifiedMember._slot, obj, nullptr); } else { // we return all slots, even the instance slots, since they are callable as unbound slots with self argument - return PythonQtSlotFunction_New(member._slot, obj, NULL); + return PythonQtSlotFunction_New(member._slot, obj, nullptr); } } else if (member._type == PythonQtMemberInfo::Signal) { // we return all signals, even the instance signals, since they are callable as unbound signals with self argument - return PythonQtSignalFunction_New(member._slot, obj, NULL); + return PythonQtSignalFunction_New(member._slot, obj, nullptr); } else if (member._type == PythonQtMemberInfo::Property) { PyObject* dummy = PythonQtClassWrapper_getDummyInstanceForProperty(wrapper, attributeName); return dummy; @@ -560,7 +560,7 @@ static PyObject *PythonQtClassWrapper_getattro(PyObject *obj, PyObject *name) QString error = QString(wrapper->classInfo()->className()) + " has no attribute named '" + QString(attributeName) + "'"; PyErr_SetString(PyExc_AttributeError, QStringToPythonConstCharPointer(error)); - return NULL; + return nullptr; } static int PythonQtClassWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value) @@ -593,49 +593,49 @@ static PyObject * PythonQtClassWrapper_repr(PyObject * obj) */ PyTypeObject PythonQtClassWrapper_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "PythonQt.PythonQtClassWrapper", /*tp_name*/ - sizeof(PythonQtClassWrapper), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - 0, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, //PythonQtClassWrapper_repr, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - PythonQtClassWrapper_getattro, /*tp_getattro*/ - PythonQtClassWrapper_setattro, /*tp_setattro*/ - 0, /*tp_as_buffer*/ + PyVarObject_HEAD_INIT(nullptr, 0) + "PythonQt.PythonQtClassWrapper", /*tp_name*/ + sizeof(PythonQtClassWrapper), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + nullptr, /*tp_dealloc*/ + 0, /*tp_vectorcall_offset*/ + nullptr, /*tp_getattr*/ + nullptr, /*tp_setattr*/ + nullptr, /*tp_compare*/ + nullptr, //PythonQtClassWrapper_repr, /*tp_repr*/ + nullptr, /*tp_as_number*/ + nullptr, /*tp_as_sequence*/ + nullptr, /*tp_as_mapping*/ + nullptr, /*tp_hash */ + nullptr, /*tp_call*/ + nullptr, /*tp_str*/ + PythonQtClassWrapper_getattro, /*tp_getattro*/ + PythonQtClassWrapper_setattro, /*tp_setattro*/ + nullptr, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - 0, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ + nullptr, /* tp_doc */ + nullptr, /* tp_traverse */ + nullptr, /* tp_clear */ + nullptr, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ #ifdef PY3K - PythonQtClassWrapper_methods, /* tp_methods */ + PythonQtClassWrapper_methods, /* tp_methods */ #else - 0, /* tp_methods */ + nullptr, /* tp_methods */ #endif - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ - (initproc)PythonQtClassWrapper_init, /* tp_init */ - PythonQtClassWrapper_alloc, /* tp_alloc */ - 0, /* tp_new */ - 0, /* tp_free */ + nullptr, /* tp_members */ + nullptr, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + nullptr, /* tp_descr_get */ + nullptr, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)PythonQtClassWrapper_init, /* tp_init */ + PythonQtClassWrapper_alloc, /* tp_alloc */ + nullptr, /* tp_new */ + nullptr, /* tp_free */ }; //------------------------------------------------------- diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp index e81476df4..e31fe090d 100644 --- a/src/PythonQtConversion.cpp +++ b/src/PythonQtConversion.cpp @@ -51,7 +51,7 @@ QHash PythonQtConv::_metaTypeToPythonConverters; QHash PythonQtConv::_pythonToMetaTypeConverters; -PythonQtConvertPythonSequenceToQVariantListCB* PythonQtConv::_pythonSequenceToQVariantListCB = NULL; +PythonQtConvertPythonSequenceToQVariantListCB* PythonQtConv::_pythonSequenceToQVariantListCB = nullptr; PyObject* PythonQtConv::GetPyBool(bool val) { @@ -87,7 +87,7 @@ PyObject* PythonQtConv::ConvertQtValueToPython(const PythonQtMethodInfo::Paramet } else if ((info.typeId == PythonQtMethodInfo::Unknown || info.typeId >= QMetaType::User) && info.isQList && (info.innerNamePointerCount == 1)) { // it is a QList template: - QList* listPtr = NULL; + QList* listPtr = nullptr; if (info.pointerCount == 1) { listPtr = *((QList**)data); } else if (info.pointerCount == 0) { @@ -96,7 +96,7 @@ PyObject* PythonQtConv::ConvertQtValueToPython(const PythonQtMethodInfo::Paramet if (listPtr) { return ConvertQListOfPointerTypeToPythonList(listPtr, info); } else { - return NULL; + return nullptr; } } @@ -221,11 +221,11 @@ PyObject* PythonQtConv::convertQtValueToPythonInternal(int type, const void* dat } void* PythonQtConv::CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo& info, PythonQtArgumentFrame* frame) { - void* ptr = NULL; + void* ptr = nullptr; if (info.pointerCount>1) { - return NULL; + return nullptr; } else if (info.pointerCount==1) { - PythonQtArgumentFrame_ADD_VALUE(frame, void*, NULL, ptr); + PythonQtArgumentFrame_ADD_VALUE(frame, void*, nullptr, ptr); } else if (info.enumWrapper) { // create enum return value PythonQtArgumentFrame_ADD_VALUE(frame, long, 0, ptr); @@ -283,7 +283,7 @@ PyObject* PythonQtConv::convertQtValueToPythonInternal(int type, const void* dat if (object) { // if we can be upcasted to the given name, we pass the casted pointer in: object = wrapper->classInfo()->castTo(object, className); - ok = object!=NULL; + ok = object!=nullptr; } else { // if it is a NULL ptr, we need to check if it inherits, so that we might pass the NULL ptr ok = wrapper->classInfo()->inherits(className); @@ -299,9 +299,9 @@ void* PythonQtConv::handlePythonToQtAutoConversion(int typeId, PyObject* obj, vo static int brushId = QMetaType::type("QBrush"); static int cursorId = QMetaType::type("QCursor"); static int colorId = QMetaType::type("QColor"); - static PyObject* qtGlobalColorEnum = PythonQtClassInfo::findEnumWrapper("Qt::GlobalColor", NULL); + static PyObject* qtGlobalColorEnum = PythonQtClassInfo::findEnumWrapper("Qt::GlobalColor", nullptr); if (typeId == cursorId) { - static PyObject* qtCursorShapeEnum = PythonQtClassInfo::findEnumWrapper("Qt::CursorShape", NULL); + static PyObject* qtCursorShapeEnum = PythonQtClassInfo::findEnumWrapper("Qt::CursorShape", nullptr); if ((PyObject*)obj->ob_type == qtCursorShapeEnum) { Qt::CursorShape val = (Qt::CursorShape)PyInt_AsLong(obj); if (!ptr) { @@ -361,13 +361,13 @@ void* PythonQtConv::handlePythonToQtAutoConversion(int typeId, PyObject* obj, vo return ptr; } } - return NULL; + return nullptr; } void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, PythonQtClassInfo* /*classInfo*/, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame) { bool ok = false; - void* ptr = NULL; + void* ptr = nullptr; // autoconversion of QPen/QBrush/QCursor/QColor from different type if (info.pointerCount==0 && !strict) { @@ -429,8 +429,8 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i QByteArray bytes; bytes = str.toUtf8(); if (ok) { - void* ptr2 = NULL; - PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(NULL,frame, QVariant(bytes), ptr2); + void* ptr2 = nullptr; + PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(nullptr,frame, QVariant(bytes), ptr2); PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,frame, void*, (((QByteArray*)((QVariant*)ptr2)->constData())->data()), ptr); } } @@ -441,8 +441,8 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i // result value is not useable in Python), or if all these APIs need to be wrapped manually/differently, like PyQt/PySide do. QString str = PyObjGetString(obj, strict, ok); if (ok) { - void* ptr2 = NULL; - PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(NULL,frame, QVariant(str), ptr2); + void* ptr2 = nullptr; + PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(nullptr,frame, QVariant(str), ptr2); PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,frame, void*, (void*)((QVariant*)ptr2)->constData(), ptr); } } else if (info.name == "PyObject") { @@ -450,7 +450,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, void*, obj, ptr); } else if (obj == Py_None) { // None is treated as a NULL ptr - PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, void*, NULL, ptr); + PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, void*, nullptr, ptr); } else { void* foreignWrapper = PythonQt::priv()->unwrapForeignWrapper(info.name, obj); if (foreignWrapper) { @@ -461,7 +461,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i bool ok; int value = PyObjGetInt(obj, true, ok); if (ok && value==0) { - PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, void*, NULL, ptr); + PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, void*, nullptr, ptr); } } } @@ -642,7 +642,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject,frame, unsigned int, val, ptr); return ptr; } else { - return NULL; + return nullptr; } } @@ -660,7 +660,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i if (ok) { return ptr; } else { - return NULL; + return nullptr; } } } @@ -682,7 +682,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i if (ok) { return ptr; } else { - return NULL; + return nullptr; } } } @@ -1213,7 +1213,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) PythonQtConvertPythonToMetaTypeCB* converter = _pythonToMetaTypeConverters.value(type); if (converter) { // allocate a default object of the needed type: - v = QVariant(type, (const void*)NULL); + v = QVariant(type, (const void*)nullptr); // now call the converter, passing the internal object of the variant ok = (*converter)(val, (void*)v.constData(), type, true); if (!ok) { @@ -1224,7 +1224,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) const PythonQtMethodInfo::ParameterInfo& info = PythonQtMethodInfo::getParameterInfoForMetaType(type); if (info.isQList && (info.innerNamePointerCount == 1)) { // allocate a default object of the needed type: - v = QVariant(type, (const void*)NULL); + v = QVariant(type, (const void*)nullptr); ok = ConvertPythonListToQListOfPointerType(val, (QList*)v.constData(), info, true); if (!ok) { v = QVariant(); @@ -1241,7 +1241,7 @@ PyObject* PythonQtConv::QStringToPyObject(const QString& str) if (str.isNull()) { return PyString_FromString(""); } else { - return PyUnicode_DecodeUTF16((const char*)str.utf16(), str.length()*2, NULL, NULL); + return PyUnicode_DecodeUTF16((const char*)str.utf16(), str.length()*2, nullptr, nullptr); } } @@ -1276,7 +1276,7 @@ PyObject* PythonQtConv::QVariantToPyObject(const QVariant& v) Py_INCREF(Py_None); return Py_None; } - PyObject* obj = NULL; + PyObject* obj = nullptr; if (v.userType() >= QMetaType::User && !PythonQt::priv()->isPythonQtAnyObjectPtrMetaId(v.userType())) { // try the slower way, which supports more conversions, e.g. QList const PythonQtMethodInfo::ParameterInfo& info = PythonQtMethodInfo::getParameterInfoForMetaType(v.userType()); diff --git a/src/PythonQtConversion.h b/src/PythonQtConversion.h index 9cf997558..1ff05bee7 100644 --- a/src/PythonQtConversion.h +++ b/src/PythonQtConversion.h @@ -109,7 +109,7 @@ class PYTHONQT_EXPORT PythonQtConv { static PyObject* ConvertQtValueToPython(const PythonQtMethodInfo::ParameterInfo& info, const void* data); //! convert python object to Qt (according to the given parameter) and if the conversion should be strict (classInfo is currently not used anymore) - static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, PythonQtClassInfo* classInfo, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame = NULL); + static void* ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& info, PyObject* obj, bool strict, PythonQtClassInfo* classInfo, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame = nullptr); //! creates a data storage for the passed parameter type and returns a void pointer to be set as arg[0] of qt_metacall static void* CreateQtReturnValue(const PythonQtMethodInfo::ParameterInfo& info, PythonQtArgumentFrame* frame); @@ -156,10 +156,10 @@ class PYTHONQT_EXPORT PythonQtConv { static PyObject* QVariantHashToPyObject(const QVariantHash& m); static PyObject* QVariantMapToPyObject(const QVariantMap& m); static PyObject* QVariantListToPyObject(const QVariantList& l); - + //! get human readable string from CPP object (when the metatype is known) static QString CPPObjectToString(int type, const void* data); - + //! register a converter callback from python to cpp for given metatype static void registerPythonToMetaTypeConverter(int metaTypeId, PythonQtConvertPythonToMetaTypeCB* cb) { _pythonToMetaTypeConverters.insert(metaTypeId, cb); } @@ -194,10 +194,10 @@ class PYTHONQT_EXPORT PythonQtConv { static bool isStringType(PyTypeObject* type); protected: - static QHash _metaTypeToPythonConverters; - static QHash _pythonToMetaTypeConverters; + static QHash _metaTypeToPythonConverters; + static QHash _pythonToMetaTypeConverters; static PythonQtConvertPythonSequenceToQVariantListCB* _pythonSequenceToQVariantListCB; - + //! handle automatic conversion of some special types (QColor, QBrush, ...) static void* handlePythonToQtAutoConversion(int typeId, PyObject* obj, void* alreadyAllocatedCPPObject, PythonQtArgumentFrame* frame); @@ -212,13 +212,13 @@ class PYTHONQT_EXPORT PythonQtConv { //! helper template function for QVariantMapToPyObject/QVariantHashToPyObject template static PyObject* mapToPython (const Map& m); - + }; template PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList* */ inList, int metaTypeId) { - ListType* list = (ListType*)inList; + ListType* list = (ListType*)inList; static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId))); if (innerType == QVariant::Invalid) { std::cerr << "PythonQtConvertListOfValueTypeToPythonList: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; @@ -235,7 +235,7 @@ PyObject* PythonQtConvertListOfValueTypeToPythonList(const void* /*QList* */ template bool PythonQtConvertPythonListToListOfValueType(PyObject* obj, void* /*QList* */ outList, int metaTypeId, bool /*strict*/) { - ListType* list = (ListType*)outList; + ListType* list = (ListType*)outList; static const int innerType = PythonQtMethodInfo::getInnerTemplateMetaType(QByteArray(QMetaType::typeName(metaTypeId))); if (innerType == QVariant::Invalid) { std::cerr << "PythonQtConvertPythonListToListOfValueType: unknown inner type " << QMetaType::typeName(metaTypeId) << std::endl; @@ -270,7 +270,7 @@ PyObject* PythonQtConvertListOfKnownClassToPythonList(const void* /*QList* */ { ListType* list = (ListType*)inList; static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(PythonQtMethodInfo::getInnerListTypeName(QByteArray(QMetaType::typeName(metaTypeId)))); - if (innerType == NULL) { + if (innerType == nullptr) { std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type " << innerType->className().constData() << std::endl; } PyObject* result = PyTuple_New(list->size()); @@ -290,7 +290,7 @@ bool PythonQtConvertPythonListToListOfKnownClass(PyObject* obj, void* /*QList { ListType* list = (ListType*)outList; static PythonQtClassInfo* innerType = PythonQt::priv()->getClassInfo(PythonQtMethodInfo::getInnerListTypeName(QByteArray(QMetaType::typeName(metaTypeId)))); - if (innerType == NULL) { + if (innerType == nullptr) { std::cerr << "PythonQtConvertListOfKnownClassToPythonList: unknown inner type " << innerType->className().constData() << std::endl; } bool result = false; @@ -500,7 +500,7 @@ bool PythonQtConvertPythonToIntegerMap(PyObject* val, void* /*QMap* */ o tuple = PyList_GetItem(items, i); key = PyTuple_GetItem(tuple, 0); value = PyTuple_GetItem(tuple, 1); - + bool ok; int intKey = PythonQtConv::PyObjGetInt(key, false, ok); // this is quite some overhead, but it avoids having another large switch... diff --git a/src/PythonQtImporter.cpp b/src/PythonQtImporter.cpp index 21ec5a43b..9afa3f71a 100644 --- a/src/PythonQtImporter.cpp +++ b/src/PythonQtImporter.cpp @@ -128,7 +128,7 @@ PythonQtImport::ModuleInfo PythonQtImport::getModuleInfo(PythonQtImporter* self, */ int PythonQtImporter_init(PythonQtImporter *self, PyObject *args, PyObject * /*kwds*/) { - self->_path = NULL; + self->_path = nullptr; const char* cpath; if (!PyArg_ParseTuple(args, "s", @@ -177,12 +177,12 @@ PyObject * PythonQtImporter_find_module(PyObject *obj, PyObject *args) { PythonQtImporter *self = (PythonQtImporter *)obj; - PyObject *path = NULL; + PyObject *path = nullptr; char *fullname; if (!PyArg_ParseTuple(args, "s|O:PythonQtImporter.find_module", &fullname, &path)) - return NULL; + return nullptr; //qDebug() << "looking for " << fullname << " at " << *self->_path; @@ -205,7 +205,7 @@ PythonQtImporter_iter_modules(PyObject *obj, PyObject *args) const char* prefix; if (!PyArg_ParseTuple(args, "|s", &prefix)) { - return NULL; + return nullptr; } PythonQtImporter *self = (PythonQtImporter *)obj; PythonQtObjectPtr pkgutil = PythonQt::self()->importModule("pkgutil"); @@ -221,37 +221,37 @@ PyObject * PythonQtImporter_load_module(PyObject *obj, PyObject *args) { PythonQtImporter *self = (PythonQtImporter *)obj; - PyObject *code = NULL, *mod = NULL, *dict = NULL; + PyObject *code = nullptr, *mod = nullptr, *dict = nullptr; char *fullname; if (!PyArg_ParseTuple(args, "s:PythonQtImporter.load_module", &fullname)) - return NULL; + return nullptr; PythonQtImport::ModuleInfo info = PythonQtImport::getModuleInfo(self, fullname); if (info.type == PythonQtImport::MI_NOT_FOUND) { - return NULL; + return nullptr; } if (info.type == PythonQtImport::MI_PACKAGE || info.type == PythonQtImport::MI_MODULE) { QString fullPath; QString fullCachePath; code = PythonQtImport::getModuleCode(self, fullname, fullPath, fullCachePath); - if (code == NULL) { - return NULL; + if (code == nullptr) { + return nullptr; } mod = PyImport_AddModule(fullname); - if (mod == NULL) { + if (mod == nullptr) { Py_DECREF(code); - return NULL; + return nullptr; } dict = PyModule_GetDict(mod); if (PyDict_SetItemString(dict, "__loader__", (PyObject *)self) != 0) { Py_DECREF(code); Py_DECREF(mod); - return NULL; + return nullptr; } if (info.type == PythonQtImport::MI_PACKAGE) { @@ -263,25 +263,25 @@ PythonQtImporter_load_module(PyObject *obj, PyObject *args) QStringToPythonConstCharPointer(*self->_path), SEP, QStringToPythonConstCharPointer(subname)); - if (fullpath == NULL) { + if (fullpath == nullptr) { Py_DECREF(code); Py_DECREF(mod); - return NULL; + return nullptr; } pkgpath = Py_BuildValue("[O]", fullpath); Py_DECREF(fullpath); - if (pkgpath == NULL) { + if (pkgpath == nullptr) { Py_DECREF(code); Py_DECREF(mod); - return NULL; + return nullptr; } err = PyDict_SetItemString(dict, "__path__", pkgpath); Py_DECREF(pkgpath); if (err != 0) { Py_DECREF(code); Py_DECREF(mod); - return NULL; + return nullptr; } // set __package__ only for Python 3, because in Python 2 it causes the exception "__package__ set to non-string" @@ -293,7 +293,7 @@ PythonQtImporter_load_module(PyObject *obj, PyObject *args) if (err != 0) { Py_DECREF(code); Py_DECREF(mod); - return NULL; + return nullptr; } #endif } @@ -301,7 +301,7 @@ PythonQtImporter_load_module(PyObject *obj, PyObject *args) #ifdef PY3K PyObject* fullnameObj = PyUnicode_FromString(fullname); PyObject* fullPathObj = PythonQtConv::QStringToPyObject(fullPath); - PyObject* fullCachePathObj = !fullCachePath.isEmpty() ? PythonQtConv::QStringToPyObject(fullCachePath) : NULL; + PyObject* fullCachePathObj = !fullCachePath.isEmpty() ? PythonQtConv::QStringToPyObject(fullCachePath) : nullptr; mod = PyImport_ExecCodeModuleObject(fullnameObj, code, fullPathObj, fullCachePathObj); Py_XDECREF(fullnameObj); Py_XDECREF(fullPathObj); @@ -372,7 +372,7 @@ PyObject * PythonQtImporter_get_data(PyObject* /*obj*/, PyObject* /*args*/) { // EXTRA, NOT YET IMPLEMENTED - return NULL; + return nullptr; } PyObject * @@ -382,7 +382,7 @@ PythonQtImporter_get_code(PyObject *obj, PyObject *args) char *fullname; if (!PyArg_ParseTuple(args, "s:PythonQtImporter.get_code", &fullname)) - return NULL; + return nullptr; QString notused; QString notused2; @@ -393,7 +393,7 @@ PyObject * PythonQtImporter_get_source(PyObject * /*obj*/, PyObject * /*args*/) { // EXTRA, NOT YET IMPLEMENTED - return NULL; + return nullptr; } PyDoc_STRVAR(doc_find_module, @@ -447,7 +447,7 @@ PyMethodDef PythonQtImporter_methods[] = { doc_get_code}, {"get_source", PythonQtImporter_get_source, METH_VARARGS, doc_get_source}, - {NULL, NULL, 0 , NULL} /* sentinel */ + {nullptr, nullptr, 0 , nullptr} /* sentinel */ }; @@ -457,48 +457,48 @@ PyDoc_STRVAR(PythonQtImporter_doc, Create a new PythonQtImporter instance. 'path' must be a valid path on disk/or inside of a zip file known to MeVisLab\n\ . Every path is accepted."); -#define DEFERRED_ADDRESS(ADDR) 0 +#define DEFERRED_ADDRESS(ADDR) nullptr PyTypeObject PythonQtImporter_Type = { PyVarObject_HEAD_INIT(DEFERRED_ADDRESS(&PyType_Type), 0) "PythonQtImport.PythonQtImporter", sizeof(PythonQtImporter), - 0, /* tp_itemsize */ + 0, /* tp_itemsize */ (destructor)PythonQtImporter_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ - 0, /* tp_compare */ - 0, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - 0, /* tp_hash */ - 0, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ + 0, /* tp_vectorcall_offset */ + nullptr, /* tp_getattr */ + nullptr, /* tp_setattr */ + nullptr, /* tp_compare */ + nullptr, /* tp_repr */ + nullptr, /* tp_as_number */ + nullptr, /* tp_as_sequence */ + nullptr, /* tp_as_mapping */ + nullptr, /* tp_hash */ + nullptr, /* tp_call */ + nullptr, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + nullptr, /* tp_setattro */ + nullptr, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE , /* tp_flags */ PythonQtImporter_doc, /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PythonQtImporter_methods, /* tp_methods */ - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ + nullptr, /* tp_traverse */ + nullptr, /* tp_clear */ + nullptr, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ + PythonQtImporter_methods, /* tp_methods */ + nullptr, /* tp_members */ + nullptr, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + nullptr, /* tp_descr_get */ + nullptr, /* tp_descr_set */ + 0, /* tp_dictoffset */ (initproc)PythonQtImporter_init, /* tp_init */ PyType_GenericAlloc, /* tp_alloc */ - PyType_GenericNew, /* tp_new */ - PyObject_Del, /* tp_free */ + PyType_GenericNew, /* tp_new */ + PyObject_Del, /* tp_free */ }; @@ -543,7 +543,7 @@ open_exclusive(const QString& filename) fd = open(filename.toLocal8Bit(), flags, 0666); #endif if (fd < 0) - return NULL; + return nullptr; return fdopen(fd, "wb"); #else /* Best we can do -- on Windows this can't happen anyway */ @@ -560,7 +560,7 @@ void PythonQtImport::writeCompiledModule(PyCodeObject *co, const QString& filena return; } fp = open_exclusive(filename); - if (fp == NULL) { + if (fp == nullptr) { if (Py_VerboseFlag) PySys_WriteStderr( "# can't create %s\n", QStringToPythonConstCharPointer(filename)); @@ -656,14 +656,14 @@ PythonQtImport::unmarshalCode(const QString& path, const QByteArray& data, time_ #else code = PyMarshal_ReadObjectFromString(buf + 8, size - 8); #endif - if (code == NULL) - return NULL; + if (code == nullptr) + return nullptr; if (!PyCode_Check(code)) { Py_DECREF(code); PyErr_Format(PyExc_TypeError, "compiled module %.200s is not a code object", QStringToPythonConstCharPointer(path)); - return NULL; + return nullptr; } return code; } @@ -675,14 +675,10 @@ PyObject * PythonQtImport::compileSource(const QString& path, const QByteArray& data) { PyObject *code; - QByteArray data1 = data; -// in qt4, data is null terminated -// data1.resize(data.size()+1); -// data1.data()[data.size()-1] = 0; #ifdef PY3K PyObject* filename = PythonQtConv::QStringToPyObject(path); code = Py_CompileStringObject(data.data(), filename, - Py_file_input, NULL, -1); + Py_file_input, nullptr, -1); Py_DECREF(filename); #else code = Py_CompileString(data.data(), QStringToPythonConstCharPointer(path), @@ -721,7 +717,7 @@ PythonQtImport::getCodeFromData(const QString& path, int isbytecode,int /*ispack qdata = PythonQt::importInterface()->readSourceFile(path, ok); if (!ok) { // mlabErrorConst("PythonQtImporter","File could not be verified" << path); - return NULL; + return nullptr; } if (qdata == " ") { qdata.clear(); @@ -776,7 +772,7 @@ PythonQtImport::getModuleCode(PythonQtImporter *self, const char* fullname, QStr QString test; for (zso = mlab_searchorder; *zso->suffix;zso++) { - PyObject *code = NULL; + PyObject *code = nullptr; test = path + zso->suffix; if (Py_VerboseFlag > 1) @@ -800,7 +796,7 @@ PythonQtImport::getModuleCode(PythonQtImporter *self, const char* fullname, QStr Py_DECREF(code); continue; } - if (code != NULL) { + if (code != nullptr) { modpath = test; #ifdef PY3K if (isbytecode) { @@ -814,7 +810,7 @@ PythonQtImport::getModuleCode(PythonQtImporter *self, const char* fullname, QStr } PyErr_Format(PythonQtImportError, "can't find module '%.200s'", fullname); - return NULL; + return nullptr; } QString PythonQtImport::replaceExtension(const QString& str, const QString& ext) @@ -845,7 +841,7 @@ PyObject* PythonQtImport::getCodeFromPyc(const QString& file) mtime = getMTimeOfSource(pyc); } code = getCodeFromData(pyc, true, false, mtime); - if (code != Py_None && code != NULL) { + if (code != Py_None && code != nullptr) { return code; } if (code) { @@ -867,11 +863,11 @@ static struct PyModuleDef PythonQtImport_def = { "PythonQtImport", /* m_name */ mlabimport_doc, /* m_doc */ -1, /* m_size */ - NULL, /* m_methods */ - NULL, /* m_reload */ - NULL, /* m_traverse */ - NULL, /* m_clear */ - NULL /* m_free */ + nullptr, /* m_methods */ + nullptr, /* m_reload */ + nullptr, /* m_traverse */ + nullptr, /* m_clear */ + nullptr /* m_free */ }; #endif @@ -911,8 +907,8 @@ void PythonQtImport::init() #endif PythonQtImportError = PyErr_NewException(const_cast("PythonQtImport.PythonQtImportError"), - PyExc_ImportError, NULL); - if (PythonQtImportError == NULL) + PyExc_ImportError, nullptr); + if (PythonQtImportError == nullptr) return; Py_INCREF(PythonQtImportError); diff --git a/src/PythonQtInstanceWrapper.cpp b/src/PythonQtInstanceWrapper.cpp index 7b99e8e9d..08ba737a3 100644 --- a/src/PythonQtInstanceWrapper.cpp +++ b/src/PythonQtInstanceWrapper.cpp @@ -58,13 +58,13 @@ static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self, PythonQt::priv()->removeWrapperPointer(self->_wrappedPtr); // we own our qobject, so we delete it now: delete self->_obj; - self->_obj = NULL; + self->_obj = nullptr; // if this object is reference counted, we just unref it: PythonQtVoidPtrCB* unrefCB = self->classInfo()->referenceCountingUnrefCB(); if (unrefCB) { (*unrefCB)(self->_wrappedPtr); - self->_wrappedPtr = NULL; + self->_wrappedPtr = nullptr; } else if (force || self->_ownedByPythonQt) { int type = self->classInfo()->metaTypeId(); @@ -75,10 +75,10 @@ static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self, PythonQtSlotInfo* slot = self->classInfo()->destructor(); if (slot) { void* args[2]; - args[0] = NULL; + args[0] = nullptr; args[1] = &self->_wrappedPtr; PythonQtSlotInfo::invokeQtMethod(slot->decorator(), slot, args); - self->_wrappedPtr = NULL; + self->_wrappedPtr = nullptr; } else { if (type>=0) { // use QMetaType to destroy the object @@ -99,7 +99,7 @@ static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self, PythonQtShellSetInstanceWrapperCB* cb = self->classInfo()->shellSetInstanceWrapperCB(); if (cb) { // remove the pointer to the Python wrapper from the C++ object: - (*cb)(self->_obj, NULL); + (*cb)(self->_obj, nullptr); } } if (force || self->_ownedByPythonQt) { @@ -107,14 +107,14 @@ static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self, delete self->_obj; } } else { - if (self->_obj->parent()==NULL) { + if (self->_obj->parent()==nullptr) { // tell someone who is interested that the qobject is no longer wrapped, if it has no parent PythonQt::qObjectNoLongerWrappedCB(self->_obj); } } } } - self->_obj = NULL; + self->_obj = nullptr; } static void PythonQtInstanceWrapper_dealloc(PythonQtInstanceWrapper* self) @@ -128,16 +128,16 @@ static PyObject* PythonQtInstanceWrapper_new(PyTypeObject *type, PyObject * /*ar { //PythonQtClassWrapper *classType = (PythonQtClassWrapper*)type; PythonQtInstanceWrapper *self; - static PyObject* emptyTuple = NULL; - if (emptyTuple==NULL) { + static PyObject* emptyTuple = nullptr; + if (emptyTuple==nullptr) { emptyTuple = PyTuple_New(0); } - self = (PythonQtInstanceWrapper*)PyBaseObject_Type.tp_new(type, emptyTuple, NULL); + self = (PythonQtInstanceWrapper*)PyBaseObject_Type.tp_new(type, emptyTuple, nullptr); - if (self != NULL) { + if (self != nullptr) { new (&self->_obj) QPointer(); - self->_wrappedPtr = NULL; + self->_wrappedPtr = nullptr; self->_ownedByPythonQt = false; self->_useQMetaTypeDestroy = false; self->_isShellInstance = false; @@ -155,9 +155,9 @@ int PythonQtInstanceWrapper_init(PythonQtInstanceWrapper * self, PyObject * args // we are called from python, try to construct our object if (self->classInfo()->constructors()) { - void* directCPPPointer = NULL; + void* directCPPPointer = nullptr; PythonQtPassThisOwnershipType ownership; - PythonQtSlotFunction_CallImpl(self->classInfo(), NULL, self->classInfo()->constructors(), args, kwds, NULL, &directCPPPointer, &ownership); + PythonQtSlotFunction_CallImpl(self->classInfo(), nullptr, self->classInfo()->constructors(), args, kwds, nullptr, &directCPPPointer, &ownership); if (PyErr_Occurred()) { return -1; } @@ -221,7 +221,7 @@ static PyObject *PythonQtInstanceWrapper_richcompare(PythonQtInstanceWrapper* wr PythonQtInstanceWrapper* w1 = wrapper; PythonQtInstanceWrapper* w2 = (PythonQtInstanceWrapper*)other; // check pointers directly - if (w1->_wrappedPtr != NULL) { + if (w1->_wrappedPtr != nullptr) { if (w1->_wrappedPtr == w2->_wrappedPtr) { areSamePtrs = true; } @@ -299,9 +299,9 @@ static PyObject *PythonQtInstanceWrapper_richcompare(PythonQtInstanceWrapper* wr PyObject* args = PyTuple_New(1); Py_INCREF(other); PyTuple_SET_ITEM(args, 0, other); - PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, NULL, wrapper->_wrappedPtr); + PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, opSlot._slot, args, nullptr, wrapper->_wrappedPtr); Py_DECREF(args); - if (result == NULL) { + if (result == nullptr) { // special handling of EQ and NE, if call fails we just return EQ == false / NE == true. if (code == Py_EQ) { PyErr_Clear(); @@ -329,9 +329,9 @@ static PyObject *PythonQtInstanceWrapper_classname(PythonQtInstanceWrapper* obj) PyObject *PythonQtInstanceWrapper_inherits(PythonQtInstanceWrapper* obj, PyObject *args) { - char *name = NULL; + char *name = nullptr; if (!PyArg_ParseTuple(args, "s:PythonQtInstanceWrapper.inherits",&name)) { - return NULL; + return nullptr; } return PythonQtConv::GetPyBool(obj->classInfo()->inherits(name)); } @@ -346,7 +346,7 @@ PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self) PythonQtMemberInfo deleteSlot = self->classInfo()->member("py_delete"); if (deleteSlot._type == PythonQtMemberInfo::Slot) { // call the py_delete slot instead of internal C++ destructor... - PyObject* resultObj = PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, deleteSlot._slot, NULL, NULL, self->_wrappedPtr); + PyObject* resultObj = PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, deleteSlot._slot, nullptr, nullptr, self->_wrappedPtr); Py_XDECREF(resultObj); } else { PythonQtInstanceWrapper_deleteObject(self, true); @@ -369,7 +369,7 @@ static PyMethodDef PythonQtInstanceWrapper_methods[] = { {"delete", (PyCFunction)PythonQtInstanceWrapper_delete, METH_NOARGS, "Deletes the C++ object (at your own risk, my friend!)" }, -{NULL, NULL, 0, NULL} /* Sentinel */ +{nullptr, nullptr, 0, nullptr} /* Sentinel */ }; @@ -378,8 +378,8 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) const char *attributeName; PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj; - if ((attributeName = PyString_AsString(name)) == NULL) { - return NULL; + if ((attributeName = PyString_AsString(name)) == nullptr) { + return nullptr; } if (qstrcmp(attributeName, "__dict__")==0) { @@ -417,7 +417,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) PythonQtMemberInfo member = wrapper->classInfo()->member(dynamicDictString); if (member._type == PythonQtMemberInfo::Slot) { PyObject* args = PyTuple_New(0); - PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, args, NULL, wrapper->_wrappedPtr); + PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, args, nullptr, wrapper->_wrappedPtr); Py_DECREF(args); if (result) { if (PyDict_Check(result)) { @@ -446,7 +446,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) // we need to bind the class signal to the object PythonQtSignalFunctionObject* sig = (PythonQtSignalFunctionObject*)superAttr; if (sig->_dynamicInfo) { - if (!wrapper->dynamicClassInfo() || wrapper->dynamicClassInfo()->_dynamicMetaObject == NULL) { + if (!wrapper->dynamicClassInfo() || wrapper->dynamicClassInfo()->_dynamicMetaObject == nullptr) { // force creation of meta object: if (wrapper->_obj) { wrapper->_obj->metaObject(); @@ -454,14 +454,14 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) } if (wrapper->dynamicClassInfo()) { // go through the whole inheritance chain to find a signal in the dynamic class info: - PythonQtClassInfo* classInfo = NULL; + PythonQtClassInfo* classInfo = nullptr; PythonQtClassWrapper* classType = (PythonQtClassWrapper*)Py_TYPE(wrapper); while (classType->_dynamicClassInfo) { classInfo = classType->_dynamicClassInfo->_classInfo; if (classInfo) { PythonQtMemberInfo member = classInfo->member(attributeName); if (member._type == PythonQtMemberInfo::Signal) { - PyObject* boundSignal = PythonQtSignalFunction_New(member._slot, (PyObject*)wrapper, NULL); + PyObject* boundSignal = PythonQtSignalFunction_New(member._slot, (PyObject*)wrapper, nullptr); Py_DECREF(superAttr); return boundSignal; } @@ -488,13 +488,13 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) QString methodName = "getProperty('"; methodName += attributeName; methodName += "')"; - profilingCB(PythonQt::Enter, wrapper->_obj->metaObject()->className(), QStringToPythonConstCharPointer(methodName), NULL); + profilingCB(PythonQt::Enter, wrapper->_obj->metaObject()->className(), QStringToPythonConstCharPointer(methodName), nullptr); } PyObject* value = PythonQtConv::QVariantToPyObject(member._property.read(wrapper->_obj)); if (profilingCB) { - profilingCB(PythonQt::Leave, NULL, NULL, NULL); + profilingCB(PythonQt::Leave, nullptr, nullptr, nullptr); } return value; @@ -506,14 +506,14 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) } else { QString error = QString("Trying to read property '") + attributeName + "' from a destroyed " + wrapper->classInfo()->className() + " object"; PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(error)); - return NULL; + return nullptr; } break; case PythonQtMemberInfo::Slot: - return PythonQtSlotFunction_New(member._slot, obj, NULL); + return PythonQtSlotFunction_New(member._slot, obj, nullptr); break; case PythonQtMemberInfo::Signal: - return PythonQtSignalFunction_New(member._slot, obj, NULL); + return PythonQtSignalFunction_New(member._slot, obj, nullptr); break; case PythonQtMemberInfo::EnumValue: { @@ -536,7 +536,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) // check for a getter slot PythonQtMemberInfo member = wrapper->classInfo()->member(getterString + attributeName); if (member._type == PythonQtMemberInfo::Slot) { - return PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, NULL, NULL, wrapper->_wrappedPtr); + return PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, nullptr, nullptr, wrapper->_wrappedPtr); } { @@ -547,7 +547,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) PyObject* args = PyTuple_New(1); Py_INCREF(name); PyTuple_SET_ITEM(args, 0, name); - PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, args, NULL, wrapper->_wrappedPtr); + PyObject* result = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, member._slot, args, nullptr, wrapper->_wrappedPtr); Py_DECREF(args); if (result) { return result; @@ -601,7 +601,7 @@ static PyObject *PythonQtInstanceWrapper_getattro(PyObject *obj,PyObject *name) } PyErr_SetString(PyExc_AttributeError, QStringToPythonConstCharPointer(error)); - return NULL; + return nullptr; } static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObject *value) @@ -610,7 +610,7 @@ static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec const char *attributeName; PythonQtInstanceWrapper *wrapper = (PythonQtInstanceWrapper *)obj; - if ((attributeName = PyString_AsString(name)) == NULL) + if ((attributeName = PyString_AsString(name)) == nullptr) return -1; PythonQtMemberInfo member = wrapper->classInfo()->member(attributeName); @@ -639,13 +639,13 @@ static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec QString methodName = "setProperty('"; methodName += attributeName; methodName += "')"; - profilingCB(PythonQt::Enter, wrapper->_obj->metaObject()->className(), QStringToPythonConstCharPointer(methodName), NULL); + profilingCB(PythonQt::Enter, wrapper->_obj->metaObject()->className(), QStringToPythonConstCharPointer(methodName), nullptr); } success = prop.write(wrapper->_obj, v); if (profilingCB) { - profilingCB(PythonQt::Leave, NULL, NULL, NULL); + profilingCB(PythonQt::Leave, nullptr, nullptr, nullptr); } } if (success) { @@ -679,7 +679,7 @@ static int PythonQtInstanceWrapper_setattro(PyObject *obj,PyObject *name,PyObjec PyObject* args = PyTuple_New(1); Py_INCREF(value); PyTuple_SET_ITEM(args, 0, value); - PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, setter._slot, args, NULL, wrapper->_wrappedPtr, &result); + PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, setter._slot, args, nullptr, wrapper->_wrappedPtr, &result); Py_DECREF(args); return 0; } @@ -746,7 +746,7 @@ static QString getStringFromObject(PythonQtInstanceWrapper* wrapper) { // next, try to call py_toString PythonQtMemberInfo info = wrapper->classInfo()->member("py_toString"); if (info._type == PythonQtMemberInfo::Slot) { - PyObject* resultObj = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, info._slot, NULL, NULL, wrapper->_wrappedPtr); + PyObject* resultObj = PythonQtSlotFunction_CallImpl(wrapper->classInfo(), wrapper->_obj, info._slot, nullptr, nullptr, wrapper->_wrappedPtr); if (resultObj) { result = PythonQtConv::PyObjGetString(resultObj); Py_DECREF(resultObj); @@ -829,13 +829,13 @@ static PyObject * PythonQtInstanceWrapper_repr(PyObject * obj) static int PythonQtInstanceWrapper_builtin_nonzero(PyObject *obj) { PythonQtInstanceWrapper* wrapper = (PythonQtInstanceWrapper*)obj; - return (wrapper->_wrappedPtr == NULL && wrapper->_obj == NULL)?0:1; + return (wrapper->_wrappedPtr == nullptr && wrapper->_obj == nullptr)?0:1; } static long PythonQtInstanceWrapper_hash(PythonQtInstanceWrapper *obj) { - if (obj->_wrappedPtr != NULL) { + if (obj->_wrappedPtr != nullptr) { return static_cast(reinterpret_cast(obj->_wrappedPtr)); } else { QObject* qobj = obj->_obj; // get pointer from QPointer wrapper @@ -847,103 +847,103 @@ static long PythonQtInstanceWrapper_hash(PythonQtInstanceWrapper *obj) // we override nb_nonzero, so that one can do 'if' expressions to test for a NULL ptr static PyNumberMethods PythonQtInstanceWrapper_as_number = { - 0, /* nb_add */ - 0, /* nb_subtract */ - 0, /* nb_multiply */ + nullptr, /* nb_add */ + nullptr, /* nb_subtract */ + nullptr, /* nb_multiply */ #ifndef PY3K - 0, /* nb_divide */ + nullptr, /* nb_divide */ #endif - 0, /* nb_remainder */ - 0, /* nb_divmod */ - 0, /* nb_power */ - 0, /* nb_negative */ - 0, /* nb_positive */ - 0, /* nb_absolute */ + nullptr, /* nb_remainder */ + nullptr, /* nb_divmod */ + nullptr, /* nb_power */ + nullptr, /* nb_negative */ + nullptr, /* nb_positive */ + nullptr, /* nb_absolute */ PythonQtInstanceWrapper_builtin_nonzero, /* nb_nonzero / nb_bool in Py3K */ - 0, /* nb_invert */ - 0, /* nb_lshift */ - 0, /* nb_rshift */ - 0, /* nb_and */ - 0, /* nb_xor */ - 0, /* nb_or */ + nullptr, /* nb_invert */ + nullptr, /* nb_lshift */ + nullptr, /* nb_rshift */ + nullptr, /* nb_and */ + nullptr, /* nb_xor */ + nullptr, /* nb_or */ #ifndef PY3K - 0, /* nb_coerce */ + nullptr, /* nb_coerce */ #endif - 0, /* nb_int */ - 0, /* nb_long / nb_reserved in Py3K */ - 0, /* nb_float */ + nullptr, /* nb_int */ + nullptr, /* nb_long / nb_reserved in Py3K */ + nullptr, /* nb_float */ #ifndef PY3K - 0, /* nb_oct */ - 0, /* nb_hex */ + nullptr, /* nb_oct */ + nullptr, /* nb_hex */ #endif - 0, /* nb_inplace_add */ - 0, /* nb_inplace_subtract */ - 0, /* nb_inplace_multiply */ + nullptr, /* nb_inplace_add */ + nullptr, /* nb_inplace_subtract */ + nullptr, /* nb_inplace_multiply */ #ifndef PY3K - 0, /* nb_inplace_divide */ + nullptr, /* nb_inplace_divide */ #endif - 0, /* nb_inplace_remainder */ - 0, /* nb_inplace_power */ - 0, /* nb_inplace_lshift */ - 0, /* nb_inplace_rshift */ - 0, /* nb_inplace_and */ - 0, /* nb_inplace_xor */ - 0, /* nb_inplace_or */ - 0, /* nb_floor_divide */ - 0, /* nb_true_divide */ - 0, /* nb_inplace_floor_divide */ - 0, /* nb_inplace_true_divide */ + nullptr, /* nb_inplace_remainder */ + nullptr, /* nb_inplace_power */ + nullptr, /* nb_inplace_lshift */ + nullptr, /* nb_inplace_rshift */ + nullptr, /* nb_inplace_and */ + nullptr, /* nb_inplace_xor */ + nullptr, /* nb_inplace_or */ + nullptr, /* nb_floor_divide */ + nullptr, /* nb_true_divide */ + nullptr, /* nb_inplace_floor_divide */ + nullptr, /* nb_inplace_true_divide */ #ifdef PY3K - 0, /* nb_index in Py3K */ + nullptr, /* nb_index in Py3K */ #endif }; PyTypeObject PythonQtInstanceWrapper_Type = { PyVarObject_HEAD_INIT(&PythonQtClassWrapper_Type, 0) - "PythonQt.PythonQtInstanceWrapper", /*tp_name*/ + "PythonQt.PythonQtInstanceWrapper", /*tp_name*/ sizeof(PythonQtInstanceWrapper), /*tp_basicsize*/ - 0, /*tp_itemsize*/ + 0, /*tp_itemsize*/ (destructor)PythonQtInstanceWrapper_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - PythonQtInstanceWrapper_repr, /*tp_repr*/ - &PythonQtInstanceWrapper_as_number, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - (hashfunc)PythonQtInstanceWrapper_hash, /*tp_hash */ - 0, /*tp_call*/ - PythonQtInstanceWrapper_str, /*tp_str*/ - PythonQtInstanceWrapper_getattro, /*tp_getattro*/ - PythonQtInstanceWrapper_setattro, /*tp_setattro*/ - 0, /*tp_as_buffer*/ + 0, /*tp_vectorcall_offset*/ + nullptr, /*tp_getattr*/ + nullptr, /*tp_setattr*/ + nullptr, /*tp_compare*/ + PythonQtInstanceWrapper_repr, /*tp_repr*/ + &PythonQtInstanceWrapper_as_number, /*tp_as_number*/ + nullptr, /*tp_as_sequence*/ + nullptr, /*tp_as_mapping*/ + (hashfunc)PythonQtInstanceWrapper_hash, /*tp_hash */ + nullptr, /*tp_call*/ + PythonQtInstanceWrapper_str, /*tp_str*/ + PythonQtInstanceWrapper_getattro, /*tp_getattro*/ + PythonQtInstanceWrapper_setattro, /*tp_setattro*/ + nullptr, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE #ifndef PY3K | Py_TPFLAGS_CHECKTYPES #endif , /*tp_flags*/ - "PythonQtInstanceWrapper object", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)PythonQtInstanceWrapper_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ -#ifdef PY3K - PythonQtInstanceWrapper_methods, -#else - 0, /* tp_methods */ -#endif - 0, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ - 0, /* tp_dictoffset */ + "PythonQtInstanceWrapper object", /* tp_doc */ + nullptr, /* tp_traverse */ + nullptr, /* tp_clear */ + (richcmpfunc)PythonQtInstanceWrapper_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ +#ifdef PY3K + PythonQtInstanceWrapper_methods, +#else + 0, /* tp_methods */ +#endif + nullptr, /* tp_members */ + nullptr, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + nullptr, /* tp_descr_get */ + nullptr, /* tp_descr_set */ + 0, /* tp_dictoffset */ (initproc)PythonQtInstanceWrapper_init, /* tp_init */ - 0, /* tp_alloc */ + nullptr, /* tp_alloc */ PythonQtInstanceWrapper_new, /* tp_new */ }; diff --git a/src/PythonQtInstanceWrapper.h b/src/PythonQtInstanceWrapper.h index 8c04d03e4..afdea68a1 100644 --- a/src/PythonQtInstanceWrapper.h +++ b/src/PythonQtInstanceWrapper.h @@ -64,7 +64,7 @@ struct PythonQtInstanceWrapper { PyObject_HEAD //! the class information, this is set even if the _obj or _wrappedPtr is NULL to support typed NULL pointers - inline PythonQtClassInfo* classInfo() + inline PythonQtClassInfo* classInfo() { return ((PythonQtClassWrapper*)Py_TYPE(this))->_classInfo; } inline PythonQtDynamicClassInfo* dynamicClassInfo() diff --git a/src/PythonQtMethodInfo.cpp b/src/PythonQtMethodInfo.cpp index e06abff6b..e1d91ec75 100644 --- a/src/PythonQtMethodInfo.cpp +++ b/src/PythonQtMethodInfo.cpp @@ -73,10 +73,10 @@ PythonQtMethodInfo::PythonQtMethodInfo(const QMetaMethod& meta, PythonQtClassInf PythonQtMethodInfo::PythonQtMethodInfo(const QByteArray& typeName, const QList& args) { ParameterInfo type; - fillParameterInfo(type, typeName, NULL); + fillParameterInfo(type, typeName, nullptr); _parameters.append(type); Q_FOREACH (const QByteArray& name, args) { - fillParameterInfo(type, name, NULL); + fillParameterInfo(type, name, nullptr); _parameters.append(type); } setupAllowThreads(); @@ -135,7 +135,7 @@ void PythonQtMethodInfo::fillParameterInfo(ParameterInfo& type, const QByteArray { QByteArray name = orgName; - type.enumWrapper = NULL; + type.enumWrapper = nullptr; type.innerNamePointerCount = 0; type.isQList = false; type.passOwnershipToCPP = false; diff --git a/src/PythonQtMethodInfo.h b/src/PythonQtMethodInfo.h index 82ab4dd7c..db8499044 100644 --- a/src/PythonQtMethodInfo.h +++ b/src/PythonQtMethodInfo.h @@ -70,7 +70,7 @@ class PYTHONQT_EXPORT PythonQtMethodInfo PyObject* enumWrapper; // if it is an enum, a pointer to the enum wrapper int typeId; // a mixture from QMetaType and ParameterType char pointerCount; // the number of pointer indirections - char innerNamePointerCount; // the number of pointer indirections in the inner name + char innerNamePointerCount; // the number of pointer indirections in the inner name bool isConst; bool isReference; bool isQList; @@ -113,7 +113,7 @@ class PYTHONQT_EXPORT PythonQtMethodInfo static void addParameterTypeAlias(const QByteArray& alias, const QByteArray& name); //! fill the parameter info for the given type name - static void fillParameterInfo(ParameterInfo& type, const QByteArray& name, PythonQtClassInfo* classInfo = NULL); + static void fillParameterInfo(ParameterInfo& type, const QByteArray& name, PythonQtClassInfo* classInfo = nullptr); //! returns a parameter info for the given metatype (and creates and caches one if it is not yet present) static const ParameterInfo& getParameterInfoForMetaType(int type); @@ -161,20 +161,20 @@ class PYTHONQT_EXPORT PythonQtSlotInfo : public PythonQtMethodInfo _parameters = info._parameters; _shouldAllowThreads = info._shouldAllowThreads; _slotIndex = info._slotIndex; - _next = NULL; + _next = nullptr; _decorator = info._decorator; _type = info._type; _upcastingOffset = 0; } - PythonQtSlotInfo(PythonQtClassInfo* classInfo, const QMetaMethod& meta, int slotIndex, QObject* decorator = NULL, Type type = MemberSlot ):PythonQtMethodInfo() - { + PythonQtSlotInfo(PythonQtClassInfo* classInfo, const QMetaMethod& meta, int slotIndex, QObject* decorator = nullptr, Type type = MemberSlot ):PythonQtMethodInfo() + { const PythonQtMethodInfo* info = getCachedMethodInfo(meta, classInfo); _meta = meta; _parameters = info->parameters(); _shouldAllowThreads = info->shouldAllowThreads(); _slotIndex = slotIndex; - _next = NULL; + _next = nullptr; _decorator = decorator; _type = type; _upcastingOffset = 0; @@ -203,10 +203,10 @@ class PYTHONQT_EXPORT PythonQtSlotInfo : public PythonQtMethodInfo void setNextInfo(PythonQtSlotInfo* next) { _next = next; } //! returns if the slot is a decorator slot - bool isInstanceDecorator() const { return _decorator!=NULL && _type == InstanceDecorator; } + bool isInstanceDecorator() const { return _decorator!=nullptr && _type == InstanceDecorator; } //! returns if the slot is a constructor slot - bool isClassDecorator() const { return _decorator!=NULL && _type == ClassDecorator; } + bool isClassDecorator() const { return _decorator!=nullptr && _type == ClassDecorator; } QObject* decorator() const { return _decorator; } diff --git a/src/PythonQtMisc.cpp b/src/PythonQtMisc.cpp index 3575156df..fdc90871d 100644 --- a/src/PythonQtMisc.cpp +++ b/src/PythonQtMisc.cpp @@ -44,11 +44,11 @@ #define PYTHONQT_MAX_ARGUMENT_FRAME_SIZE (PYTHONQT_MAX_ARGS * 2) -PythonQtArgumentFrame* PythonQtArgumentFrame::_freeListHead = NULL; +PythonQtArgumentFrame* PythonQtArgumentFrame::_freeListHead = nullptr; PythonQtArgumentFrame::PythonQtArgumentFrame() { - _freeListNext = NULL; + _freeListNext = nullptr; // it is important to reserve the memory immediately, // otherwise pointers would change while pushing back new arguments. @@ -62,11 +62,11 @@ PythonQtArgumentFrame::~PythonQtArgumentFrame() PythonQtArgumentFrame* PythonQtArgumentFrame::newFrame() { - PythonQtArgumentFrame* frame = NULL; + PythonQtArgumentFrame* frame = nullptr; if (_freeListHead) { frame = _freeListHead; _freeListHead = _freeListHead->_freeListNext; - frame->_freeListNext = NULL; + frame->_freeListNext = nullptr; } else { frame = new PythonQtArgumentFrame(); } @@ -88,7 +88,7 @@ void PythonQtArgumentFrame::cleanupFreeList() head = head->_freeListNext; delete tmp; } - _freeListHead = NULL; + _freeListHead = nullptr; } void PythonQtArgumentFrame::reset() diff --git a/src/PythonQtObjectPtr.cpp b/src/PythonQtObjectPtr.cpp index fe906c79e..b0486004c 100644 --- a/src/PythonQtObjectPtr.cpp +++ b/src/PythonQtObjectPtr.cpp @@ -113,7 +113,7 @@ void PythonQtObjectPtr::setNewRef(PyObject* o) bool PythonQtObjectPtr::fromVariant(const QVariant& variant) { if (!variant.isNull()) { - PyObject* object = NULL; + PyObject* object = nullptr; if (PythonQt::priv()->isPythonQtSafeObjectPtrMetaId(variant.userType())) { object = (*((const PythonQtSafeObjectPtr*)variant.constData())).object(); } else if (PythonQt::priv()->isPythonQtObjectPtrMetaId(variant.userType())) { @@ -123,7 +123,7 @@ bool PythonQtObjectPtr::fromVariant(const QVariant& variant) return true; } else { - setObject(NULL); + setObject(nullptr); return false; } } @@ -137,7 +137,7 @@ QVariant PythonQtObjectPtr::toVariant() PythonQtObjectPtr & PythonQtObjectPtr::operator=(PythonQtSafeObjectPtr &&p) { if (_object) { - setObject(NULL); + setObject(nullptr); } _object = p.takeObject(); return *this; diff --git a/src/PythonQtObjectPtr.h b/src/PythonQtObjectPtr.h index 0300e7df7..a1591fee5 100644 --- a/src/PythonQtObjectPtr.h +++ b/src/PythonQtObjectPtr.h @@ -56,10 +56,10 @@ class PythonQtSafeObjectPtr; class PYTHONQT_EXPORT PythonQtObjectPtr { public: - PythonQtObjectPtr():_object(NULL) {} + PythonQtObjectPtr():_object(nullptr) {} PythonQtObjectPtr(const PythonQtObjectPtr &p) - :_object(NULL) { + :_object(nullptr) { setObject(p.object()); } @@ -72,14 +72,14 @@ class PYTHONQT_EXPORT PythonQtObjectPtr PythonQtObjectPtr(PythonQtSafeObjectPtr &&p); //! If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count. - PythonQtObjectPtr(const QVariant& variant):_object(NULL) { + PythonQtObjectPtr(const QVariant& variant):_object(nullptr) { fromVariant(variant); } PythonQtObjectPtr(PyObject* o); - + ~PythonQtObjectPtr(); - + //! If the given variant holds a PythonQtObjectPtr, extract the value from it and hold onto the reference. This results in an increment of the reference count. bool fromVariant(const QVariant& variant); @@ -97,7 +97,7 @@ class PYTHONQT_EXPORT PythonQtObjectPtr //! rvalue assignment operator that steals the reference from p PythonQtObjectPtr &operator=(PythonQtObjectPtr &&p) { if (_object) { - setObject(NULL); + setObject(nullptr); } _object = p.takeObject(); return *this; @@ -144,7 +144,7 @@ class PYTHONQT_EXPORT PythonQtObjectPtr //! sets the object and passes the ownership (stealing the reference, in Python slang) void setNewRef(PyObject* o); - + PyObject* object() const { return _object; } @@ -181,14 +181,14 @@ class PYTHONQT_EXPORT PythonQtObjectPtr //! the caller has to take care about the decref of the taken object! PyObject* takeObject() { PyObject* o = _object; - _object = NULL; + _object = nullptr; return o; } protected: void setObject(PyObject* o); - + private: PyObject* _object; }; @@ -197,22 +197,22 @@ class PYTHONQT_EXPORT PythonQtObjectPtr class PYTHONQT_EXPORT PythonQtSafeObjectPtr { public: - PythonQtSafeObjectPtr() :_object(NULL) {} + PythonQtSafeObjectPtr() :_object(nullptr) {} PythonQtSafeObjectPtr(const PythonQtSafeObjectPtr &p) - :_object(NULL) { + :_object(nullptr) { setObject(p.object()); } PythonQtSafeObjectPtr(const PythonQtObjectPtr &p) - :_object(NULL) { + :_object(nullptr) { setObject(p.object()); } //! rvalue copy constructor, does not need any incref/decref. PythonQtSafeObjectPtr(PythonQtSafeObjectPtr &&p) :_object(p._object) { - p._object = NULL; + p._object = nullptr; } //! rvalue copy constructor, does not need any incref/decref. @@ -237,17 +237,17 @@ class PYTHONQT_EXPORT PythonQtSafeObjectPtr //! rvalue assignment operator that steals the reference from p PythonQtSafeObjectPtr &operator=(PythonQtSafeObjectPtr &&p) { if (_object) { - setObject(NULL); + setObject(nullptr); } _object = p._object; - p._object = NULL; + p._object = nullptr; return *this; } //! rvalue assignment operator that steals the reference from p PythonQtSafeObjectPtr &operator=(PythonQtObjectPtr &&p) { if (_object) { - setObjectUnsafe(NULL); + setObjectUnsafe(nullptr); } _object = p.takeObject(); return *this; @@ -290,7 +290,7 @@ class PYTHONQT_EXPORT PythonQtSafeObjectPtr //! the caller has to take care about the decref of the taken object! PyObject* takeObject() { PyObject* o = _object; - _object = NULL; + _object = nullptr; return o; } diff --git a/src/PythonQtProperty.cpp b/src/PythonQtProperty.cpp index af306e99f..09e020e3b 100644 --- a/src/PythonQtProperty.cpp +++ b/src/PythonQtProperty.cpp @@ -40,7 +40,7 @@ int PythonQtProperty_init(PyObject *object, PyObject *args, PyObject *kw) self->data = new PythonQtPropertyData(); PythonQtPropertyData* data = self->data; - PyObject* type = 0; + PyObject* type = nullptr; static const char *kwlist[] = { "type", @@ -48,7 +48,7 @@ int PythonQtProperty_init(PyObject *object, PyObject *args, PyObject *kw) "doc", "designable", "scriptable", "stored", "user", "constant", "final", "notify", - 0 + nullptr }; if (!PyArg_ParseTupleAndKeywords(args, kw, @@ -69,19 +69,19 @@ int PythonQtProperty_init(PyObject *object, PyObject *args, PyObject *kw) } if (data->fget == Py_None) { - data->fget = NULL; + data->fget = nullptr; } if (data->fset == Py_None) { - data->fset = NULL; + data->fset = nullptr; } if (data->freset == Py_None) { - data->freset = NULL; + data->freset = nullptr; } if (data->fdel == Py_None) { - data->fdel = NULL; + data->fdel = nullptr; } if (data->doc == Py_None) { - data->doc = NULL; + data->doc = nullptr; } if (data->fdel) { std::cerr << "Property: fdel is not yet supported!" << std::endl; @@ -109,7 +109,7 @@ void PythonQtProperty_dealloc(PyObject* object) Py_CLEAR(self->data->doc); delete self->data; - self->data = NULL; + self->data = nullptr; Py_TYPE(object)->tp_free(object); } @@ -128,7 +128,7 @@ PyObject* PythonQtProperty_setter(PyObject* object, PyObject* func) return object; } else { PyErr_SetString(PyExc_TypeError, "Property needs a callable as fset."); - return 0; + return nullptr; } } @@ -147,7 +147,7 @@ PyObject* PythonQtProperty_getter(PyObject* object, PyObject* func) return object; } else { PyErr_SetString(PyExc_TypeError, "Property needs a callable as fget."); - return 0; + return nullptr; } } @@ -158,7 +158,7 @@ PyObject* PythonQtProperty_call(PyObject* object, PyObject* args, PyObject* kw) return PythonQtProperty_getter(object, func); } else { PyErr_SetString(PyExc_TypeError, "Property expects a single callable."); - return 0; + return nullptr; } } @@ -167,7 +167,7 @@ static PyMethodDef PythonQtProperty_methods[] = { { "getter", (PyCFunction)PythonQtProperty_getter, METH_O, "Sets the fget function." }, { "write", (PyCFunction)PythonQtProperty_setter, METH_O, "Sets the fset function." }, { "read", (PyCFunction)PythonQtProperty_getter, METH_O, "Sets the fget function." }, - { NULL, NULL, 0, NULL } /* Sentinel */ + { nullptr, nullptr, 0, nullptr } /* Sentinel */ }; @@ -184,8 +184,8 @@ static PyObject *PythonQtProperty_get_doc(PythonQtProperty* self, void * /*closu } static PyGetSetDef PythonQtProperty_getsets[] = { - { const_cast("__doc__"), (getter)PythonQtProperty_get_doc, NULL, NULL }, - { NULL, NULL, NULL,NULL }, + { const_cast("__doc__"), (getter)PythonQtProperty_get_doc, nullptr, nullptr }, + { nullptr, nullptr, nullptr,nullptr }, }; PyDoc_STRVAR(PythonQtProperty_doc, @@ -199,47 +199,47 @@ PyTypeObject PythonQtProperty_Type = { sizeof(PythonQtProperty), /*tp_basicsize*/ 0, /*tp_itemsize*/ PythonQtProperty_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ + 0, /*tp_vectorcall_offset*/ + nullptr, /*tp_getattr*/ + nullptr, /*tp_setattr*/ + nullptr, /*tp_compare*/ + nullptr, /*tp_repr*/ + nullptr, /*tp_as_number*/ + nullptr, /*tp_as_sequence*/ + nullptr, /*tp_as_mapping*/ + nullptr, /*tp_hash */ PythonQtProperty_call, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ + nullptr, /*tp_str*/ + nullptr, /*tp_getattro*/ + nullptr, /*tp_setattro*/ + nullptr, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ PythonQtProperty_doc, /*tp_doc */ - 0, /*tp_traverse */ - 0, /*tp_clear */ - 0, /*tp_richcompare */ + nullptr, /*tp_traverse */ + nullptr, /*tp_clear */ + nullptr, /*tp_richcompare */ 0, /*tp_weaklistoffset */ - 0, /*tp_iter */ - 0, /*tp_iternext */ + nullptr, /*tp_iter */ + nullptr, /*tp_iternext */ PythonQtProperty_methods, /*tp_methods */ - 0, /*tp_members */ + nullptr, /*tp_members */ PythonQtProperty_getsets, /*tp_getset */ - 0, /*tp_base */ - 0, /*tp_dict */ - 0, /*tp_descr_get */ - 0, /*tp_descr_set */ + nullptr, /*tp_base */ + nullptr, /*tp_dict */ + nullptr, /*tp_descr_get */ + nullptr, /*tp_descr_set */ 0, /*tp_dictoffset */ PythonQtProperty_init, /*tp_init */ - 0, /*tp_alloc */ + nullptr, /*tp_alloc */ PyType_GenericNew, /*tp_new */ - 0, /*tp_free */ - 0, /*tp_is_gc */ - 0, /*tp_bases */ - 0, /*tp_mro */ - 0, /*tp_cache */ - 0, /*tp_subclasses */ - 0, /*tp_weaklist */ - 0, /*tp_del */ + nullptr, /*tp_free */ + nullptr, /*tp_is_gc */ + nullptr, /*tp_bases */ + nullptr, /*tp_mro */ + nullptr, /*tp_cache */ + nullptr, /*tp_subclasses */ + nullptr, /*tp_weaklist */ + nullptr, /*tp_del */ }; bool PythonQtPropertyData::callSetter(PyObject* wrapper, PyObject* newValue) @@ -253,7 +253,7 @@ bool PythonQtPropertyData::callSetter(PyObject* wrapper, PyObject* newValue) PyObject* result = PyObject_CallObject(fset, pyargs); - bool ok = (result != NULL); + bool ok = (result != nullptr); Py_XDECREF(result); Py_DECREF(pyargs); return ok; @@ -274,7 +274,7 @@ PyObject* PythonQtPropertyData::callGetter(PyObject* wrapper) return value; } else { PyErr_Format(PyExc_TypeError, "Property is write only."); - return NULL; + return nullptr; } } @@ -285,7 +285,7 @@ bool PythonQtPropertyData::callReset(PyObject* wrapper) PyTuple_SET_ITEM(pyargs, 0, wrapper); Py_INCREF(wrapper); PyObject* result = PyObject_CallObject(freset, pyargs); - bool ok = (result != NULL); + bool ok = (result != nullptr); Py_XDECREF(result); Py_DECREF(pyargs); return ok; diff --git a/src/PythonQtProperty.h b/src/PythonQtProperty.h index 8c95ea121..ef4d6a3cb 100644 --- a/src/PythonQtProperty.h +++ b/src/PythonQtProperty.h @@ -46,12 +46,12 @@ extern PYTHONQT_EXPORT PyTypeObject PythonQtProperty_Type; struct PythonQtPropertyData { PythonQtPropertyData() { - fget = NULL; - fset = NULL; - fdel = NULL; - freset = NULL; - notify = NULL; - doc = NULL; + fget = nullptr; + fset = nullptr; + fdel = nullptr; + freset = nullptr; + notify = nullptr; + doc = nullptr; designable = true; scriptable = true; stored = true; diff --git a/src/PythonQtSignal.cpp b/src/PythonQtSignal.cpp index f14408dcf..3d2e3b7b3 100644 --- a/src/PythonQtSignal.cpp +++ b/src/PythonQtSignal.cpp @@ -56,7 +56,7 @@ //----------------------------------------------------------------------------------- -static PythonQtSignalFunctionObject *PythonQtSignal_free_list = NULL; +static PythonQtSignalFunctionObject *PythonQtSignal_free_list = nullptr; PyObject *PythonQtSignalFunction_Call(PyObject *func, PyObject *args, PyObject *kw) { @@ -66,7 +66,7 @@ PyObject *PythonQtSignalFunction_Call(PyObject *func, PyObject *args, PyObject * PyObject *PythonQtSignalFunction_tpNew(PyTypeObject *subtype, PyObject *args, PyObject *kwds) { - return PythonQtSignalFunction_New(NULL, NULL, NULL); + return PythonQtSignalFunction_New(nullptr, nullptr, nullptr); } PyObject * @@ -74,16 +74,16 @@ PythonQtSignalFunction_New(PythonQtSlotInfo *ml, PyObject *self, PyObject *modul { PythonQtSignalFunctionObject *op; op = PythonQtSignal_free_list; - if (op != NULL) { + if (op != nullptr) { PythonQtSignal_free_list = (PythonQtSignalFunctionObject *)(op->m_self); PyObject_INIT(op, &PythonQtSignalFunction_Type); } else { op = PyObject_GC_New(PythonQtSignalFunctionObject, &PythonQtSignalFunction_Type); - if (op == NULL) - return NULL; + if (op == nullptr) + return nullptr; } - op->_dynamicInfo = NULL; + op->_dynamicInfo = nullptr; op->m_ml = ml; Py_XINCREF(self); op->m_self = self; @@ -101,7 +101,7 @@ meth_dealloc(PythonQtSignalFunctionObject *m) PyObject_GC_UnTrack(m); if (m->_dynamicInfo) { delete m->_dynamicInfo; - m->_dynamicInfo = NULL; + m->_dynamicInfo = nullptr; } Py_XDECREF(m->m_self); Py_XDECREF(m->m_module); @@ -130,12 +130,12 @@ static int meth_traverse(PythonQtSignalFunctionObject *m, visitproc visit, void *arg) { int err; - if (m->m_self != NULL) { + if (m->m_self != nullptr) { err = visit(m->m_self, arg); if (err) return err; } - if (m->m_module != NULL) { + if (m->m_module != nullptr) { err = visit(m->m_module, arg); if (err) return err; @@ -155,17 +155,17 @@ meth_get__self__(PythonQtSignalFunctionObject *m, void * /*closure*/) } #endif self = m->m_self; - if (self == NULL) + if (self == nullptr) self = Py_None; Py_INCREF(self); return self; } static PyGetSetDef meth_getsets [] = { - {const_cast("__doc__"), (getter)meth_get__doc__, NULL, NULL}, - {const_cast("__name__"), (getter)meth_get__name__, NULL, NULL}, - {const_cast("__self__"), (getter)meth_get__self__, NULL, NULL}, - {NULL, NULL, NULL,NULL}, + {const_cast("__doc__"), (getter)meth_get__doc__, nullptr, nullptr}, + {const_cast("__name__"), (getter)meth_get__name__, nullptr, nullptr}, + {const_cast("__self__"), (getter)meth_get__self__, nullptr, nullptr}, + {nullptr, nullptr, nullptr,nullptr}, }; #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 6 @@ -176,7 +176,7 @@ static PyGetSetDef meth_getsets [] = { static PyMemberDef meth_members[] = { {const_cast("__module__"), T_OBJECT, OFF(m_module), PY_WRITE_RESTRICTED}, - {NULL} + {nullptr} }; int PythonQtSignalFunction_init(PyObject *object, PyObject *args, PyObject *kw) @@ -261,7 +261,7 @@ static PyObject *PythonQtSignalFunction_connect(PythonQtSignalFunctionObject* ty } } } - return NULL; + return nullptr; } static PyObject *PythonQtSignalFunction_disconnect(PythonQtSignalFunctionObject* type, PyObject *args) @@ -277,21 +277,21 @@ static PyObject *PythonQtSignalFunction_disconnect(PythonQtSignalFunctionObject* bool result = PythonQt::self()->removeSignalHandler(self->_obj, signal, callable); return PythonQtConv::GetPyBool(result); } else if (argc==0) { - bool result = PythonQt::self()->removeSignalHandler(self->_obj, signal, NULL); - result |= QObject::disconnect(self->_obj, signal, NULL, NULL); + bool result = PythonQt::self()->removeSignalHandler(self->_obj, signal, nullptr); + result |= QObject::disconnect(self->_obj, signal, nullptr, nullptr); return PythonQtConv::GetPyBool(result); } else { PyErr_SetString(PyExc_ValueError, "Called disconnect with wrong number of arguments"); } } } - return NULL; + return nullptr; } static PyObject *PythonQtSignalFunction_emit(PythonQtSignalFunctionObject* func, PyObject *args) { PythonQtSignalFunctionObject* f = (PythonQtSignalFunctionObject*)func; - return PythonQtMemberFunction_Call(f->m_ml, f->m_self, args, NULL); + return PythonQtMemberFunction_Call(f->m_ml, f->m_self, args, nullptr); } static PyMethodDef meth_methods[] = { @@ -313,7 +313,7 @@ static PyMethodDef meth_methods[] = { {"emit", (PyCFunction)PythonQtSignalFunction_emit, METH_VARARGS, "Emits the signal with given arguments" }, - {NULL, NULL, 0 , NULL} /* Sentinel */ + {nullptr, nullptr, 0 , nullptr} /* Sentinel */ }; static PyObject * @@ -353,7 +353,7 @@ static long meth_hash(PythonQtSignalFunctionObject *a) { long x,y; - if (a->m_self == NULL) + if (a->m_self == nullptr) x = 0; else { x = PyObject_Hash(a->m_self); @@ -401,53 +401,53 @@ PyTypeObject PythonQtSignalFunction_Type = { "QtCore.Signal", sizeof(PythonQtSignalFunctionObject), 0, - (destructor)meth_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ + (destructor)meth_dealloc, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ + nullptr, /* tp_getattr */ + nullptr, /* tp_setattr */ #ifdef PY3K - 0, + nullptr, #else - (cmpfunc)meth_compare, /* tp_compare */ + (cmpfunc)meth_compare, /* tp_compare */ #endif (reprfunc)meth_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ + nullptr, /* tp_as_number */ + nullptr, /* tp_as_sequence */ // TODO: implement tp_as_mapping to support overload resolution on the signal - 0, /* tp_as_mapping */ + nullptr, /* tp_as_mapping */ (hashfunc)meth_hash, /* tp_hash */ - PythonQtSignalFunction_Call, /* tp_call */ - 0, /* tp_str */ - PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ + PythonQtSignalFunction_Call, /* tp_call */ + nullptr, /* tp_str */ + PyObject_GenericGetAttr, /* tp_getattro */ + nullptr, /* tp_setattro */ + nullptr, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ - PythonQtSignalFunction_doc, /* tp_doc */ + PythonQtSignalFunction_doc, /* tp_doc */ (traverseproc)meth_traverse, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)meth_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - meth_methods, /* tp_methods */ - meth_members, /* tp_members */ - meth_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /*tp_descr_get */ - 0, /*tp_descr_set */ - 0, /*tp_dictoffset */ + nullptr, /* tp_clear */ + (richcmpfunc)meth_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ + meth_methods, /* tp_methods */ + meth_members, /* tp_members */ + meth_getsets, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + nullptr, /*tp_descr_get */ + nullptr, /*tp_descr_set */ + 0, /*tp_dictoffset */ PythonQtSignalFunction_init, /*tp_init */ - 0, /*tp_alloc */ - PythonQtSignalFunction_tpNew, /*tp_new */ - 0, /*tp_free */ - 0, /*tp_is_gc */ - 0, /*tp_bases */ - 0, /*tp_mro */ - 0, /*tp_cache */ - 0, /*tp_subclasses */ - 0, /*tp_weaklist */ - 0, /*tp_del */ + nullptr, /*tp_alloc */ + PythonQtSignalFunction_tpNew, /*tp_new */ + nullptr, /*tp_free */ + nullptr, /*tp_is_gc */ + nullptr, /*tp_bases */ + nullptr, /*tp_mro */ + nullptr, /*tp_cache */ + nullptr, /*tp_subclasses */ + nullptr, /*tp_weaklist */ + nullptr, /*tp_del */ }; diff --git a/src/PythonQtSignalReceiver.cpp b/src/PythonQtSignalReceiver.cpp index 406e1939e..da9e80bc2 100644 --- a/src/PythonQtSignalReceiver.cpp +++ b/src/PythonQtSignalReceiver.cpp @@ -100,7 +100,7 @@ PyObject* PythonQtSignalTarget::call(PyObject* callable, const PythonQtMethodInf } } - PyObject* pargs = NULL; + PyObject* pargs = nullptr; if (count>1) { pargs = PyTuple_New(count-1); } @@ -117,14 +117,14 @@ PyObject* PythonQtSignalTarget::call(PyObject* callable, const PythonQtMethodInf } if (arg) { // steals reference, no unref - PyTuple_SetItem(pargs, i-1,arg); + PyTuple_SetItem(pargs, i-1, arg); } else { err = true; break; } } - PyObject* result = NULL; + PyObject* result = nullptr; if (!err) { PyErr_Clear(); result = PyObject_CallObject(callable, pargs); @@ -196,7 +196,7 @@ bool PythonQtSignalReceiver::addSignalHandler(const char* signal, PyObject* call PythonQtSignalTarget t(sigId, signalInfo, _slotCount, callable); _targets.append(t); // now connect to ourselves with the new slot id - QMetaObject::connect(_obj, sigId, this, _slotCount, Qt::AutoConnection, 0); + QMetaObject::connect(_obj, sigId, this, _slotCount, Qt::AutoConnection, nullptr); _slotCount++; flag = true; diff --git a/src/PythonQtSignalReceiver.h b/src/PythonQtSignalReceiver.h index 16682cf24..7e8e5b134 100644 --- a/src/PythonQtSignalReceiver.h +++ b/src/PythonQtSignalReceiver.h @@ -57,7 +57,7 @@ class PYTHONQT_EXPORT PythonQtSignalTarget { public: PythonQtSignalTarget() { _signalId = -1; - _methodInfo = NULL; + _methodInfo = nullptr; _slotId = -1; } @@ -119,7 +119,7 @@ class PythonQtSignalReceiver : public PythonQtSignalReceiverBase { bool addSignalHandler(const char* signal, PyObject* callable); //! remove a signal handler for given callable (or all callables on that signal if callable is NULL) - bool removeSignalHandler(const char* signal, PyObject* callable = NULL); + bool removeSignalHandler(const char* signal, PyObject* callable = nullptr); //! we implement this method to simulate a number of slots that match the ids in _targets virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments); diff --git a/src/PythonQtSlot.cpp b/src/PythonQtSlot.cpp index 0cc60986a..c72311a67 100644 --- a/src/PythonQtSlot.cpp +++ b/src/PythonQtSlot.cpp @@ -59,13 +59,13 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObject* args, bool strict, PythonQtSlotInfo* info, void* firstArgument, PyObject** pythonReturnValue, void** directReturnValuePointer, PythonQtPassThisOwnershipType* passThisOwnershipToCPP) { if (directReturnValuePointer) { - *directReturnValuePointer = NULL; + *directReturnValuePointer = nullptr; } PythonQtArgumentFrame* frame = PythonQtArgumentFrame::newFrame(); // the arguments that are passed to qt_metacall void* argList[PYTHONQT_MAX_ARGS]; - PyObject* result = NULL; + PyObject* result = nullptr; int argc = info->parameterCount(); const QList& params = info->parameters(); @@ -73,18 +73,16 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj bool isVoidReturnValue = (returnValueParam.typeId == QMetaType::Void); // set return argument to NULL - argList[0] = NULL; + argList[0] = nullptr; bool ok = true; - bool skipFirst = false; PythonQtPassThisOwnershipType passThisOwnership = IgnoreOwnership; int instanceDecoOffset = 0; // it is important to keep arg1 on this scope, because it is stored in argList[1] and // would go away if it is moved into the if scope - void* arg1 = NULL; + void* arg1 = nullptr; if (info->isInstanceDecorator()) { - skipFirst = true; instanceDecoOffset = 1; // for decorators on CPP objects, we take the cpp ptr, for QObjects we take the QObject pointer @@ -101,14 +99,14 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj } for (int i = 1 + instanceDecoOffset; i pass ownership of this to someObject) - if (argList[i] && (*(void**)argList[i])==NULL) { + if (argList[i] && (*(void**)argList[i])==nullptr) { // if the object to which the ownership should be passed is NULL, // we need to pass the ownership to Python passThisOwnership = PassOwnershipToPython; @@ -130,14 +128,14 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj if (!directReturnValuePointer) { // create empty default value for the return value argList[0] = PythonQtConv::CreateQtReturnValue(returnValueParam, frame); - if (argList[0]==NULL) { + if (argList[0]==nullptr) { // return value could not be created, maybe we have a registered class with a default constructor, so that we can construct the pythonqt wrapper object and // pass its internal pointer PythonQtClassInfo* info = PythonQt::priv()->getClassInfo(returnValueParam.name); if (info && info->pythonQtClassWrapper()) { PyObject* emptyTuple = PyTuple_New(0); // 1) default construct an empty object as python object (owned by PythonQt), by calling the meta class with empty arguments - result = PyObject_Call((PyObject*)info->pythonQtClassWrapper(), emptyTuple, NULL); + result = PyObject_Call((PyObject*)info->pythonQtClassWrapper(), emptyTuple, nullptr); if (result) { argList[0] = ((PythonQtInstanceWrapper*)result)->_wrappedPtr; } @@ -153,7 +151,7 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj PythonQt::ProfilingCB* profilingCB = PythonQt::priv()->profilingCB(); if (profilingCB) { - const char* className = NULL; + const char* className = nullptr; if (info->decorator()) { className = info->decorator()->metaObject()->className(); } else { @@ -210,14 +208,14 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj } if (profilingCB) { - profilingCB(PythonQt::Leave, NULL, NULL, NULL); + profilingCB(PythonQt::Leave, nullptr, nullptr, nullptr); } // handle the return value (which in most cases still needs to be converted to a Python object) if (!hadException) { if (argList[0] || isVoidReturnValue) { if (directReturnValuePointer) { - result = NULL; + result = nullptr; } else { // the resulting object maybe present already, because we created it above at 1)... if (!result) { @@ -227,11 +225,11 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj } else { QString e = QString("Called ") + info->fullSignature() + ", return type '" + returnValueParam.name + "' is ignored because it is unknown to PythonQt. Probably you should register it using qRegisterMetaType() or add a default constructor decorator to the class."; PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(e)); - result = NULL; + result = nullptr; ok = false; } } else { - result = NULL; + result = nullptr; ok = false; } } @@ -258,7 +256,7 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj //----------------------------------------------------------------------------------- -static PythonQtSlotFunctionObject *pythonqtslot_free_list = NULL; +static PythonQtSlotFunctionObject *pythonqtslot_free_list = nullptr; PyObject *PythonQtSlotFunction_Call(PyObject *func, PyObject *args, PyObject *kw) { @@ -270,13 +268,13 @@ PyObject *PythonQtMemberFunction_Call(PythonQtSlotInfo* info, PyObject* m_self, { if (PyObject_TypeCheck(m_self, &PythonQtInstanceWrapper_Type)) { PythonQtInstanceWrapper* self = (PythonQtInstanceWrapper*) m_self; - if (!info->isClassDecorator() && (self->_obj==NULL && self->_wrappedPtr==NULL)) { + if (!info->isClassDecorator() && (self->_obj==nullptr && self->_wrappedPtr==nullptr)) { QString error = QString("Trying to call '") + info->slotName() + "' on a destroyed " + self->classInfo()->className() + " object"; PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(error)); - return NULL; + return nullptr; } else { PythonQtPassThisOwnershipType ownership; - PyObject* result = PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, info, args, kw, self->_wrappedPtr, NULL, &ownership); + PyObject* result = PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, info, args, kw, self->_wrappedPtr, nullptr, &ownership); if (ownership == PassOwnershipToCPP) { self->passOwnershipToCPP(); } else if (ownership == PassOwnershipToPython) { @@ -287,7 +285,7 @@ PyObject *PythonQtMemberFunction_Call(PythonQtSlotInfo* info, PyObject* m_self, } else if (m_self->ob_type == &PythonQtClassWrapper_Type) { PythonQtClassWrapper* type = (PythonQtClassWrapper*) m_self; if (info->isClassDecorator()) { - return PythonQtSlotFunction_CallImpl(type->classInfo(), NULL, info, args, kw); + return PythonQtSlotFunction_CallImpl(type->classInfo(), nullptr, info, args, kw); } else { // otherwise, it is an unbound call and we have an instanceDecorator or normal slot... Py_ssize_t argc = PyTuple_Size(args); @@ -296,15 +294,15 @@ PyObject *PythonQtMemberFunction_Call(PythonQtSlotInfo* info, PyObject* m_self, if (PyObject_TypeCheck(firstArg, (PyTypeObject*)&PythonQtInstanceWrapper_Type) && ((PythonQtInstanceWrapper*)firstArg)->classInfo()->inherits(type->classInfo())) { PythonQtInstanceWrapper* self = (PythonQtInstanceWrapper*)firstArg; - if (!info->isClassDecorator() && (self->_obj==NULL && self->_wrappedPtr==NULL)) { + if (!info->isClassDecorator() && (self->_obj==nullptr && self->_wrappedPtr==nullptr)) { QString error = QString("Trying to call '") + info->slotName() + "' on a destroyed " + self->classInfo()->className() + " object"; PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(error)); - return NULL; + return nullptr; } // strip the first argument... PyObject* newargs = PyTuple_GetSlice(args, 1, argc); PythonQtPassThisOwnershipType ownership; - PyObject* result = PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, info, newargs, kw, self->_wrappedPtr, NULL, &ownership); + PyObject* result = PythonQtSlotFunction_CallImpl(self->classInfo(), self->_obj, info, newargs, kw, self->_wrappedPtr, nullptr, &ownership); if (ownership == PassOwnershipToCPP) { self->passOwnershipToCPP(); } else if (ownership == PassOwnershipToPython) { @@ -316,17 +314,17 @@ PyObject *PythonQtMemberFunction_Call(PythonQtSlotInfo* info, PyObject* m_self, // first arg is not of correct type! QString error = "slot " + info->fullSignature() + " requires " + type->classInfo()->className() + " instance as first argument, got " + firstArg->ob_type->tp_name; PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(error)); - return NULL; + return nullptr; } } else { // wrong number of args QString error = "slot " + info->fullSignature() + " requires " + type->classInfo()->className() + " instance as first argument."; PyErr_SetString(PyExc_ValueError, QStringToPythonConstCharPointer(error)); - return NULL; + return nullptr; } } } - return NULL; + return nullptr; } PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject * kw, void* firstArg, void** directReturnValuePointer, PythonQtPassThisOwnershipType* passThisOwnershipToCPP) @@ -337,14 +335,14 @@ PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* o *passThisOwnershipToCPP = IgnoreOwnership; } - PyObject* r = NULL; + PyObject* r = nullptr; bool ok = false; if (directReturnValuePointer) { - *directReturnValuePointer = NULL; + *directReturnValuePointer = nullptr; } - if( (kw != NULL && PyDict_Check(kw) && (PyDict_Size(kw) > 0)) ) { + if( (kw != nullptr && PyDict_Check(kw) && (PyDict_Size(kw) > 0)) ) { // -------------------keyword args slot call ------------------------- // keyword arguments are given as dict, must be mapped to arguments in correct order @@ -451,14 +449,14 @@ PythonQtSlotFunction_New(PythonQtSlotInfo *ml, PyObject *self, PyObject *module) { PythonQtSlotFunctionObject *op; op = pythonqtslot_free_list; - if (op != NULL) { + if (op != nullptr) { pythonqtslot_free_list = (PythonQtSlotFunctionObject *)(op->m_self); PyObject_INIT(op, &PythonQtSlotFunction_Type); } else { op = PyObject_GC_New(PythonQtSlotFunctionObject, &PythonQtSlotFunction_Type); - if (op == NULL) - return NULL; + if (op == nullptr) + return nullptr; } op->m_ml = ml; Py_XINCREF(self); @@ -474,7 +472,7 @@ PythonQtSlotFunction_GetSlotInfo(PyObject *op) { if (!PythonQtSlotFunction_Check(op)) { PyErr_Format(PyExc_SystemError, "%s:%d: bad argument to internal function", __FILE__, __LINE__); - return NULL; + return nullptr; } return ((PythonQtSlotFunctionObject *)op) -> m_ml; } @@ -484,7 +482,7 @@ PythonQtSlotFunction_GetSelf(PyObject *op) { if (!PythonQtSlotFunction_Check(op)) { PyErr_Format(PyExc_SystemError, "%s:%d: bad argument to internal function", __FILE__, __LINE__); - return NULL; + return nullptr; } return ((PythonQtSlotFunctionObject *)op) -> m_self; } @@ -554,7 +552,7 @@ meth_get__doc__(PythonQtSlotFunctionObject * m, void * /*closure*/) pyReturnType = "float"; } else { PythonQtClassInfo* returnTypeClassInfo = PythonQt::priv()->getClassInfo(returnType); - // a class wrapper does not necessarily need to exist + // a class wrapper needs not necessarily to exist if (returnTypeClassInfo && returnTypeClassInfo->pythonQtClassWrapper()) { PyObject* s = PyObject_GetAttrString(returnTypeClassInfo->pythonQtClassWrapper(), "__module__"); if (s) { @@ -579,12 +577,12 @@ static int meth_traverse(PythonQtSlotFunctionObject *m, visitproc visit, void *arg) { int err; - if (m->m_self != NULL) { + if (m->m_self != nullptr) { err = visit(m->m_self, arg); if (err) return err; } - if (m->m_module != NULL) { + if (m->m_module != nullptr) { err = visit(m->m_module, arg); if (err) return err; @@ -604,17 +602,17 @@ meth_get__self__(PythonQtSlotFunctionObject *m, void * /*closure*/) } #endif self = m->m_self; - if (self == NULL) + if (self == nullptr) self = Py_None; Py_INCREF(self); return self; } static PyGetSetDef meth_getsets [] = { - {const_cast("__doc__"), (getter)meth_get__doc__, NULL, NULL}, - {const_cast("__name__"), (getter)meth_get__name__, NULL, NULL}, - {const_cast("__self__"), (getter)meth_get__self__, NULL, NULL}, - {NULL, NULL, NULL,NULL}, + {const_cast("__doc__"), (getter)meth_get__doc__, nullptr, nullptr}, + {const_cast("__name__"), (getter)meth_get__name__, nullptr, nullptr}, + {const_cast("__self__"), (getter)meth_get__self__, nullptr, nullptr}, + {nullptr, nullptr, nullptr,nullptr}, }; #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 6 @@ -625,7 +623,7 @@ static PyGetSetDef meth_getsets [] = { static PyMemberDef meth_members[] = { {const_cast("__module__"), T_OBJECT, OFF(m_module), PY_WRITE_RESTRICTED}, - {NULL} + {nullptr} }; static PyObject *PythonQtSlotFunction_parameterTypes(PythonQtSlotFunctionObject* type) @@ -715,7 +713,7 @@ static PyMethodDef meth_methods[] = { {"typeName", (PyCFunction)PythonQtSlotFunction_typeName, METH_NOARGS, "Returns a tuple of the C++ return value types of each slot overload" }, - {NULL, NULL, 0 , NULL} /* Sentinel */ + {nullptr, nullptr, 0 , nullptr} /* Sentinel */ }; static PyObject * @@ -751,7 +749,7 @@ static long meth_hash(PythonQtSlotFunctionObject *a) { long x,y; - if (a->m_self == NULL) + if (a->m_self == nullptr) x = 0; else { x = PyObject_Hash(a->m_self); @@ -796,7 +794,7 @@ meth_descr_get(PyObject *descr, PyObject *obj, PyObject* type) { if (PythonQtSlotFunction_Check(descr)) { PythonQtSlotFunctionObject *slotObj = (PythonQtSlotFunctionObject*)descr; - return PythonQtSlotFunction_New(slotObj->m_ml, obj, NULL); + return PythonQtSlotFunction_New(slotObj->m_ml, obj, nullptr); } else { // wrong type @@ -810,39 +808,39 @@ PyTypeObject PythonQtSlotFunction_Type = { "builtin_qt_slot", sizeof(PythonQtSlotFunctionObject), 0, - (destructor)meth_dealloc, /* tp_dealloc */ - 0, /* tp_print */ - 0, /* tp_getattr */ - 0, /* tp_setattr */ + (destructor)meth_dealloc, /* tp_dealloc */ + 0, /* tp_vectorcall_offset */ + nullptr, /* tp_getattr */ + nullptr, /* tp_setattr */ #ifdef PY3K - 0, + nullptr, #else (cmpfunc)meth_compare, /* tp_compare */ #endif - (reprfunc)meth_repr, /* tp_repr */ - 0, /* tp_as_number */ - 0, /* tp_as_sequence */ - 0, /* tp_as_mapping */ - (hashfunc)meth_hash, /* tp_hash */ - PythonQtSlotFunction_Call, /* tp_call */ - 0, /* tp_str */ + (reprfunc)meth_repr, /* tp_repr */ + nullptr, /* tp_as_number */ + nullptr, /* tp_as_sequence */ + nullptr, /* tp_as_mapping */ + (hashfunc)meth_hash, /* tp_hash */ + PythonQtSlotFunction_Call, /* tp_call */ + nullptr, /* tp_str */ PyObject_GenericGetAttr, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer */ + nullptr, /* tp_setattro */ + nullptr, /* tp_as_buffer */ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,/* tp_flags */ - 0, /* tp_doc */ - (traverseproc)meth_traverse, /* tp_traverse */ - 0, /* tp_clear */ - (richcmpfunc)meth_richcompare, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - meth_methods, /* tp_methods */ - meth_members, /* tp_members */ - meth_getsets, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - meth_descr_get, /* tp_descr_get */ + nullptr, /* tp_doc */ + (traverseproc)meth_traverse, /* tp_traverse */ + nullptr, /* tp_clear */ + (richcmpfunc)meth_richcompare, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ + meth_methods, /* tp_methods */ + meth_members, /* tp_members */ + meth_getsets, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + meth_descr_get, /* tp_descr_get */ }; /* Clear out the free list */ diff --git a/src/PythonQtSlot.h b/src/PythonQtSlot.h index 699fb29bd..1040a9223 100644 --- a/src/PythonQtSlot.h +++ b/src/PythonQtSlot.h @@ -70,7 +70,7 @@ PyObject* PythonQtSlotFunction_GetSelf(PyObject *); PyObject* PythonQtSlotFunction_Call(PyObject *, PyObject *, PyObject *); -PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject *kw, void* firstArg=NULL, void** directReturnValuePointer=NULL, PythonQtPassThisOwnershipType* passThisOwnershipToCPP = NULL); +PyObject *PythonQtSlotFunction_CallImpl(PythonQtClassInfo* classInfo, QObject* objectToCall, PythonQtSlotInfo* info, PyObject *args, PyObject *kw, void* firstArg=nullptr, void** directReturnValuePointer=nullptr, PythonQtPassThisOwnershipType* passThisOwnershipToCPP = nullptr); PyObject* PythonQtSlotFunction_New(PythonQtSlotInfo *, PyObject *, PyObject *); diff --git a/src/PythonQtSlotDecorator.cpp b/src/PythonQtSlotDecorator.cpp index 1c7f9e736..8e9ea3e55 100644 --- a/src/PythonQtSlotDecorator.cpp +++ b/src/PythonQtSlotDecorator.cpp @@ -39,10 +39,10 @@ int PythonQtSlotDecorator_init(PyObject *object, PyObject *args, PyObject *kw) self->returnType = new QByteArray(); self->args = new QByteArray(); - char* argName = 0; - PyObject* argResult = 0; + char* argName = nullptr; + PyObject* argResult = nullptr; - static const char* kwlist[] = {"name", "result", 0}; + static const char* kwlist[] = {"name", "result", nullptr}; static PyObject* emptyTuple = PyTuple_New(0); if (!PyArg_ParseTupleAndKeywords(emptyTuple, kw, "|sO:QtCore.Slot", (char**) kwlist, &argName, &argResult)) { return 0; @@ -96,7 +96,7 @@ PyObject* PythonQtSlotDecorator_call(PyObject* object, PyObject* args, PyObject* QByteArray signature = returnType + " " + slotName + "(" + *self->args + ")"; static PyObject* qtSlots = PyString_FromString("_qtSlots"); - PyObject* signatures = NULL; + PyObject* signatures = nullptr; if (!PyObject_HasAttr(function, qtSlots)) { // create a new list signatures = PyList_New(0); @@ -127,49 +127,49 @@ PyDoc_STRVAR(PythonQtSlotDecorator_doc, PyTypeObject PythonQtSlotDecorator_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) - "PythonQt.QtCore.Slot", /*tp_name*/ - sizeof(PythonQtSlotDecorator),/*tp_basicsize*/ + "PythonQt.QtCore.Slot", /*tp_name*/ + sizeof(PythonQtSlotDecorator), /*tp_basicsize*/ 0, /*tp_itemsize*/ - 0, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - PythonQtSlotDecorator_call, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ + nullptr, /*tp_dealloc*/ + 0, /*tp_vectorcall_offset*/ + nullptr, /*tp_getattr*/ + nullptr, /*tp_setattr*/ + nullptr, /*tp_compare*/ + nullptr, /*tp_repr*/ + nullptr, /*tp_as_number*/ + nullptr, /*tp_as_sequence*/ + nullptr, /*tp_as_mapping*/ + nullptr, /*tp_hash */ + PythonQtSlotDecorator_call, /*tp_call*/ + nullptr, /*tp_str*/ + nullptr, /*tp_getattro*/ + nullptr, /*tp_setattro*/ + nullptr, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT, /*tp_flags*/ PythonQtSlotDecorator_doc, /*tp_doc */ - 0, /*tp_traverse */ - 0, /*tp_clear */ - 0, /*tp_richcompare */ + nullptr, /*tp_traverse */ + nullptr, /*tp_clear */ + nullptr, /*tp_richcompare */ 0, /*tp_weaklistoffset */ - 0, /*tp_iter */ - 0, /*tp_iternext */ - 0, /*tp_methods */ - 0, /*tp_members */ - 0, /*tp_getset */ - 0, /*tp_base */ - 0, /*tp_dict */ - 0, /*tp_descr_get */ - 0, /*tp_descr_set */ + nullptr, /*tp_iter */ + nullptr, /*tp_iternext */ + nullptr, /*tp_methods */ + nullptr, /*tp_members */ + nullptr, /*tp_getset */ + nullptr, /*tp_base */ + nullptr, /*tp_dict */ + nullptr, /*tp_descr_get */ + nullptr, /*tp_descr_set */ 0, /*tp_dictoffset */ - PythonQtSlotDecorator_init, /*tp_init */ - 0, /*tp_alloc */ + PythonQtSlotDecorator_init, /*tp_init */ + nullptr, /*tp_alloc */ PyType_GenericNew, /*tp_new */ - 0, /*tp_free */ - 0, /*tp_is_gc */ - 0, /*tp_bases */ - 0, /*tp_mro */ - 0, /*tp_cache */ - 0, /*tp_subclasses */ - 0, /*tp_weaklist */ - 0, /*tp_del */ + nullptr, /*tp_free */ + nullptr, /*tp_is_gc */ + nullptr, /*tp_bases */ + nullptr, /*tp_mro */ + nullptr, /*tp_cache */ + nullptr, /*tp_subclasses */ + nullptr, /*tp_weaklist */ + nullptr, /*tp_del */ }; diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp index cc5e2ad30..149553b24 100644 --- a/src/PythonQtStdDecorators.cpp +++ b/src/PythonQtStdDecorators.cpp @@ -113,8 +113,8 @@ bool PythonQtStdDecorators::disconnect(QObject* sender, const QByteArray& signal } if (sender) { result = PythonQt::self()->removeSignalHandler(sender, signalTmp, callable); - if (callable == NULL) { - result |= QObject::disconnect(sender, signalTmp, NULL, NULL); + if (callable == nullptr) { + result |= QObject::disconnect(sender, signalTmp, nullptr, nullptr); } if (!result) { if (sender->metaObject()->indexOfSignal(QMetaObject::normalizedSignature(signalTmp.constData()+1)) == -1) { @@ -196,7 +196,7 @@ void PythonQtStdDecorators::static_QTimer_singleShot(int msec, PyObject* callabl QObject* PythonQtStdDecorators::findChild(QObject* parent, PyObject* type, const QString& name) { - const QMetaObject* meta = NULL; + const QMetaObject* meta = nullptr; QByteArray typeName; if (PyObject_TypeCheck(type, &PythonQtClassWrapper_Type)) { @@ -208,7 +208,7 @@ QObject* PythonQtStdDecorators::findChild(QObject* parent, PyObject* type, const } if (typeName.isEmpty() && !meta) { - return NULL; + return nullptr; } return findChild(parent, typeName, meta, name); @@ -216,7 +216,7 @@ QObject* PythonQtStdDecorators::findChild(QObject* parent, PyObject* type, const QList PythonQtStdDecorators::findChildren(QObject* parent, PyObject* type, const QString& name) { - const QMetaObject* meta = NULL; + const QMetaObject* meta = nullptr; QByteArray typeName; if (PyObject_TypeCheck(type, &PythonQtClassWrapper_Type)) { @@ -242,7 +242,7 @@ QList PythonQtStdDecorators::findChildren(QObject* parent, PyObject* t QList PythonQtStdDecorators::findChildren(QObject* parent, PyObject* type, const QRegExp& regExp) { - const QMetaObject* meta = NULL; + const QMetaObject* meta = nullptr; QByteArray typeName; if (PyObject_TypeCheck(type, &PythonQtClassWrapper_Type)) { @@ -274,7 +274,7 @@ QObject* PythonQtStdDecorators::findChild(QObject* parent, const char* typeName, QObject* obj = children.at(i); if (!obj) - return NULL; + return nullptr; // Skip if the name doesn't match. if (!name.isNull() && obj->objectName() != name) @@ -288,11 +288,11 @@ QObject* PythonQtStdDecorators::findChild(QObject* parent, const char* typeName, for (i = 0; i < children.size(); ++i) { QObject* obj = findChild(children.at(i), typeName, meta, name); - if (obj != NULL) + if (obj != nullptr) return obj; } - return NULL; + return nullptr; } int PythonQtStdDecorators::findChildren(QObject* parent, const char* typeName, const QMetaObject* meta, const QString& name, QList& list) diff --git a/src/PythonQtStdDecorators.h b/src/PythonQtStdDecorators.h index ca4d0f173..ca0021636 100644 --- a/src/PythonQtStdDecorators.h +++ b/src/PythonQtStdDecorators.h @@ -69,9 +69,9 @@ public Q_SLOTS: bool connect(QObject* receiver, QObject* sender, const QByteArray& signal, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); } bool static_QObject_connect(QObject* sender, const QByteArray& signal, PyObject* callable) { return connect(sender, signal, callable); } bool static_QObject_connect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot, Qt::ConnectionType type = Qt::AutoConnection) { return connect(sender, signal, receiver, slot, type); } - bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = NULL); + bool disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = nullptr); bool disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot); - bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = NULL) { return disconnect(sender, signal, callable); } + bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, PyObject* callable = nullptr) { return disconnect(sender, signal, callable); } bool static_QObject_disconnect(QObject* sender, const QByteArray& signal, QObject* receiver, const QByteArray& slot) { return disconnect(sender, signal, receiver, slot); } const QMetaObject* metaObject( QObject* obj ); diff --git a/src/PythonQtStdIn.cpp b/src/PythonQtStdIn.cpp index ff1af56c1..b36b3ec76 100644 --- a/src/PythonQtStdIn.cpp +++ b/src/PythonQtStdIn.cpp @@ -46,8 +46,8 @@ static PyObject *PythonQtStdInRedirect_new(PyTypeObject *type, PyObject * /*args { PythonQtStdInRedirect *self; self = (PythonQtStdInRedirect *)type->tp_alloc(type, 0); - self->_cb = NULL; - self->_callData = NULL; + self->_cb = nullptr; + self->_callData = nullptr; self->_isatty = false; return (PyObject *)self; @@ -77,50 +77,50 @@ static PyMethodDef PythonQtStdInRedirect_methods[] = { {"isatty", (PyCFunction)PythonQtStdInRedirect_isatty, METH_NOARGS, "returns True if this is a tty-like device. False by default." }, - {NULL, NULL, 0 , NULL} /* sentinel */ + {nullptr, nullptr, 0 , nullptr} /* sentinel */ }; static PyMemberDef PythonQtStdInRedirect_members[] = { - {NULL} /* Sentinel */ + {nullptr} /* Sentinel */ }; PyTypeObject PythonQtStdInRedirectType = { - PyVarObject_HEAD_INIT(NULL, 0) - "PythonQtStdInRedirect", /*tp_name*/ - sizeof(PythonQtStdInRedirect), /*tp_basicsize*/ + PyVarObject_HEAD_INIT(nullptr, 0) + "PythonQtStdInRedirect", /*tp_name*/ + sizeof(PythonQtStdInRedirect), /*tp_basicsize*/ 0, /*tp_itemsize*/ - 0, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ + nullptr, /*tp_dealloc*/ + 0, /*tp_vectorcall_offset*/ + nullptr, /*tp_getattr*/ + nullptr, /*tp_setattr*/ + nullptr, /*tp_compare*/ + nullptr, /*tp_repr*/ + nullptr, /*tp_as_number*/ + nullptr, /*tp_as_sequence*/ + nullptr, /*tp_as_mapping*/ + nullptr, /*tp_hash */ + nullptr, /*tp_call*/ + nullptr, /*tp_str*/ + nullptr, /*tp_getattro*/ + nullptr, /*tp_setattro*/ + nullptr, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "PythonQtStdInRedirect", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PythonQtStdInRedirect_methods, /* tp_methods */ - PythonQtStdInRedirect_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ + "PythonQtStdInRedirect", /* tp_doc */ + nullptr, /* tp_traverse */ + nullptr, /* tp_clear */ + nullptr, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ + PythonQtStdInRedirect_methods, /* tp_methods */ + PythonQtStdInRedirect_members, /* tp_members */ + nullptr, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + nullptr, /* tp_descr_get */ + nullptr, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PythonQtStdInRedirect_new, /* tp_new */ + nullptr, /* tp_init */ + nullptr, /* tp_alloc */ + PythonQtStdInRedirect_new, /* tp_new */ }; diff --git a/src/PythonQtStdOut.cpp b/src/PythonQtStdOut.cpp index 5c69fcd62..4069bd8ea 100644 --- a/src/PythonQtStdOut.cpp +++ b/src/PythonQtStdOut.cpp @@ -48,7 +48,7 @@ static PyObject *PythonQtStdOutRedirect_new(PyTypeObject *type, PyObject * /*arg self->softspace = 0; self->closed = false; - self->_cb = NULL; + self->_cb = nullptr; return (PyObject *)self; } @@ -75,7 +75,7 @@ static PyObject *PythonQtStdOutRedirect_write(PyObject *self, PyObject *args) } else { char *string; if (!PyArg_ParseTuple(args, "s", &string)) { - return NULL; + return nullptr; } #ifdef PY3K output = QString::fromUtf8(string); @@ -115,7 +115,7 @@ static PyMethodDef PythonQtStdOutRedirect_methods[] = { {"isatty", (PyCFunction)PythonQtStdOutRedirect_isatty, METH_NOARGS, "return False since this object is not a tty-like device. Needed for logging framework" }, - {NULL, NULL, 0 , NULL} /* sentinel */ + {nullptr, nullptr, 0 , nullptr} /* sentinel */ }; static PyMemberDef PythonQtStdOutRedirect_members[] = { @@ -125,46 +125,46 @@ static PyMemberDef PythonQtStdOutRedirect_members[] = { { const_cast("closed"), T_BOOL, offsetof(PythonQtStdOutRedirect, closed), 0, const_cast("soft space flag") }, - {NULL} /* Sentinel */ + {nullptr} /* Sentinel */ }; PyTypeObject PythonQtStdOutRedirectType = { - PyVarObject_HEAD_INIT(NULL, 0) + PyVarObject_HEAD_INIT(nullptr, 0) "PythonQtStdOutRedirect", /*tp_name*/ - sizeof(PythonQtStdOutRedirect), /*tp_basicsize*/ + sizeof(PythonQtStdOutRedirect), /*tp_basicsize*/ 0, /*tp_itemsize*/ - 0, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ + nullptr, /*tp_dealloc*/ + 0, /*tp_vectorcall_offset*/ + nullptr, /*tp_getattr*/ + nullptr, /*tp_setattr*/ + nullptr, /*tp_compare*/ + nullptr, /*tp_repr*/ + nullptr, /*tp_as_number*/ + nullptr, /*tp_as_sequence*/ + nullptr, /*tp_as_mapping*/ + nullptr, /*tp_hash */ + nullptr, /*tp_call*/ + nullptr, /*tp_str*/ + nullptr, /*tp_getattro*/ + nullptr, /*tp_setattro*/ + nullptr, /*tp_as_buffer*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ - "PythonQtStdOutRedirect", /* tp_doc */ - 0, /* tp_traverse */ - 0, /* tp_clear */ - 0, /* tp_richcompare */ - 0, /* tp_weaklistoffset */ - 0, /* tp_iter */ - 0, /* tp_iternext */ - PythonQtStdOutRedirect_methods, /* tp_methods */ - PythonQtStdOutRedirect_members, /* tp_members */ - 0, /* tp_getset */ - 0, /* tp_base */ - 0, /* tp_dict */ - 0, /* tp_descr_get */ - 0, /* tp_descr_set */ + "PythonQtStdOutRedirect", /* tp_doc */ + nullptr, /* tp_traverse */ + nullptr, /* tp_clear */ + nullptr, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + nullptr, /* tp_iter */ + nullptr, /* tp_iternext */ + PythonQtStdOutRedirect_methods, /* tp_methods */ + PythonQtStdOutRedirect_members, /* tp_members */ + nullptr, /* tp_getset */ + nullptr, /* tp_base */ + nullptr, /* tp_dict */ + nullptr, /* tp_descr_get */ + nullptr, /* tp_descr_set */ 0, /* tp_dictoffset */ - 0, /* tp_init */ - 0, /* tp_alloc */ - PythonQtStdOutRedirect_new, /* tp_new */ + nullptr, /* tp_init */ + nullptr, /* tp_alloc */ + PythonQtStdOutRedirect_new, /* tp_new */ }; diff --git a/src/PythonQtThreadSupport.h b/src/PythonQtThreadSupport.h index 407c16bf1..b1666ce05 100644 --- a/src/PythonQtThreadSupport.h +++ b/src/PythonQtThreadSupport.h @@ -119,7 +119,7 @@ class PythonQtThreadStateSaver void restore() { if (_state) { PyEval_RestoreThread(_state); - _state = NULL; + _state = nullptr; } } diff --git a/src/gui/PythonQtScriptingConsole.cpp b/src/gui/PythonQtScriptingConsole.cpp index d1e766663..2eaf73e20 100644 --- a/src/gui/PythonQtScriptingConsole.cpp +++ b/src/gui/PythonQtScriptingConsole.cpp @@ -174,7 +174,7 @@ void PythonQtScriptingConsole::executeCode(const QString& code) _stdOut = ""; _stdErr = ""; PythonQtObjectPtr p; - PyObject* dict = NULL; + PyObject* dict = nullptr; if (PyModule_Check(_context)) { dict = PyModule_GetDict(_context); } else if (PyDict_Check(_context)) { From d34f933c0e744f29b06c5a71887baf4553ff6057 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sun, 1 Jan 2023 19:53:57 +0100 Subject: [PATCH 2/8] Add override and noexcept modifiers - uses global includes where needed --- .idea/.gitignore | 8 ++++++++ src/PythonQt.h | 4 ++-- src/PythonQtImporter.h | 8 ++++---- src/PythonQtObjectPtr.cpp | 2 +- src/PythonQtObjectPtr.h | 8 ++++---- src/PythonQtQFileImporter.h | 18 +++++++++--------- src/PythonQtSignalReceiver.h | 4 ++-- src/gui/PythonQtScriptingConsole.h | 4 ++-- 8 files changed, 32 insertions(+), 24 deletions(-) create mode 100644 .idea/.gitignore diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..13566b81b --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/src/PythonQt.h b/src/PythonQt.h index 0e54a66b1..e8577f354 100644 --- a/src/PythonQt.h +++ b/src/PythonQt.h @@ -642,7 +642,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { PythonQtSignalReceiver* getSignalReceiver(QObject* obj); PythonQt(int flags, const QByteArray& pythonQtModuleName); - ~PythonQt(); + ~PythonQt() override; static PythonQt* _self; static int _uniqueModuleCount; @@ -659,7 +659,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { public: PythonQtPrivate(); - ~PythonQtPrivate(); + ~PythonQtPrivate() override; enum DecoratorTypes { StaticDecorator = 1, diff --git a/src/PythonQtImporter.h b/src/PythonQtImporter.h index 3999102b0..d9595c4cd 100644 --- a/src/PythonQtImporter.h +++ b/src/PythonQtImporter.h @@ -44,11 +44,11 @@ #include "PythonQtPythonInclude.h" -#include "structmember.h" -#include "osdefs.h" -#include "marshal.h" #include "compile.h" -#include +#include "marshal.h" +#include "osdefs.h" +#include "structmember.h" +#include #include #include diff --git a/src/PythonQtObjectPtr.cpp b/src/PythonQtObjectPtr.cpp index b0486004c..6448a18eb 100644 --- a/src/PythonQtObjectPtr.cpp +++ b/src/PythonQtObjectPtr.cpp @@ -39,8 +39,8 @@ */ //---------------------------------------------------------------------------------- +#include -#include "PythonQt.h" QVariant PythonQtObjectPtr::evalScript(const QString& script, int start) { return PythonQt::self()->evalScript(_object, script, start); diff --git a/src/PythonQtObjectPtr.h b/src/PythonQtObjectPtr.h index a1591fee5..84e6ed70c 100644 --- a/src/PythonQtObjectPtr.h +++ b/src/PythonQtObjectPtr.h @@ -64,7 +64,7 @@ class PYTHONQT_EXPORT PythonQtObjectPtr } //! rvalue copy constructor, does not need any incref/decref. - PythonQtObjectPtr(PythonQtObjectPtr &&p) + PythonQtObjectPtr(PythonQtObjectPtr &&p) noexcept :_object(p.takeObject()) { } @@ -95,7 +95,7 @@ class PYTHONQT_EXPORT PythonQtObjectPtr } //! rvalue assignment operator that steals the reference from p - PythonQtObjectPtr &operator=(PythonQtObjectPtr &&p) { + PythonQtObjectPtr &operator=(PythonQtObjectPtr &&p) noexcept { if (_object) { setObject(nullptr); } @@ -210,7 +210,7 @@ class PYTHONQT_EXPORT PythonQtSafeObjectPtr } //! rvalue copy constructor, does not need any incref/decref. - PythonQtSafeObjectPtr(PythonQtSafeObjectPtr &&p) + PythonQtSafeObjectPtr(PythonQtSafeObjectPtr &&p) noexcept :_object(p._object) { p._object = nullptr; } @@ -235,7 +235,7 @@ class PYTHONQT_EXPORT PythonQtSafeObjectPtr } //! rvalue assignment operator that steals the reference from p - PythonQtSafeObjectPtr &operator=(PythonQtSafeObjectPtr &&p) { + PythonQtSafeObjectPtr &operator=(PythonQtSafeObjectPtr &&p) noexcept { if (_object) { setObject(nullptr); } diff --git a/src/PythonQtQFileImporter.h b/src/PythonQtQFileImporter.h index 7eb78c9f9..2510b12b1 100644 --- a/src/PythonQtQFileImporter.h +++ b/src/PythonQtQFileImporter.h @@ -49,16 +49,16 @@ class PythonQtQFileImporter : public PythonQtImportFileInterface { public: PythonQtQFileImporter(); - ~PythonQtQFileImporter(); + ~PythonQtQFileImporter() override; - QByteArray readFileAsBytes (const QString &filename); - - QByteArray readSourceFile (const QString &filename, bool &ok); - - bool exists (const QString &filename); - bool isEggArchive(const QString& filename); - - QDateTime lastModifiedDate (const QString &filename); + QByteArray readFileAsBytes (const QString &filename) override; + + QByteArray readSourceFile (const QString &filename, bool &ok) override; + + bool exists (const QString &filename) override; + bool isEggArchive(const QString& filename) override; + + QDateTime lastModifiedDate (const QString &filename) override; }; diff --git a/src/PythonQtSignalReceiver.h b/src/PythonQtSignalReceiver.h index 7e8e5b134..49f7031ff 100644 --- a/src/PythonQtSignalReceiver.h +++ b/src/PythonQtSignalReceiver.h @@ -113,7 +113,7 @@ class PythonQtSignalReceiver : public PythonQtSignalReceiverBase { public: PythonQtSignalReceiver(QObject* obj); - ~PythonQtSignalReceiver(); + ~PythonQtSignalReceiver() override; //! add a signal handler bool addSignalHandler(const char* signal, PyObject* callable); @@ -122,7 +122,7 @@ class PythonQtSignalReceiver : public PythonQtSignalReceiverBase { bool removeSignalHandler(const char* signal, PyObject* callable = nullptr); //! we implement this method to simulate a number of slots that match the ids in _targets - virtual int qt_metacall(QMetaObject::Call c, int id, void **arguments); + int qt_metacall(QMetaObject::Call c, int id, void **arguments) override; private: //! get the index of the signal diff --git a/src/gui/PythonQtScriptingConsole.h b/src/gui/PythonQtScriptingConsole.h index f0e58c060..c47a0f023 100644 --- a/src/gui/PythonQtScriptingConsole.h +++ b/src/gui/PythonQtScriptingConsole.h @@ -57,14 +57,14 @@ class PYTHONQT_EXPORT PythonQtScriptingConsole : public QTextEdit public: PythonQtScriptingConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags i = 0); - ~PythonQtScriptingConsole(); + ~PythonQtScriptingConsole() override; public Q_SLOTS: //! execute current line void executeLine(bool storeOnly); //! derived key press event - void keyPressEvent (QKeyEvent * e); + void keyPressEvent (QKeyEvent * e) override; //! output from console void consoleMessage(const QString & message); From 1f2e329c8f5b7b3cd0d651a708734e2d7633a8b3 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sun, 1 Jan 2023 19:57:12 +0100 Subject: [PATCH 3/8] Fix type conversion warnings, use const - remove unused variable --- src/PythonQt.cpp | 4 ++-- src/PythonQtClassWrapper.cpp | 8 ++++---- src/PythonQtConversion.cpp | 28 ++++++++++++++-------------- src/PythonQtInstanceWrapper.cpp | 8 ++++---- src/PythonQtMethodInfo.cpp | 2 +- src/PythonQtSignal.cpp | 18 +++++++++--------- src/PythonQtSignalReceiver.cpp | 2 +- src/PythonQtSlot.cpp | 10 +++++----- src/gui/PythonQtScriptingConsole.cpp | 1 - 9 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index cd1001ff4..aed06f967 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -266,7 +266,7 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName) "QtSystemMsg" }; - for (int i = 0; i_dynamicInfo) { signal->_dynamicInfo->name = PyString_AsString(key); foreach(QByteArray sig, signal->_dynamicInfo->signatures) { - QMetaMethodBuilder method = builder.addSignal(signal->_dynamicInfo->name + "(" + sig + ")"); + builder.addSignal(signal->_dynamicInfo->name + "(" + sig + ")"); needsMetaObject = true; } } diff --git a/src/PythonQtClassWrapper.cpp b/src/PythonQtClassWrapper.cpp index 7edd2bc6d..7887538c0 100644 --- a/src/PythonQtClassWrapper.cpp +++ b/src/PythonQtClassWrapper.cpp @@ -419,16 +419,16 @@ PyObject *PythonQtClassWrapper_inherits(PythonQtClassWrapper *type, PyObject *ar static PyMethodDef PythonQtClassWrapper_methods[] = { - {"className", (PyCFunction)PythonQtClassWrapper_classname, METH_NOARGS, + {"className", reinterpret_cast(reinterpret_cast(PythonQtClassWrapper_classname)), METH_NOARGS, "Return the classname of the object" }, - {"inherits", (PyCFunction)PythonQtClassWrapper_inherits, METH_VARARGS, + {"inherits", reinterpret_cast(reinterpret_cast(PythonQtClassWrapper_inherits)), METH_VARARGS, "Returns if the class inherits or is of given type name" }, - {"help", (PyCFunction)PythonQtClassWrapper_help, METH_NOARGS, + {"help", reinterpret_cast(reinterpret_cast(PythonQtClassWrapper_help)), METH_NOARGS, "Shows the help of available methods for this class" }, - {"delete", (PyCFunction)PythonQtClassWrapper_delete, METH_VARARGS, + {"delete", reinterpret_cast(reinterpret_cast(PythonQtClassWrapper_delete)), METH_VARARGS, "Deletes the given C++ object" }, {nullptr, nullptr, 0 , nullptr} /* Sentinel */ diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp index e31fe090d..70380b8d9 100644 --- a/src/PythonQtConversion.cpp +++ b/src/PythonQtConversion.cpp @@ -503,7 +503,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i break; case QMetaType::Long: { - qint64 val = PyObjGetLongLong(obj, strict, ok); + auto val = PyObjGetLongLong(obj, strict, ok); if (ok && (val >= LONG_MIN && val <= LONG_MAX)) { PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, long, val, ptr); } @@ -511,8 +511,8 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i break; case QMetaType::ULong: { - qint64 val = (unsigned long)PyObjGetLongLong(obj, strict, ok); - if (ok && (val >= 0 && val <= ULONG_MAX)) { + auto val = PyObjGetULongLong(obj, strict, ok); + if (ok && val <= ULONG_MAX) { PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, unsigned long, val, ptr); } } @@ -535,7 +535,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i break; case QMetaType::UInt: { - quint64 val = PyObjGetLongLong(obj, strict, ok); + auto val = PyObjGetLongLong(obj, strict, ok); if (ok && (val >= 0 && val <= UINT_MAX)) { PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, unsigned int, val, ptr); } @@ -1066,26 +1066,26 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) { double d = PyObjGetDouble(val,false,ok); if (ok) v = QVariant(d); - break; } + break; case QMetaType::Float: { float d = (float) PyObjGetDouble(val,false,ok); if (ok) v = qVariantFromValue(d); - break; } + break; case QMetaType::Long: { long d = (long) PyObjGetLongLong(val,false,ok); if (ok) v = qVariantFromValue(d); - break; } + break; case QMetaType::ULong: { unsigned long d = (unsigned long) PyObjGetLongLong(val,false,ok); if (ok) v = qVariantFromValue(d); - break; } + break; case QMetaType::LongLong: { qint64 d = PyObjGetLongLong(val, false, ok); @@ -1102,26 +1102,26 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) { short d = (short) PyObjGetInt(val,false,ok); if (ok) v = qVariantFromValue(d); - break; } + break; case QMetaType::UShort: { unsigned short d = (unsigned short) PyObjGetInt(val,false,ok); if (ok) v = qVariantFromValue(d); - break; } + break; case QMetaType::Char: { char d = (char) PyObjGetInt(val,false,ok); if (ok) v = qVariantFromValue(d); - break; } + break; case QMetaType::UChar: { unsigned char d = (unsigned char) PyObjGetInt(val,false,ok); if (ok) v = qVariantFromValue(d); - break; } + break; case QVariant::ByteArray: { @@ -1131,8 +1131,8 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) #else v = QVariant(PyObjGetString(val, false, ok)); #endif - break; } + break; case QVariant::String: { bool ok; @@ -1207,7 +1207,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) } } } - } else if (type >= QVariant::UserType) { + } else if (static_cast(type) >= QVariant::UserType) { // not an instance wrapper, but there might be other converters // Maybe we have a special converter that is registered for that type: PythonQtConvertPythonToMetaTypeCB* converter = _pythonToMetaTypeConverters.value(type); diff --git a/src/PythonQtInstanceWrapper.cpp b/src/PythonQtInstanceWrapper.cpp index 08ba737a3..60dd65f7d 100644 --- a/src/PythonQtInstanceWrapper.cpp +++ b/src/PythonQtInstanceWrapper.cpp @@ -357,16 +357,16 @@ PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self) static PyMethodDef PythonQtInstanceWrapper_methods[] = { - {"className", (PyCFunction)PythonQtInstanceWrapper_classname, METH_NOARGS, + {"className", reinterpret_cast(reinterpret_cast(PythonQtInstanceWrapper_classname)), METH_NOARGS, "Return the classname of the object" }, - {"inherits", (PyCFunction)PythonQtInstanceWrapper_inherits, METH_VARARGS, + {"inherits", reinterpret_cast(reinterpret_cast(PythonQtInstanceWrapper_inherits)), METH_VARARGS, "Returns if the class inherits or is of given type name" }, - {"help", (PyCFunction)PythonQtInstanceWrapper_help, METH_NOARGS, + {"help", reinterpret_cast(reinterpret_cast(PythonQtInstanceWrapper_help)), METH_NOARGS, "Shows the help of available methods for this class" }, - {"delete", (PyCFunction)PythonQtInstanceWrapper_delete, METH_NOARGS, + {"delete", reinterpret_cast(reinterpret_cast(PythonQtInstanceWrapper_delete)), METH_NOARGS, "Deletes the C++ object (at your own risk, my friend!)" }, {nullptr, nullptr, 0, nullptr} /* Sentinel */ diff --git a/src/PythonQtMethodInfo.cpp b/src/PythonQtMethodInfo.cpp index e1d91ec75..3c8ee7ff1 100644 --- a/src/PythonQtMethodInfo.cpp +++ b/src/PythonQtMethodInfo.cpp @@ -85,7 +85,7 @@ PythonQtMethodInfo::PythonQtMethodInfo(const QByteArray& typeName, const QList(reinterpret_cast(PythonQtSignalFunction_parameterTypes)), METH_NOARGS, "Returns a tuple of tuples of the C++ parameter types for all overloads of the signal" }, - {"parameterNames", (PyCFunction)PythonQtSignalFunction_parameterNames, METH_NOARGS, + {"parameterNames", reinterpret_cast(reinterpret_cast(PythonQtSignalFunction_parameterNames)), METH_NOARGS, "Returns a tuple of tuples of the C++ parameter type names (if available), for all overloads of the signal" }, - {"typeName", (PyCFunction)PythonQtSignalFunction_typeName, METH_NOARGS, + {"typeName", reinterpret_cast(reinterpret_cast(PythonQtSignalFunction_typeName)), METH_NOARGS, "Returns a tuple of the C++ return value types of each signal overload" }, - {"connect", (PyCFunction)PythonQtSignalFunction_connect, METH_VARARGS, + {"connect", reinterpret_cast(reinterpret_cast(PythonQtSignalFunction_connect)), METH_VARARGS, "Connects the signal to the Python callable" }, - {"disconnect", (PyCFunction)PythonQtSignalFunction_disconnect, METH_VARARGS, + {"disconnect", reinterpret_cast(reinterpret_cast(PythonQtSignalFunction_disconnect)), METH_VARARGS, "Disconnects the signal from the given Python callable or disconnects all if no argument is passed." }, - {"emit", (PyCFunction)PythonQtSignalFunction_emit, METH_VARARGS, + {"emit", reinterpret_cast(reinterpret_cast(PythonQtSignalFunction_emit)), METH_VARARGS, "Emits the signal with given arguments" }, {nullptr, nullptr, 0 , nullptr} /* Sentinel */ @@ -326,11 +326,11 @@ meth_repr(PythonQtSignalFunctionObject *f) if (f->m_self->ob_type == &PythonQtClassWrapper_Type) { PythonQtClassWrapper* self = (PythonQtClassWrapper*) f->m_self; return PyString_FromFormat("", - f->m_ml->slotName().data(), + f->m_ml->slotName().constData(), self->classInfo()->className().constData()); } else { return PyString_FromFormat("", - f->m_ml->slotName().data(), + f->m_ml->slotName().constData(), f->m_self->ob_type->tp_name, f->m_self); } @@ -374,7 +374,7 @@ static PyObject* meth_richcompare(PythonQtSignalFunctionObject *a, PythonQtSignalFunctionObject *b, int op) { int x = meth_compare(a, b); - bool r; + bool r = false; if (op == Py_LT) r = x < 0; else if (op == Py_LE) diff --git a/src/PythonQtSignalReceiver.cpp b/src/PythonQtSignalReceiver.cpp index da9e80bc2..3a5eda628 100644 --- a/src/PythonQtSignalReceiver.cpp +++ b/src/PythonQtSignalReceiver.cpp @@ -266,7 +266,7 @@ int PythonQtSignalReceiver::qt_metacall(QMetaObject::Call c, int id, void **argu } bool shouldDelete = false; - for(const PythonQtSignalTarget& t : _targets) { + for(const PythonQtSignalTarget& t : qAsConst(_targets)) { if (t.slotId() == id) { const int sigId = t.signalId(); t.call(arguments); diff --git a/src/PythonQtSlot.cpp b/src/PythonQtSlot.cpp index c72311a67..f2ccae4f0 100644 --- a/src/PythonQtSlot.cpp +++ b/src/PythonQtSlot.cpp @@ -704,13 +704,13 @@ PyObject *PythonQtMemberFunction_typeName(PythonQtSlotInfo* theInfo) } static PyMethodDef meth_methods[] = { - {"parameterTypes", (PyCFunction)PythonQtSlotFunction_parameterTypes, METH_NOARGS, + {"parameterTypes", reinterpret_cast(reinterpret_cast(PythonQtSlotFunction_parameterTypes)), METH_NOARGS, "Returns a tuple of tuples of the C++ parameter types for all overloads of the slot" }, - {"parameterNames", (PyCFunction)PythonQtSlotFunction_parameterNames, METH_NOARGS, + {"parameterNames", reinterpret_cast(reinterpret_cast(PythonQtSlotFunction_parameterNames)), METH_NOARGS, "Returns a tuple of tuples of the C++ parameter type names (if available), for all overloads of the slot" }, - {"typeName", (PyCFunction)PythonQtSlotFunction_typeName, METH_NOARGS, + {"typeName", reinterpret_cast(reinterpret_cast(PythonQtSlotFunction_typeName)), METH_NOARGS, "Returns a tuple of the C++ return value types of each slot overload" }, {nullptr, nullptr, 0 , nullptr} /* Sentinel */ @@ -722,11 +722,11 @@ meth_repr(PythonQtSlotFunctionObject *f) if (f->m_self->ob_type == &PythonQtClassWrapper_Type) { PythonQtClassWrapper* self = (PythonQtClassWrapper*) f->m_self; return PyString_FromFormat("", - f->m_ml->slotName().data(), + f->m_ml->slotName().constData(), self->classInfo()->className().constData()); } else { return PyString_FromFormat("", - f->m_ml->slotName().data(), + f->m_ml->slotName().constData(), f->m_self->ob_type->tp_name, f->m_self); } diff --git a/src/gui/PythonQtScriptingConsole.cpp b/src/gui/PythonQtScriptingConsole.cpp index 2eaf73e20..baa6f7ed4 100644 --- a/src/gui/PythonQtScriptingConsole.cpp +++ b/src/gui/PythonQtScriptingConsole.cpp @@ -464,7 +464,6 @@ void PythonQtScriptingConsole::keyPressEvent(QKeyEvent* event) { } else { _completer->popup()->hide(); } - eventHandled = true; } } From 664c6c5930817f4ec32bcdd8d3ac77200c11cbfe Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Sun, 1 Jan 2023 19:59:39 +0100 Subject: [PATCH 4/8] Avoid redefinition warnings, fix export macros - add missing check --- src/PythonQtPythonInclude.h | 5 ----- src/PythonQtSystem.h | 20 +++++++++++++------- src/gui/PythonQtScriptingConsole.cpp | 5 +++-- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h index 00f0b0788..2a4922895 100644 --- a/src/PythonQtPythonInclude.h +++ b/src/PythonQtPythonInclude.h @@ -33,11 +33,6 @@ #ifndef __PythonQtPythonInclude_h #define __PythonQtPythonInclude_h -// Undefine macros that Python.h defines to avoid redefinition warning. -#undef _POSIX_C_SOURCE -#undef _POSIX_THREADS -#undef _XOPEN_SOURCE - // Undefine Qt keywords that conflict with Python headers #ifdef slots #undef slots diff --git a/src/PythonQtSystem.h b/src/PythonQtSystem.h index d7131bb79..d49345eeb 100644 --- a/src/PythonQtSystem.h +++ b/src/PythonQtSystem.h @@ -42,15 +42,21 @@ */ //---------------------------------------------------------------------------------- -#ifdef WIN32 -#ifdef PYTHONQT_EXPORTS -#define PYTHONQT_EXPORT __declspec(dllexport) -#else -#define PYTHONQT_EXPORT __declspec(dllimport) -#endif + +#if defined(WIN32) + #ifdef PYTHONQT_EXPORTS + #define PYTHONQT_EXPORT __declspec(dllexport) + #else + #define PYTHONQT_EXPORT __declspec(dllimport) + #endif #else -#define PYTHONQT_EXPORT + #ifdef PYTHONQT_EXPORTS + #define PYTHONQT_EXPORT __attribute__((__visibility__("default"))) + #else + #define PYTHONQT_EXPORT + #endif #endif + #endif diff --git a/src/gui/PythonQtScriptingConsole.cpp b/src/gui/PythonQtScriptingConsole.cpp index baa6f7ed4..6e2218454 100644 --- a/src/gui/PythonQtScriptingConsole.cpp +++ b/src/gui/PythonQtScriptingConsole.cpp @@ -451,8 +451,9 @@ void PythonQtScriptingConsole::keyPressEvent(QKeyEvent* event) { } if (eventHandled) { - - _completer->popup()->hide(); + if(_completer != nullptr) { + _completer->popup()->hide(); + } event->accept(); } else { From 08911ec5de3f4d35e3d6e855ff5af26c02811494 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Mon, 2 Jan 2023 13:39:02 +0100 Subject: [PATCH 5/8] Add facility to set task done callback - on async signal handlers (originally provided by @usiems) --- src/PythonQt.cpp | 7 +++++++ src/PythonQt.h | 8 ++++++++ src/PythonQtStdDecorators.cpp | 11 +++++++++++ src/PythonQtStdDecorators.h | 14 ++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index aed06f967..a1a963704 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -274,6 +274,7 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName) } _self->priv()->pythonQtModule().addObject("Debug", _self->priv()->_debugAPI); + _self->priv()->pythonQtModule().addObject("Config", _self->priv()->_configAPI); Py_INCREF((PyObject*)&PythonQtSlotDecorator_Type); Py_INCREF((PyObject*)&PythonQtSignalFunction_Type); @@ -396,6 +397,11 @@ PythonQtPrivate::~PythonQtPrivate() { PythonQtArgumentFrame::cleanupFreeList(); } +void PythonQtPrivate::setTaskDoneCallback(const PythonQtObjectPtr & callable) +{ + _pyTaskDoneCallback = callable; +} + void PythonQt::setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * callbackData) { if (!callback) { @@ -1434,6 +1440,7 @@ PythonQtPrivate::PythonQtPrivate() _hadError = false; _systemExitExceptionHandlerEnabled = false; _debugAPI = new PythonQtDebugAPI(this); + _configAPI = new PythonQtConfigAPI(this); } void PythonQtPrivate::setupSharedLibrarySuffixes() diff --git a/src/PythonQt.h b/src/PythonQt.h index e8577f354..a3db5bf4e 100644 --- a/src/PythonQt.h +++ b/src/PythonQt.h @@ -651,6 +651,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { }; class PythonQtDebugAPI; +class PythonQtConfigAPI; //! internal PythonQt details class PYTHONQT_EXPORT PythonQtPrivate : public QObject { @@ -669,6 +670,10 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { AllDecorators = 0xffff }; + //! Set a callable that is used as the argument for the add_done_callback for the Task + //! created by checkAndRunCoroutine + void setTaskDoneCallback(const PythonQtObjectPtr& callable); + //! get the suffixes that are used for shared libraries const QStringList& sharedLibrarySuffixes() { return _sharedLibrarySuffixes; } @@ -849,6 +854,8 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { PythonQtObjectPtr _pySourceFileLoader; PythonQtObjectPtr _pySourcelessFileLoader; + PythonQtObjectPtr _pyTaskDoneCallback; + //! the cpp object wrapper factories QList _cppWrapperFactories; @@ -861,6 +868,7 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { PythonQt::ProfilingCB* _profilingCB; PythonQtDebugAPI* _debugAPI; + PythonQtConfigAPI* _configAPI; int _initFlags; int _PythonQtObjectPtr_metaId; diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp index 149553b24..9635199bb 100644 --- a/src/PythonQtStdDecorators.cpp +++ b/src/PythonQtStdDecorators.cpp @@ -354,6 +354,17 @@ const QMetaObject* PythonQtStdDecorators::metaObject( QObject* obj ) return obj->metaObject(); } +//--------------------------------------------------------------------------- + +void PythonQtConfigAPI::setTaskDoneCallback(PyObject* object) +{ + if (PythonQt::self()) { + PythonQt::self()->priv()->setTaskDoneCallback(object); + } +} + +//--------------------------------------------------------------------------- + bool PythonQtDebugAPI::isOwnedByPython( PyObject* object ) { if (PyObject_TypeCheck(object, &PythonQtInstanceWrapper_Type)) { diff --git a/src/PythonQtStdDecorators.h b/src/PythonQtStdDecorators.h index ca0021636..5ee1b9cb7 100644 --- a/src/PythonQtStdDecorators.h +++ b/src/PythonQtStdDecorators.h @@ -173,6 +173,20 @@ public Q_SLOTS: }; +//! Some methods to set properties of PythonQt from Python +class PYTHONQT_EXPORT PythonQtConfigAPI : public QObject +{ + Q_OBJECT +public: + PythonQtConfigAPI(QObject* parent):QObject(parent) {}; + +public slots: + //! Set a callable that is used as the argument for the add_done_callback for the Task/Future + //! created when, e.g., an async function is connected to signal. + void setTaskDoneCallback(PyObject* object); +}; + + //! Some helper methods that allow testing of the ownership class PYTHONQT_EXPORT PythonQtDebugAPI : public QObject { From d4d41dfa37f6f0ceb4a4507a5f259aade955e671 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Mon, 2 Jan 2023 13:46:12 +0100 Subject: [PATCH 6/8] Make sure queued connection of Signals with Python types are safe - patch as proposed by Florian Link --- src/PythonQtConversion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PythonQtConversion.cpp b/src/PythonQtConversion.cpp index 70380b8d9..a2e94dba8 100644 --- a/src/PythonQtConversion.cpp +++ b/src/PythonQtConversion.cpp @@ -1515,7 +1515,7 @@ QByteArray PythonQtConv::getCPPTypeName(PyObject* type) } else if (isStringType(typeObject)) { result = "QString"; } else { - result = "PyObject*"; + result = "PythonQtSafeObjectPtr"; } } } else if (type == Py_None) { From 1c2efcefb4773891f744d0cacfa2e97e99c4511a Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Mon, 2 Jan 2023 13:49:46 +0100 Subject: [PATCH 7/8] Add missing GIL scope to single shot timer destructor - provided by Florian Link --- src/PythonQtStdDecorators.cpp | 8 ++++++++ src/PythonQtStdDecorators.h | 1 + 2 files changed, 9 insertions(+) diff --git a/src/PythonQtStdDecorators.cpp b/src/PythonQtStdDecorators.cpp index 9635199bb..b3e281393 100644 --- a/src/PythonQtStdDecorators.cpp +++ b/src/PythonQtStdDecorators.cpp @@ -432,11 +432,19 @@ PythonQtSingleShotTimer::PythonQtSingleShotTimer(int msec, const PythonQtObjectP connect(this, SIGNAL(timeout()), this, SLOT(slotTimeout())); } +PythonQtSingleShotTimer::~PythonQtSingleShotTimer() +{ + PYTHONQT_GIL_SCOPE + _callable = nullptr; +} + void PythonQtSingleShotTimer::slotTimeout() { if (_callable) { + PYTHONQT_GIL_SCOPE _callable.call(); } // delete ourself deleteLater(); } + diff --git a/src/PythonQtStdDecorators.h b/src/PythonQtStdDecorators.h index 5ee1b9cb7..b5c0ba607 100644 --- a/src/PythonQtStdDecorators.h +++ b/src/PythonQtStdDecorators.h @@ -124,6 +124,7 @@ class PythonQtSingleShotTimer : public QTimer Q_OBJECT public: PythonQtSingleShotTimer(int msec, const PythonQtObjectPtr& callable); + ~PythonQtSingleShotTimer() override; public Q_SLOTS : void slotTimeout(); From ebf8bff3166422bc25f82108a9be7c806e6fb8e7 Mon Sep 17 00:00:00 2001 From: mrbean-bremen Date: Mon, 2 Jan 2023 17:02:39 +0100 Subject: [PATCH 8/8] Add initial support for coroutines - when a signal calls a Python function and it is a coroutine, it will be scheduled (patch by Florian Link) --- src/PythonQt.cpp | 50 ++++++++++++++++++++++++++++++++++ src/PythonQt.h | 8 ++++++ src/PythonQtSignalReceiver.cpp | 1 + 3 files changed, 59 insertions(+) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index a1a963704..ee182c0ed 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -88,6 +88,16 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName) _self->_p->_pySourcelessFileLoader = importlib.getVariable("SourcelessFileLoader"); } +#ifdef PY3K + PythonQtObjectPtr asyncio; + asyncio.setNewRef(PyImport_ImportModule("asyncio")); + if (asyncio) + { + _self->_p->_pyEnsureFuture = asyncio.getVariable("ensure_future"); + _self->_p->_pyFutureClass = asyncio.getVariable("Future"); + } +#endif + PythonQt::priv()->setupSharedLibrarySuffixes(); PythonQtMethodInfo::addParameterTypeAlias("QObjectList", "QList"); @@ -402,6 +412,46 @@ void PythonQtPrivate::setTaskDoneCallback(const PythonQtObjectPtr & callable) _pyTaskDoneCallback = callable; } +PythonQtObjectPtr PythonQtPrivate::checkAndRunCoroutine(const PythonQtObjectPtr& object) +{ + PythonQtObjectPtr result; +#ifdef PY3K + if (!PyCoro_CheckExact(object)) + { + return result; + } + + if (!_pyEnsureFuture) + { + std::cerr << "PythonQt: ensure_future not initialized" << std::endl; + return PythonQtObjectPtr(); + } + PyObject* args = PyTuple_New(1); + PyObject* coro = object.object(); + Py_INCREF(coro); + PyTuple_SetItem(args, 0, coro); + PyObject* r = PyObject_CallObject(_pyEnsureFuture, args); + result.setNewRef(r); + if (_pyTaskDoneCallback) { + PyObject* methodName = PyUnicode_FromString("add_done_callback"); + PyObject_CallMethodObjArgs(r, methodName, _pyTaskDoneCallback.object(), nullptr); + Py_XDECREF(methodName); + } + Py_XDECREF(args); +#endif + return result; +} + +PythonQtObjectPtr PythonQtPrivate::createAsyncioFuture() +{ + if (!_pyFutureClass) + { + std::cerr << "PythonQt: _pyFutureClass not initialized" << std::endl; + return nullptr; + } + return _pyFutureClass.call(); +} + void PythonQt::setRedirectStdInCallback(PythonQtInputChangedCB* callback, void * callbackData) { if (!callback) { diff --git a/src/PythonQt.h b/src/PythonQt.h index a3db5bf4e..263c0162d 100644 --- a/src/PythonQt.h +++ b/src/PythonQt.h @@ -674,6 +674,12 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { //! created by checkAndRunCoroutine void setTaskDoneCallback(const PythonQtObjectPtr& callable); + //! Runs the given coroutine (via asyncio), returns a scheduled task if it object is a coroutine. + PythonQtObjectPtr checkAndRunCoroutine(const PythonQtObjectPtr& object); + + //! Creates a new asyncio.Future object + PythonQtObjectPtr createAsyncioFuture(); + //! get the suffixes that are used for shared libraries const QStringList& sharedLibrarySuffixes() { return _sharedLibrarySuffixes; } @@ -853,6 +859,8 @@ class PYTHONQT_EXPORT PythonQtPrivate : public QObject { PythonQtObjectPtr _pySourceFileLoader; PythonQtObjectPtr _pySourcelessFileLoader; + PythonQtObjectPtr _pyEnsureFuture; + PythonQtObjectPtr _pyFutureClass; PythonQtObjectPtr _pyTaskDoneCallback; diff --git a/src/PythonQtSignalReceiver.cpp b/src/PythonQtSignalReceiver.cpp index 3a5eda628..916b068a2 100644 --- a/src/PythonQtSignalReceiver.cpp +++ b/src/PythonQtSignalReceiver.cpp @@ -55,6 +55,7 @@ void PythonQtSignalTarget::call(void **arguments) const { PYTHONQT_GIL_SCOPE PyObject* result = call(_callable, methodInfo(), arguments); if (result) { + PythonQt::priv()->checkAndRunCoroutine(result); Py_DECREF(result); } }