From 8d3c66cf187ade0f981e2e8e763b7a979cce2145 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 9 Mar 2022 21:55:31 +0100 Subject: [PATCH] Core/Mod: modernize C++11 * use nullptr --- src/App/ApplicationPy.cpp | 127 +++++++++--------- src/App/DocumentObjectPyImp.cpp | 32 ++--- src/App/DocumentPyImp.cpp | 97 ++++++------- src/App/ExtensionContainerPyImp.cpp | 2 +- src/App/GroupExtensionPyImp.cpp | 54 ++++---- src/App/MaterialPyImp.cpp | 4 +- src/App/PropertyContainerPyImp.cpp | 44 +++--- src/Base/BaseClassPyImp.cpp | 8 +- src/Base/Console.cpp | 4 +- src/Gui/View3DPy.cpp | 6 +- src/Gui/ViewProviderDocumentObjectPyImp.cpp | 6 +- src/Gui/ViewProviderPyImp.cpp | 75 ++++++----- src/Mod/Fem/App/FemMeshPyImp.cpp | 4 +- src/Mod/Part/App/AttachEnginePyImp.cpp | 4 +- src/Mod/Path/App/FeaturePathCompoundPyImp.cpp | 18 +-- src/Mod/Points/App/PointsPyImp.cpp | 4 +- 16 files changed, 248 insertions(+), 241 deletions(-) diff --git a/src/App/ApplicationPy.cpp b/src/App/ApplicationPy.cpp index 7f06663df3..36c4dad69a 100644 --- a/src/App/ApplicationPy.cpp +++ b/src/App/ApplicationPy.cpp @@ -188,13 +188,13 @@ PyMethodDef Application::Methods[] = { PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args) { char *path, *doc="",*mod=""; - if (!PyArg_ParseTuple(args, "s|ss", &path, &doc, &mod)) // convert args: Python->C - return 0; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s|ss", &path, &doc, &mod)) + return nullptr; try { Base::FileInfo fi(path); if (!fi.isFile() || !fi.exists()) { PyErr_Format(PyExc_IOError, "File %s doesn't exist.", path); - return 0; + return nullptr; } std::string module = mod; @@ -203,7 +203,7 @@ PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args) std::vector modules = GetApplication().getImportModules(ext.c_str()); if (modules.empty()) { PyErr_Format(PyExc_IOError, "Filetype %s is not supported.", ext.c_str()); - return 0; + return nullptr; } else { module = modules.front(); @@ -226,7 +226,7 @@ PyObject* Application::sLoadFile(PyObject * /*self*/, PyObject *args) catch (const std::exception& e) { // might be subclass from zipios PyErr_Format(PyExc_IOError, "Invalid project file %s: %s", path, e.what()); - return 0; + return nullptr; } } @@ -285,15 +285,15 @@ PyObject* Application::sNewDocument(PyObject * /*self*/, PyObject *args, PyObjec PyObject* Application::sSetActiveDocument(PyObject * /*self*/, PyObject *args) { char *pstr = 0; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; try { GetApplication().setActiveDocument(pstr); } catch (const Base::Exception& e) { PyErr_SetString(Base::BaseExceptionFreeCADError, e.what()); - return NULL; + return nullptr; } Py_Return; @@ -302,22 +302,22 @@ PyObject* Application::sSetActiveDocument(PyObject * /*self*/, PyObject *args) PyObject* Application::sCloseDocument(PyObject * /*self*/, PyObject *args) { char *pstr = 0; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; Document* doc = GetApplication().getDocument(pstr); if (!doc) { PyErr_Format(PyExc_NameError, "Unknown document '%s'", pstr); - return NULL; + return nullptr; } if (!doc->isClosable()) { PyErr_Format(PyExc_RuntimeError, "The document '%s' is not closable for the moment", pstr); - return NULL; + return nullptr; } if (GetApplication().closeDocument(pstr) == false) { PyErr_Format(PyExc_RuntimeError, "Closing the document '%s' failed", pstr); - return NULL; + return nullptr; } Py_Return; @@ -326,19 +326,19 @@ PyObject* Application::sCloseDocument(PyObject * /*self*/, PyObject *args) PyObject* Application::sSaveDocument(PyObject * /*self*/, PyObject *args) { char *pDoc; - if (!PyArg_ParseTuple(args, "s", &pDoc)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pDoc)) + return nullptr; Document* doc = GetApplication().getDocument(pDoc); if ( doc ) { if ( doc->save() == false ) { PyErr_Format(Base::BaseExceptionFreeCADError, "Cannot save document '%s'", pDoc); - return 0L; + return nullptr; } } else { PyErr_Format(PyExc_NameError, "Unknown document '%s'", pDoc); - return NULL; + return nullptr; } Py_Return; @@ -347,8 +347,8 @@ PyObject* Application::sSaveDocument(PyObject * /*self*/, PyObject *args) PyObject* Application::sSaveDocumentAs(PyObject * /*self*/, PyObject *args) { char *pDoc, *pFileName; - if (!PyArg_ParseTuple(args, "ss", &pDoc, &pFileName)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "ss", &pDoc, &pFileName)) + return nullptr; Document* doc = GetApplication().getDocument(pDoc); if (doc) { @@ -364,8 +364,8 @@ PyObject* Application::sSaveDocumentAs(PyObject * /*self*/, PyObject *args) #endif PyObject* Application::sActiveDocument(PyObject * /*self*/, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; Document* doc = GetApplication().getActiveDocument(); if (doc) { @@ -380,13 +380,13 @@ PyObject* Application::sActiveDocument(PyObject * /*self*/, PyObject *args) PyObject* Application::sGetDocument(PyObject * /*self*/, PyObject *args) { char *pstr=0; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; Document* doc = GetApplication().getDocument(pstr); if ( !doc ) { PyErr_Format(PyExc_NameError, "Unknown document '%s'", pstr); - return 0L; + return nullptr; } return doc->getPyObject(); @@ -395,8 +395,8 @@ PyObject* Application::sGetDocument(PyObject * /*self*/, PyObject *args) PyObject* Application::sGetParam(PyObject * /*self*/, PyObject *args) { char *pstr=0; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; PY_TRY { return GetPyObject(GetApplication().GetParameterGroupByPath(pstr)); @@ -407,7 +407,7 @@ PyObject* Application::sSaveParameter(PyObject * /*self*/, PyObject *args) { char *pstr = "User parameter"; if (!PyArg_ParseTuple(args, "|s", &pstr)) - return NULL; + return nullptr; PY_TRY { ParameterManager* param = App::GetApplication().GetParameterSet(pstr); @@ -415,13 +415,13 @@ PyObject* Application::sSaveParameter(PyObject * /*self*/, PyObject *args) std::stringstream str; str << "No parameter set found with name: " << pstr; PyErr_SetString(PyExc_ValueError, str.str().c_str()); - return NULL; + return nullptr; } else if (!param->HasSerializer()) { std::stringstream str; str << "Parameter set cannot be serialized: " << pstr; PyErr_SetString(PyExc_RuntimeError, str.str().c_str()); - return NULL; + return nullptr; } param->SaveDocument(); @@ -435,8 +435,8 @@ PyObject* Application::sGetConfig(PyObject * /*self*/, PyObject *args) { char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; const std::map& Map = GetApplication().Config(); std::map::const_iterator it = Map.find(pstr); @@ -451,8 +451,8 @@ PyObject* Application::sGetConfig(PyObject * /*self*/, PyObject *args) PyObject* Application::sDumpConfig(PyObject * /*self*/, PyObject *args) { - if (!PyArg_ParseTuple(args, "") ) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PyObject *dict = PyDict_New(); for (std::map::iterator It= GetApplication()._mConfig.begin(); @@ -466,8 +466,8 @@ PyObject* Application::sSetConfig(PyObject * /*self*/, PyObject *args) { char *pstr,*pstr2; - if (!PyArg_ParseTuple(args, "ss", &pstr,&pstr2)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "ss", &pstr,&pstr2)) + return nullptr; GetApplication()._mConfig[pstr] = pstr2; @@ -477,8 +477,8 @@ PyObject* Application::sSetConfig(PyObject * /*self*/, PyObject *args) PyObject* Application::sGetVersion(PyObject * /*self*/, PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; Py::List list; const std::map& cfg = Application::Config(); @@ -515,7 +515,7 @@ PyObject* Application::sAddImportType(PyObject * /*self*/, PyObject *args) char *psKey,*psMod; if (!PyArg_ParseTuple(args, "ss", &psKey,&psMod)) - return NULL; + return nullptr; GetApplication().addImportType(psKey,psMod); @@ -538,8 +538,8 @@ PyObject* Application::sGetImportType(PyObject * /*self*/, PyObject *args) { char* psKey=0; - if (!PyArg_ParseTuple(args, "|s", &psKey)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "|s", &psKey)) + return nullptr; if (psKey) { Py::List list; @@ -579,7 +579,7 @@ PyObject* Application::sAddExportType(PyObject * /*self*/, PyObject *args) char *psKey,*psMod; if (!PyArg_ParseTuple(args, "ss", &psKey,&psMod)) - return NULL; + return nullptr; GetApplication().addExportType(psKey,psMod); @@ -602,8 +602,8 @@ PyObject* Application::sGetExportType(PyObject * /*self*/, PyObject *args) { char* psKey=0; - if (!PyArg_ParseTuple(args, "|s", &psKey)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "|s", &psKey)) + return nullptr; if (psKey) { Py::List list; @@ -721,8 +721,8 @@ PyObject* Application::sGetHomePath(PyObject * /*self*/, PyObject *args) PyObject* Application::sListDocuments(PyObject * /*self*/, PyObject *args) { PyObject *sort = Py_False; - if (!PyArg_ParseTuple(args, "|O",&sort)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "|O",&sort)) + return nullptr; PY_TRY { PyObject *pDict = PyDict_New(); PyObject *pKey; @@ -749,7 +749,7 @@ PyObject* Application::sAddDocObserver(PyObject * /*self*/, PyObject *args) { PyObject* o; if (!PyArg_ParseTuple(args, "O",&o)) - return NULL; + return nullptr; PY_TRY { DocumentObserverPython::addObserver(Py::Object(o)); Py_Return; @@ -760,7 +760,7 @@ PyObject* Application::sRemoveDocObserver(PyObject * /*self*/, PyObject *args) { PyObject* o; if (!PyArg_ParseTuple(args, "O",&o)) - return NULL; + return nullptr; PY_TRY { DocumentObserverPython::removeObserver(Py::Object(o)); Py_Return; @@ -772,7 +772,7 @@ PyObject *Application::sSetLogLevel(PyObject * /*self*/, PyObject *args) char *tag; PyObject *pcObj; if (!PyArg_ParseTuple(args, "sO", &tag, &pcObj)) - return NULL; + return nullptr; PY_TRY{ int l; if (PyUnicode_Check(pcObj)) { @@ -792,7 +792,7 @@ PyObject *Application::sSetLogLevel(PyObject * /*self*/, PyObject *args) else { Py_Error(Base::BaseExceptionFreeCADError, "Unknown Log Level (use 'Default', 'Error', 'Warning', 'Message', 'Log', 'Trace' or an integer)"); - return NULL; + return nullptr; } }else l = PyLong_AsLong(pcObj); @@ -816,7 +816,7 @@ PyObject *Application::sGetLogLevel(PyObject * /*self*/, PyObject *args) { char *tag; if (!PyArg_ParseTuple(args, "s", &tag)) - return NULL; + return nullptr; PY_TRY{ int l = -1; @@ -856,7 +856,7 @@ PyObject *Application::sCheckLinkDepth(PyObject * /*self*/, PyObject *args) { short depth = 0; if (!PyArg_ParseTuple(args, "h", &depth)) - return NULL; + return nullptr; PY_TRY { return Py::new_reference_to(Py::Int(GetApplication().checkLinkDepth(depth,false))); @@ -869,7 +869,7 @@ PyObject *Application::sGetLinksTo(PyObject * /*self*/, PyObject *args) int options = 0; short count = 0; if (!PyArg_ParseTuple(args, "|Oih",&pyobj,&options, &count)) - return NULL; + return nullptr; PY_TRY { DocumentObject *obj = 0; @@ -894,24 +894,27 @@ PyObject *Application::sGetDependentObjects(PyObject * /*self*/, PyObject *args) PyObject *obj; int options = 0; if (!PyArg_ParseTuple(args, "O|i", &obj,&options)) - return 0; + return nullptr; std::vector objs; - if(PySequence_Check(obj)) { + if (PySequence_Check(obj)) { Py::Sequence seq(obj); - for(Py_ssize_t i=0;i(seq[i].ptr())->getDocumentObjectPtr()); } - }else if(!PyObject_TypeCheck(obj,&DocumentObjectPy::Type)) { + } + else if(!PyObject_TypeCheck(obj,&DocumentObjectPy::Type)) { PyErr_SetString(PyExc_TypeError, "Expect first argument to be either a document object or sequence of document objects"); - return 0; - }else + return nullptr; + } + else { objs.push_back(static_cast(obj)->getDocumentObjectPtr()); + } PY_TRY { auto ret = App::Document::getDependencyList(objs,options); @@ -929,7 +932,7 @@ PyObject *Application::sSetActiveTransaction(PyObject * /*self*/, PyObject *args char *name; PyObject *persist = Py_False; if (!PyArg_ParseTuple(args, "s|O", &name,&persist)) - return 0; + return nullptr; PY_TRY { Py::Int ret(GetApplication().setActiveTransaction(name,PyObject_IsTrue(persist))); @@ -940,7 +943,7 @@ PyObject *Application::sSetActiveTransaction(PyObject * /*self*/, PyObject *args PyObject *Application::sGetActiveTransaction(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, "")) - return 0; + return nullptr; PY_TRY { int id = 0; @@ -959,7 +962,7 @@ PyObject *Application::sCloseActiveTransaction(PyObject * /*self*/, PyObject *ar PyObject *abort = Py_False; int id = 0; if (!PyArg_ParseTuple(args, "|Oi", &abort,&id)) - return 0; + return nullptr; PY_TRY { GetApplication().closeActiveTransaction(PyObject_IsTrue(abort),id); @@ -970,7 +973,7 @@ PyObject *Application::sCloseActiveTransaction(PyObject * /*self*/, PyObject *ar PyObject *Application::sCheckAbort(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, "")) - return 0; + return nullptr; PY_TRY { Base::Sequencer().checkAbort(); diff --git a/src/App/DocumentObjectPyImp.cpp b/src/App/DocumentObjectPyImp.cpp index 387be86763..88aec80d87 100644 --- a/src/App/DocumentObjectPyImp.cpp +++ b/src/App/DocumentObjectPyImp.cpp @@ -82,8 +82,8 @@ PyObject* DocumentObjectPy::addProperty(PyObject *args) std::string sDocStr; PyObject *ro = Py_False, *hd = Py_False; if (!PyArg_ParseTuple(args, "s|ssethO!O!", &sType,&sName,&sGroup,"utf-8",&sDoc,&attr, - &PyBool_Type, &ro, &PyBool_Type, &hd)) // convert args: Python->C - return NULL; // NULL triggers exception + &PyBool_Type, &ro, &PyBool_Type, &hd)) + return nullptr; if (sDoc) { sDocStr = sDoc; @@ -108,8 +108,8 @@ PyObject* DocumentObjectPy::removeProperty(PyObject *args) PyObject* DocumentObjectPy::supportedProperties(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; std::vector ary; Base::Type::getAllDerivedFrom(App::Property::getClassTypeId(), ary); @@ -127,8 +127,8 @@ PyObject* DocumentObjectPy::supportedProperties(PyObject *args) PyObject* DocumentObjectPy::touch(PyObject * args) { char *propName = 0; - if (!PyArg_ParseTuple(args, "|s",&propName)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "|s",&propName)) + return nullptr; if(propName) { if(!propName[0]) { getDocumentObjectPtr()->touch(true); @@ -147,16 +147,16 @@ PyObject* DocumentObjectPy::touch(PyObject * args) PyObject* DocumentObjectPy::purgeTouched(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; getDocumentObjectPtr()->purgeTouched(); Py_Return; } PyObject* DocumentObjectPy::enforceRecompute(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; getDocumentObjectPtr()->enforceRecompute(); Py_Return; } @@ -305,12 +305,12 @@ Py::List DocumentObjectPy::getOutListRecursive(void) const PyObject* DocumentObjectPy::setExpression(PyObject * args) { - char * path = NULL; + char * path = nullptr; PyObject * expr; - char * comment = 0; + char * comment = nullptr; - if (!PyArg_ParseTuple(args, "sO|s", &path, &expr, &comment)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "sO|s", &path, &expr, &comment)) + return nullptr; App::ObjectIdentifier p(ObjectIdentifier::parse(getDocumentObjectPtr(), path)); @@ -795,7 +795,7 @@ PyObject *DocumentObjectPy::resolve(PyObject *args) { const char *subname; if (!PyArg_ParseTuple(args, "s",&subname)) - return NULL; // NULL triggers exception + return nullptr; PY_TRY { std::string elementName; @@ -820,7 +820,7 @@ PyObject *DocumentObjectPy::resolveSubElement(PyObject *args) PyObject *append = Py_False; int type = 0; if (!PyArg_ParseTuple(args, "s|Oi",&subname,&append,&type)) - return NULL; // NULL triggers exception + return nullptr; PY_TRY { std::pair elementName; diff --git a/src/App/DocumentPyImp.cpp b/src/App/DocumentPyImp.cpp index 3b4c3e96de..5dd05fb682 100644 --- a/src/App/DocumentPyImp.cpp +++ b/src/App/DocumentPyImp.cpp @@ -51,13 +51,13 @@ std::string DocumentPy::representation(void) const PyObject* DocumentPy::save(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PY_TRY { if (!getDocumentPtr()->save()) { PyErr_SetString(PyExc_ValueError, "Object attribute 'FileName' is not set"); - return NULL; + return nullptr; } } PY_CATCH; @@ -65,7 +65,7 @@ PyObject* DocumentPy::save(PyObject * args) Base::FileInfo fi(filename); if (!fi.isReadable()) { PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", filename); - return NULL; + return nullptr; } Py_Return; @@ -89,8 +89,8 @@ PyObject* DocumentPy::saveAs(PyObject * args) PyObject* DocumentPy::saveCopy(PyObject * args) { char* fn; - if (!PyArg_ParseTuple(args, "s", &fn)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &fn)) + return nullptr; PY_TRY { getDocumentPtr()->saveCopy(fn); @@ -125,23 +125,23 @@ PyObject* DocumentPy::load(PyObject * args) PyObject* DocumentPy::restore(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; const char* filename = getDocumentPtr()->FileName.getValue(); if (!filename || *filename == '\0') { PyErr_Format(PyExc_ValueError, "Object attribute 'FileName' is not set"); - return NULL; + return nullptr; } Base::FileInfo fi(filename); if (!fi.isReadable()) { PyErr_Format(PyExc_IOError, "No such file or directory: '%s'", filename); - return NULL; + return nullptr; } try { getDocumentPtr()->restore(); } catch (...) { PyErr_Format(PyExc_IOError, "Reading from file '%s' failed", filename); - return NULL; + return nullptr; } Py_Return; } @@ -173,8 +173,8 @@ PyObject* DocumentPy::getFileName(PyObject* args) PyObject* DocumentPy::mergeProject(PyObject * args) { char* filename; - if (!PyArg_ParseTuple(args, "s", &filename)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &filename)) + return nullptr; PY_TRY { Base::FileInfo fi(filename); @@ -189,8 +189,8 @@ PyObject* DocumentPy::mergeProject(PyObject * args) PyObject* DocumentPy::exportGraphviz(PyObject * args) { char* fn=0; - if (!PyArg_ParseTuple(args, "|s",&fn)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "|s",&fn)) + return nullptr; if (fn) { Base::FileInfo fi(fn); Base::ofstream str(fi); @@ -288,8 +288,8 @@ PyObject* DocumentPy::addObject(PyObject *args, PyObject *kwd) PyObject* DocumentPy::removeObject(PyObject *args) { char *sName; - if (!PyArg_ParseTuple(args, "s",&sName)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s",&sName)) + return nullptr; DocumentObject *pcFtr = getDocumentPtr()->getObject(sName); @@ -308,7 +308,7 @@ PyObject* DocumentPy::copyObject(PyObject *args) { PyObject *obj, *rec=Py_False, *retAll=Py_False; if (!PyArg_ParseTuple(args, "O|OO",&obj,&rec,&retAll)) - return NULL; // NULL triggers exception + return nullptr; std::vector objs; bool single = false; @@ -317,7 +317,7 @@ PyObject* DocumentPy::copyObject(PyObject *args) for (Py_ssize_t i=0;i(seq[i].ptr())->getDocumentObjectPtr()); } @@ -325,7 +325,7 @@ PyObject* DocumentPy::copyObject(PyObject *args) else if (!PyObject_TypeCheck(obj,&DocumentObjectPy::Type)) { PyErr_SetString(PyExc_TypeError, "Expect first argument to be either a document object or sequence of document objects"); - return 0; + return nullptr; } else { objs.push_back(static_cast(obj)->getDocumentObjectPtr()); @@ -348,7 +348,7 @@ PyObject* DocumentPy::importLinks(PyObject *args) { PyObject *obj = Py_None; if (!PyArg_ParseTuple(args, "|O",&obj)) - return NULL; // NULL triggers exception + return nullptr; std::vector objs; if (PySequence_Check(obj)) { @@ -356,7 +356,7 @@ PyObject* DocumentPy::importLinks(PyObject *args) for (Py_ssize_t i=0;i(seq[i].ptr())->getDocumentObjectPtr()); } @@ -367,7 +367,7 @@ PyObject* DocumentPy::importLinks(PyObject *args) else if (!PyObject_TypeCheck(obj,&DocumentObjectPy::Type)) { PyErr_SetString(PyExc_TypeError, "Expect first argument to be either a document object or sequence of document objects"); - return 0; + return nullptr; } else { objs.push_back(static_cast(obj)->getDocumentObjectPtr()); @@ -390,7 +390,7 @@ PyObject* DocumentPy::moveObject(PyObject *args) { PyObject *obj, *rec=Py_False; if (!PyArg_ParseTuple(args, "O!|O!",&(DocumentObjectPy::Type),&obj,&PyBool_Type,&rec)) - return NULL; // NULL triggers exception + return nullptr; DocumentObjectPy* docObj = static_cast(obj); DocumentObject* move = getDocumentPtr()->moveObject(docObj->getDocumentObjectPtr(), PyObject_IsTrue(rec) ? true : false); @@ -405,9 +405,9 @@ PyObject* DocumentPy::moveObject(PyObject *args) PyObject* DocumentPy::openTransaction(PyObject *args) { - PyObject *value = 0; + PyObject *value = nullptr; if (!PyArg_ParseTuple(args, "|O",&value)) - return NULL; // NULL triggers exception + return nullptr; std::string cmd; @@ -419,7 +419,7 @@ PyObject* DocumentPy::openTransaction(PyObject *args) } else { PyErr_SetString(PyExc_TypeError, "string or unicode expected"); - return NULL; + return nullptr; } getDocumentPtr()->openTransaction(cmd.c_str()); @@ -428,16 +428,16 @@ PyObject* DocumentPy::openTransaction(PyObject *args) PyObject* DocumentPy::abortTransaction(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; getDocumentPtr()->abortTransaction(); Py_Return; } PyObject* DocumentPy::commitTransaction(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; getDocumentPtr()->commitTransaction(); Py_Return; } @@ -448,8 +448,8 @@ Py::Boolean DocumentPy::getHasPendingTransaction() const { PyObject* DocumentPy::undo(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; if (getDocumentPtr()->getAvailableUndos()) getDocumentPtr()->undo(); Py_Return; @@ -457,8 +457,8 @@ PyObject* DocumentPy::undo(PyObject * args) PyObject* DocumentPy::redo(PyObject * args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; if (getDocumentPtr()->getAvailableRedos()) getDocumentPtr()->redo(); Py_Return; @@ -568,9 +568,9 @@ PyObject* DocumentPy::getObject(PyObject *args) { long id = -1; char *sName = 0; - if (!PyArg_ParseTuple(args, "s",&sName)) { // convert args: Python->C + if (!PyArg_ParseTuple(args, "s",&sName)) { if (!PyArg_ParseTuple(args, "l", &id)) - return NULL; // NULL triggers exception + return nullptr; } DocumentObject *pcFtr = sName?getDocumentPtr()->getObject(sName):getDocumentPtr()->getObjectByID(id); @@ -583,8 +583,8 @@ PyObject* DocumentPy::getObject(PyObject *args) PyObject* DocumentPy::getObjectsByLabel(PyObject *args) { char *sName; - if (!PyArg_ParseTuple(args, "s",&sName)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s",&sName)) + return nullptr; Py::List list; std::string name = sName; @@ -639,8 +639,8 @@ Py::Object DocumentPy::getActiveObject(void) const PyObject* DocumentPy::supportedTypes(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; std::vector ary; Base::Type::getAllDerivedFrom(App::DocumentObject::getClassTypeId(), ary); @@ -760,7 +760,7 @@ PyObject* DocumentPy::getTempFileName(PyObject *args) { PyObject *value; if (!PyArg_ParseTuple(args, "O",&value)) - return NULL; // NULL triggers exception + return nullptr; std::string string; if (PyUnicode_Check(value)) { @@ -793,13 +793,15 @@ PyObject *DocumentPy::getCustomAttributes(const char* attr) const // wise it wouldn't be possible to address this attribute any more. // The object must then be addressed by the getObject() method directly. App::Property* prop = getPropertyContainerPtr()->getPropertyByName(attr); - if (prop) return 0; + if (prop) + return nullptr; if (this->ob_type->tp_dict == NULL) { if (PyType_Ready(this->ob_type) < 0) - return 0; + return nullptr; } PyObject* item = PyDict_GetItemString(this->ob_type->tp_dict, attr); - if (item) return 0; + if (item) + return nullptr; // search for an object with this name DocumentObject* obj = getDocumentPtr()->getObject(attr); return (obj ? obj->getPyObject() : 0); @@ -813,7 +815,8 @@ int DocumentPy::setCustomAttributes(const char* attr, PyObject *) // wise it wouldn't be possible to address this attribute any more. // The object must then be addressed by the getObject() method directly. App::Property* prop = getPropertyContainerPtr()->getPropertyByName(attr); - if (prop) return 0; + if (prop) + return 0; if (this->ob_type->tp_dict == NULL) { if (PyType_Ready(this->ob_type) < 0) return 0; @@ -839,7 +842,7 @@ PyObject* DocumentPy::getLinksTo(PyObject *args) int options = 0; short count = 0; if (!PyArg_ParseTuple(args, "|Oih", &pyobj,&options, &count)) - return NULL; + return nullptr; PY_TRY { DocumentObject *obj = 0; diff --git a/src/App/ExtensionContainerPyImp.cpp b/src/App/ExtensionContainerPyImp.cpp index 1b965e0803..9a6a2b9fcd 100644 --- a/src/App/ExtensionContainerPyImp.cpp +++ b/src/App/ExtensionContainerPyImp.cpp @@ -175,7 +175,7 @@ PyObject* ExtensionContainerPy::hasExtension(PyObject *args) { char *type; PyObject *deriv = Py_True; if (!PyArg_ParseTuple(args, "s|O", &type, &deriv)) - return NULL; // NULL triggers exception + return nullptr; //get the extension type asked for bool derived = PyObject_IsTrue(deriv); diff --git a/src/App/GroupExtensionPyImp.cpp b/src/App/GroupExtensionPyImp.cpp index 6bba7a8c69..0764cc55ed 100644 --- a/src/App/GroupExtensionPyImp.cpp +++ b/src/App/GroupExtensionPyImp.cpp @@ -42,8 +42,8 @@ std::string GroupExtensionPy::representation(void) const PyObject* GroupExtensionPy::newObject(PyObject *args) { char *sType,*sName=0; - if (!PyArg_ParseTuple(args, "s|s", &sType,&sName)) // convert args: Python->C - return NULL; + if (!PyArg_ParseTuple(args, "s|s", &sType,&sName)) + return nullptr; DocumentObject *object = getGroupExtensionPtr()->addObject(sType, sName); if ( object ) { @@ -51,35 +51,35 @@ PyObject* GroupExtensionPy::newObject(PyObject *args) } else { PyErr_Format(Base::BaseExceptionFreeCADError, "Cannot create object of type '%s'", sType); - return NULL; + return nullptr; } } PyObject* GroupExtensionPy::addObject(PyObject *args) { PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) + return nullptr; DocumentObjectPy* docObj = static_cast(object); if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an invalid object"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr()->getDocument() != getGroupExtensionPtr()->getExtendedObject()->getDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an object from another document to this group"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr() == this->getGroupExtensionPtr()->getExtendedObject()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to itself"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr()->hasExtension(GroupExtension::getExtensionClassTypeId())) { App::GroupExtension* docGrp = docObj->getDocumentObjectPtr()->getExtensionByType(); if (docGrp->hasObject(getGroupExtensionPtr()->getExtendedObject())) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to a child group"); - return NULL; + return nullptr; } } @@ -96,8 +96,8 @@ PyObject* GroupExtensionPy::addObject(PyObject *args) PyObject* GroupExtensionPy::addObjects(PyObject *args) { PyObject *object; - if (!PyArg_ParseTuple(args, "O", &object)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "O", &object)) + return nullptr; if (PyTuple_Check(object) || PyList_Check(object)) { Py::Sequence list(object); @@ -133,8 +133,8 @@ PyObject* GroupExtensionPy::addObjects(PyObject *args) { PyObject* GroupExtensionPy::setObjects(PyObject *args) { PyObject *object; - if (!PyArg_ParseTuple(args, "O", &object)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "O", &object)) + return nullptr; if (PyTuple_Check(object) || PyList_Check(object)) { Py::Sequence list(object); @@ -170,17 +170,17 @@ PyObject* GroupExtensionPy::setObjects(PyObject *args) { PyObject* GroupExtensionPy::removeObject(PyObject *args) { PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) + return nullptr; DocumentObjectPy* docObj = static_cast(object); if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an invalid object"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr()->getDocument() != getGroupExtensionPtr()->getExtendedObject()->getDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an object from another document from this group"); - return NULL; + return nullptr; } GroupExtension* grp = getGroupExtensionPtr(); @@ -196,8 +196,8 @@ PyObject* GroupExtensionPy::removeObject(PyObject *args) PyObject* GroupExtensionPy::removeObjects(PyObject *args) { PyObject *object; - if (!PyArg_ParseTuple(args, "O", &object)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "O", &object)) + return nullptr; if (PyTuple_Check(object) || PyList_Check(object)) { Py::Sequence list(object); @@ -232,8 +232,8 @@ PyObject* GroupExtensionPy::removeObjects(PyObject *args) { PyObject* GroupExtensionPy::removeObjectsFromDocument(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; getGroupExtensionPtr()->removeObjectsFromDocument(); Py_Return; @@ -242,8 +242,8 @@ PyObject* GroupExtensionPy::removeObjectsFromDocument(PyObject *args) PyObject* GroupExtensionPy::getObject(PyObject *args) { char* pcName; - if (!PyArg_ParseTuple(args, "s", &pcName)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pcName)) + return nullptr; DocumentObject* obj = getGroupExtensionPtr()->getObject(pcName); if ( obj ) { @@ -259,23 +259,23 @@ PyObject* GroupExtensionPy::hasObject(PyObject *args) PyObject *recursivePy = 0; int recursive = 0; if (!PyArg_ParseTuple(args, "O!|O", &(DocumentObjectPy::Type), &object, &recursivePy)) - return NULL; // NULL triggers exception + return nullptr; DocumentObjectPy* docObj = static_cast(object); if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot check an invalid object"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr()->getDocument() != getGroupExtensionPtr()->getExtendedObject()->getDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot check an object from another document with this group"); - return NULL; + return nullptr; } if (recursivePy) { recursive = PyObject_IsTrue(recursivePy); if ( recursive == -1) { // Note: shouldn't happen PyErr_SetString(PyExc_ValueError, "The recursive parameter should be of boolean type"); - return 0; + return nullptr; } } diff --git a/src/App/MaterialPyImp.cpp b/src/App/MaterialPyImp.cpp index fee8cebc7e..ae65f8fb9e 100644 --- a/src/App/MaterialPyImp.cpp +++ b/src/App/MaterialPyImp.cpp @@ -86,8 +86,8 @@ std::string MaterialPy::representation(void) const PyObject* MaterialPy::set(PyObject * args) { char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; getMaterialPtr()->set(pstr); diff --git a/src/App/PropertyContainerPyImp.cpp b/src/App/PropertyContainerPyImp.cpp index 67b884d687..6d7e477609 100644 --- a/src/App/PropertyContainerPyImp.cpp +++ b/src/App/PropertyContainerPyImp.cpp @@ -52,8 +52,8 @@ PyObject* PropertyContainerPy::getPropertyByName(PyObject *args) { char *pstr; int checkOwner=0; - if (!PyArg_ParseTuple(args, "s|i", &pstr, &checkOwner)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s|i", &pstr, &checkOwner)) + return nullptr; App::Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (prop) { if(!checkOwner || (checkOwner==1 && prop->getContainer()==getPropertyContainerPtr())) @@ -69,8 +69,8 @@ PyObject* PropertyContainerPy::getPropertyByName(PyObject *args) PyObject* PropertyContainerPy::getPropertyTouchList(PyObject *args) { char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; App::Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (prop && prop->isDerivedFrom(PropertyLists::getClassTypeId())) { const auto &touched = static_cast(prop)->getTouchList(); @@ -91,8 +91,8 @@ PyObject* PropertyContainerPy::getTypeOfProperty(PyObject *args) { Py::List ret; char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (!prop) { @@ -118,8 +118,8 @@ PyObject* PropertyContainerPy::getTypeOfProperty(PyObject *args) PyObject* PropertyContainerPy::getTypeIdOfProperty(PyObject *args) { char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (!prop) { @@ -268,8 +268,8 @@ PyObject* PropertyContainerPy::setPropertyStatus(PyObject *args) PyObject* PropertyContainerPy::getPropertyStatus(PyObject *args) { char* name = ""; - if (!PyArg_ParseTuple(args, "|s", &name)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "|s", &name)) + return nullptr; Py::List ret; const auto &statusMap = getStatusMap(); @@ -306,8 +306,8 @@ PyObject* PropertyContainerPy::getPropertyStatus(PyObject *args) PyObject* PropertyContainerPy::getEditorMode(PyObject *args) { char* name; - if (!PyArg_ParseTuple(args, "s", &name)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s", &name)) + return nullptr; App::Property* prop = getPropertyContainerPtr()->getPropertyByName(name); Py::List ret; @@ -324,8 +324,8 @@ PyObject* PropertyContainerPy::getEditorMode(PyObject *args) PyObject* PropertyContainerPy::getGroupOfProperty(PyObject *args) { char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (!prop) { @@ -344,8 +344,8 @@ PyObject* PropertyContainerPy::setGroupOfProperty(PyObject *args) { char *pstr; char *group; - if (!PyArg_ParseTuple(args, "ss", &pstr, &group)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "ss", &pstr, &group)) + return nullptr; PY_TRY { Property* prop = getPropertyContainerPtr()->getDynamicPropertyByName(pstr); @@ -362,8 +362,8 @@ PyObject* PropertyContainerPy::setGroupOfProperty(PyObject *args) PyObject* PropertyContainerPy::getDocumentationOfProperty(PyObject *args) { char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (!prop) { @@ -382,8 +382,8 @@ PyObject* PropertyContainerPy::setDocumentationOfProperty(PyObject *args) { char *pstr; char *doc; - if (!PyArg_ParseTuple(args, "ss", &pstr, &doc)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "ss", &pstr, &doc)) + return nullptr; PY_TRY { Property* prop = getPropertyContainerPtr()->getDynamicPropertyByName(pstr); @@ -399,8 +399,8 @@ PyObject* PropertyContainerPy::setDocumentationOfProperty(PyObject *args) PyObject* PropertyContainerPy::getEnumerationsOfProperty(PyObject *args) { char *pstr; - if (!PyArg_ParseTuple(args, "s", &pstr)) // convert args: Python->C - return nullptr; // nullptr triggers exception + if (!PyArg_ParseTuple(args, "s", &pstr)) + return nullptr; Property* prop = getPropertyContainerPtr()->getPropertyByName(pstr); if (!prop) { diff --git a/src/Base/BaseClassPyImp.cpp b/src/Base/BaseClassPyImp.cpp index 9ed0165543..3621e714f4 100644 --- a/src/Base/BaseClassPyImp.cpp +++ b/src/Base/BaseClassPyImp.cpp @@ -39,8 +39,8 @@ std::string BaseClassPy::representation() const PyObject* BaseClassPy::isDerivedFrom(PyObject *args) { char *name; - if (!PyArg_ParseTuple(args, "s", &name)) // convert args: Python->C - return nullptr; // NULL triggers exception + if (!PyArg_ParseTuple(args, "s", &name)) + return nullptr; Base::Type type = Base::Type::fromName(name); bool v = (type != Base::Type::badType() && getBaseClassPtr()->getTypeId().isDerivedFrom(type)); @@ -49,8 +49,8 @@ PyObject* BaseClassPy::isDerivedFrom(PyObject *args) PyObject* BaseClassPy::getAllDerivedFrom(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return nullptr; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; std::vector ary; Base::Type::getAllDerivedFrom(getBaseClassPtr()->getTypeId(), ary); diff --git a/src/Base/Console.cpp b/src/Base/Console.cpp index d214ced15c..8b3da64208 100644 --- a/src/Base/Console.cpp +++ b/src/Base/Console.cpp @@ -584,8 +584,8 @@ PyObject *ConsoleSingleton::sPyGetStatus(PyObject * /*self*/, PyObject *args) { char *pstr1; char *pstr2; - if (!PyArg_ParseTuple(args, "ss", &pstr1, &pstr2)) // convert args: Python->C - return nullptr; // NULL triggers exception + if (!PyArg_ParseTuple(args, "ss", &pstr1, &pstr2)) + return nullptr; PY_TRY{ bool b=false; diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index 65092891d4..492beaa78b 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -1229,7 +1229,7 @@ Py::Object View3DInventorPy::getCameraType(const Py::Tuple& args) Py::Object View3DInventorPy::setCameraType(const Py::Tuple& args) { int cameratype=-1; - if (!PyArg_ParseTuple(args.ptr(), "i", &cameratype)) { // convert args: Python->C + if (!PyArg_ParseTuple(args.ptr(), "i", &cameratype)) { char* modename; PyErr_Clear(); if (!PyArg_ParseTuple(args.ptr(), "s", &modename)) @@ -1306,10 +1306,10 @@ Py::Object View3DInventorPy::dump(const Py::Tuple& args) Py::Object View3DInventorPy::dumpNode(const Py::Tuple& args) { PyObject* object; - if (!PyArg_ParseTuple(args.ptr(), "O", &object)) // convert args: Python->C + if (!PyArg_ParseTuple(args.ptr(), "O", &object)) throw Py::Exception(); - void* ptr = 0; + void* ptr = nullptr; try { Base::Interpreter().convertSWIGPointerObj("pivy.coin", "SoNode *", object, &ptr, 0); } diff --git a/src/Gui/ViewProviderDocumentObjectPyImp.cpp b/src/Gui/ViewProviderDocumentObjectPyImp.cpp index 04c356cc95..2a2aaa8c07 100644 --- a/src/Gui/ViewProviderDocumentObjectPyImp.cpp +++ b/src/Gui/ViewProviderDocumentObjectPyImp.cpp @@ -47,8 +47,8 @@ std::string ViewProviderDocumentObjectPy::representation(void) const PyObject* ViewProviderDocumentObjectPy::update(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PY_TRY { getViewProviderDocumentObjectPtr()->updateView(); Py_Return; @@ -90,7 +90,7 @@ Py::Object ViewProviderDocumentObjectPy::getDocument(void) const PyObject *ViewProviderDocumentObjectPy::getCustomAttributes(const char* /*attr*/) const { - return 0; + return nullptr; } int ViewProviderDocumentObjectPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/) diff --git a/src/Gui/ViewProviderPyImp.cpp b/src/Gui/ViewProviderPyImp.cpp index 07cf3d26a7..b1977eb3d4 100644 --- a/src/Gui/ViewProviderPyImp.cpp +++ b/src/Gui/ViewProviderPyImp.cpp @@ -66,8 +66,8 @@ PyObject* ViewProviderPy::addProperty(PyObject *args) std::string sDocStr; PyObject *ro = Py_False, *hd = Py_False; if (!PyArg_ParseTuple(args, "s|ssethO!O!", &sType,&sName,&sGroup,"utf-8",&sDoc,&attr, - &PyBool_Type, &ro, &PyBool_Type, &hd)) // convert args: Python->C - return NULL; // NULL triggers exception + &PyBool_Type, &ro, &PyBool_Type, &hd)) + return nullptr; if (sDoc) { sDocStr = sDoc; @@ -95,7 +95,7 @@ PyObject* ViewProviderPy::removeProperty(PyObject *args) { char *sName; if (!PyArg_ParseTuple(args, "s", &sName)) - return NULL; + return nullptr; try { bool ok = getViewProviderPtr()->removeDynamicProperty(sName); @@ -108,8 +108,8 @@ PyObject* ViewProviderPy::removeProperty(PyObject *args) PyObject* ViewProviderPy::supportedProperties(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; std::vector ary; Base::Type::getAllDerivedFrom(App::Property::getClassTypeId(), ary); @@ -126,8 +126,8 @@ PyObject* ViewProviderPy::supportedProperties(PyObject *args) PyObject* ViewProviderPy::show(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PY_TRY { getViewProviderPtr()->show(); Py_Return; @@ -136,8 +136,8 @@ PyObject* ViewProviderPy::show(PyObject *args) PyObject* ViewProviderPy::hide(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PY_TRY { getViewProviderPtr()->hide(); Py_Return; @@ -146,8 +146,8 @@ PyObject* ViewProviderPy::hide(PyObject *args) PyObject* ViewProviderPy::isVisible(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PY_TRY { return Py_BuildValue("O", (getViewProviderPtr()->isShow() ? Py_True : Py_False)); } PY_CATCH; @@ -157,14 +157,14 @@ PyObject* ViewProviderPy::canDragObject(PyObject *args) { PyObject *obj = Py_None; if (!PyArg_ParseTuple(args, "|O", &obj)) - return NULL; + return nullptr; PY_TRY { bool ret; if(obj == Py_None) ret = getViewProviderPtr()->canDragObjects(); else if(!PyObject_TypeCheck(obj,&App::DocumentObjectPy::Type)) { PyErr_SetString(PyExc_TypeError, "exepcting a type of DocumentObject"); - return 0; + return nullptr; }else ret = getViewProviderPtr()->canDragObject( static_cast(obj)->getDocumentObjectPtr()); @@ -179,21 +179,21 @@ PyObject* ViewProviderPy::canDropObject(PyObject *args) PyObject *pyElements = Py_None; const char *subname = 0; if (!PyArg_ParseTuple(args, "|OOsO", &obj,&owner,&subname,&pyElements)) - return NULL; + return nullptr; PY_TRY { bool ret; if(obj == Py_None) ret = getViewProviderPtr()->canDropObjects(); else if(!PyObject_TypeCheck(obj,&App::DocumentObjectPy::Type)) { PyErr_SetString(PyExc_TypeError, "exepcting 'obj' to be of type DocumentObject"); - return 0; + return nullptr; } auto pcObject = static_cast(obj)->getDocumentObjectPtr(); - App::DocumentObject *pcOwner = 0; + App::DocumentObject *pcOwner = nullptr; if(owner!=Py_None) { if(!PyObject_TypeCheck(owner,&App::DocumentObjectPy::Type)) { PyErr_SetString(PyExc_TypeError, "exepcting 'owner' to be of type DocumentObject"); - return NULL; + return nullptr; } pcOwner = static_cast(owner)->getDocumentObjectPtr(); } @@ -201,9 +201,10 @@ PyObject* ViewProviderPy::canDropObject(PyObject *args) if(pyElements!=Py_None) { try { elements.setPyObject(pyElements); - }catch(...) { + } + catch(...) { PyErr_SetString(PyExc_TypeError, "exepcting the forth argument to be of type sequence of strings"); - return 0; + return nullptr; } } ret = getViewProviderPtr()->canDropObjectEx(pcObject,pcOwner,subname,elements.getValues()); @@ -309,8 +310,8 @@ PyObject* ViewProviderPy::addDisplayMode(PyObject * args) PyObject* ViewProviderPy::listDisplayModes(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PY_TRY { std::vector modes = getViewProviderPtr()->getDisplayModes(); PyObject* pyList = PyList_New(modes.size()); @@ -327,8 +328,8 @@ PyObject* ViewProviderPy::listDisplayModes(PyObject *args) PyObject* ViewProviderPy::toString(PyObject *args) { - if (!PyArg_ParseTuple(args, "")) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "")) + return nullptr; PY_TRY { std::string buffer = getViewProviderPtr()->toString(); return Py::new_reference_to(Py::String(buffer)); @@ -358,7 +359,7 @@ PyObject* ViewProviderPy::setTransformation(PyObject *args) PyObject* ViewProviderPy::claimChildren(PyObject* args) { if (!PyArg_ParseTuple(args, "")) - return NULL; // NULL triggers exception + return nullptr; std::vector children = this->getViewProviderPtr()->claimChildren(); Py::List ret; @@ -376,7 +377,7 @@ PyObject* ViewProviderPy::partialRender(PyObject* args) PyObject *value = Py_None; PyObject *clear = Py_False; if (!PyArg_ParseTuple(args, "|OO",&value,&clear)) - return NULL; // NULL triggers exception + return nullptr; std::vector values; if(value != Py_None) { @@ -412,7 +413,7 @@ PyObject* ViewProviderPy::getElementColors(PyObject* args) { const char *element = 0; if (!PyArg_ParseTuple(args, "|s", &element)) - return 0; + return nullptr; Py::Dict dict; for(auto &v : getViewProviderPtr()->getElementColors(element)) { @@ -427,7 +428,7 @@ PyObject* ViewProviderPy::setElementColors(PyObject* args) { PyObject *pyObj; if (!PyArg_ParseTuple(args, "O", &pyObj)) - return 0; + return nullptr; if(!PyDict_Check(pyObj)) throw Py::TypeError("Expect a dict"); @@ -451,8 +452,8 @@ PyObject* ViewProviderPy::getElementPicked(PyObject* args) { PyObject *obj; if (!PyArg_ParseTuple(args, "O",&obj)) - return NULL; - void *ptr = 0; + return nullptr; + void *ptr = nullptr; Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPickedPoint", obj, &ptr, 0); SoPickedPoint *pp = reinterpret_cast(ptr); if(!pp) @@ -469,8 +470,8 @@ PyObject* ViewProviderPy::getDetailPath(PyObject* args) PyObject *path; PyObject *append = Py_True; if (!PyArg_ParseTuple(args, "sO|O",&sub,&path,&append)) - return NULL; - void *ptr = 0; + return nullptr; + void *ptr = nullptr; Base::Interpreter().convertSWIGPointerObj("pivy.coin", "_p_SoPath", path, &ptr, 0); SoPath *pPath = reinterpret_cast(ptr); if(!pPath) @@ -490,17 +491,17 @@ PyObject* ViewProviderPy::getDetailPath(PyObject* args) PyObject *ViewProviderPy::signalChangeIcon(PyObject *args) { if (!PyArg_ParseTuple(args, "")) - return NULL; + return nullptr; getViewProviderPtr()->signalChangeIcon(); Py_Return; } PyObject *ViewProviderPy::getBoundingBox(PyObject *args) { PyObject *transform=Py_True; - PyObject *pyView = 0; - const char *subname = 0; + PyObject *pyView = nullptr; + const char *subname = nullptr; if (!PyArg_ParseTuple(args, "|sOO!", &subname,&transform,View3DInventorPy::type_object(),&pyView)) - return NULL; + return nullptr; PY_TRY { View3DInventor *view = 0; if(pyView) @@ -513,7 +514,7 @@ PyObject *ViewProviderPy::getBoundingBox(PyObject *args) { PyObject *ViewProviderPy::doubleClicked(PyObject *args) { if(!PyArg_ParseTuple(args, "")) - return 0; + return nullptr; PY_TRY { return Py::new_reference_to(Py::Boolean(getViewProviderPtr()->doubleClicked())); }PY_CATCH; @@ -526,7 +527,7 @@ PyObject *ViewProviderPy::getCustomAttributes(const char* attr) const if (prop) return prop->getPyObject(); else - return 0; + return nullptr; } int ViewProviderPy::setCustomAttributes(const char* attr, PyObject* value) diff --git a/src/Mod/Fem/App/FemMeshPyImp.cpp b/src/Mod/Fem/App/FemMeshPyImp.cpp index 2f85a87934..129aff807b 100644 --- a/src/Mod/Fem/App/FemMeshPyImp.cpp +++ b/src/Mod/Fem/App/FemMeshPyImp.cpp @@ -80,8 +80,8 @@ PyObject *FemMeshPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Py int FemMeshPy::PyInit(PyObject* args, PyObject* /*kwd*/) { PyObject *pcObj=0; - if (!PyArg_ParseTuple(args, "|O", &pcObj)) // convert args: Python->C - return -1; // NULL triggers exception + if (!PyArg_ParseTuple(args, "|O", &pcObj)) + return -1; try { // if no mesh is given diff --git a/src/Mod/Part/App/AttachEnginePyImp.cpp b/src/Mod/Part/App/AttachEnginePyImp.cpp index 31c93ac01e..993166a75c 100644 --- a/src/Mod/Part/App/AttachEnginePyImp.cpp +++ b/src/Mod/Part/App/AttachEnginePyImp.cpp @@ -509,7 +509,7 @@ PyObject* AttachEnginePy::readParametersFromFeature(PyObject* args) { PyObject* obj; if (!PyArg_ParseTuple(args, "O!",&(App::DocumentObjectPy::Type),&obj)) - return NULL; // NULL triggers exception + return nullptr; try{ App::DocumentObjectPy* dobjpy = static_cast(obj); @@ -533,7 +533,7 @@ PyObject* AttachEnginePy::writeParametersToFeature(PyObject* args) { PyObject* obj; if (!PyArg_ParseTuple(args, "O!",&(App::DocumentObjectPy::Type),&obj)) - return NULL; // NULL triggers exception + return nullptr; try{ App::DocumentObjectPy* dobjpy = static_cast(obj); diff --git a/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp b/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp index e7caae1d19..650de1673e 100644 --- a/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp +++ b/src/Mod/Path/App/FeaturePathCompoundPyImp.cpp @@ -43,21 +43,21 @@ std::string FeaturePathCompoundPy::representation(void) const PyObject* FeaturePathCompoundPy::addObject(PyObject *args) { PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) + return nullptr; DocumentObjectPy* docObj = static_cast(object); if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an invalid object"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr()->getDocument() != getFeaturePathCompoundPtr()->getDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add an object from another document to this group"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr() == this->getFeaturePathCompoundPtr()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot add a group object to itself"); - return NULL; + return nullptr; } FeatureCompound* comp = getFeaturePathCompoundPtr(); @@ -88,17 +88,17 @@ PyObject* FeaturePathCompoundPy::addObject(PyObject *args) PyObject* FeaturePathCompoundPy::removeObject(PyObject *args) { PyObject *object; - if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) // convert args: Python->C - return NULL; // NULL triggers exception + if (!PyArg_ParseTuple(args, "O!", &(DocumentObjectPy::Type), &object)) + return nullptr; DocumentObjectPy* docObj = static_cast(object); if (!docObj->getDocumentObjectPtr() || !docObj->getDocumentObjectPtr()->getNameInDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an invalid object"); - return NULL; + return nullptr; } if (docObj->getDocumentObjectPtr()->getDocument() != getFeaturePathCompoundPtr()->getDocument()) { PyErr_SetString(Base::BaseExceptionFreeCADError, "Cannot remove an object from another document from this group"); - return NULL; + return nullptr; } FeatureCompound* comp = getFeaturePathCompoundPtr(); diff --git a/src/Mod/Points/App/PointsPyImp.cpp b/src/Mod/Points/App/PointsPyImp.cpp index 84dd535d04..06a193b855 100644 --- a/src/Mod/Points/App/PointsPyImp.cpp +++ b/src/Mod/Points/App/PointsPyImp.cpp @@ -51,8 +51,8 @@ PyObject *PointsPy::PyMake(struct _typeobject *, PyObject *, PyObject *) // Pyt int PointsPy::PyInit(PyObject* args, PyObject* /*kwd*/) { PyObject *pcObj=nullptr; - if (!PyArg_ParseTuple(args, "|O", &pcObj)) // convert args: Python->C - return -1; // NULL triggers exception + if (!PyArg_ParseTuple(args, "|O", &pcObj)) + return -1; // if no mesh is given if (!pcObj) return 0;