From 4b2ffd2eca38b7fc09a662cdc280d67a32a49a0f Mon Sep 17 00:00:00 2001 From: Uwe Date: Mon, 18 Jul 2022 03:16:22 +0200 Subject: [PATCH] [Base] remove superfluous nullptr checks --- src/Base/Builder3D.cpp | 2 +- src/Base/ExceptionFactory.cpp | 4 ++-- src/Base/Factory.cpp | 4 ++-- src/Base/FileInfo.cpp | 4 ++-- src/Base/Interpreter.cpp | 36 +++++++++++++++++------------------ src/Base/Parameter.cpp | 6 +++--- src/Base/PyObjectBase.cpp | 6 +++--- src/Base/gzstream.cpp | 2 +- src/Base/swigpyrun.inl | 8 ++++---- 9 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/Base/Builder3D.cpp b/src/Base/Builder3D.cpp index b08df85ec6..feb65d6a5e 100644 --- a/src/Base/Builder3D.cpp +++ b/src/Base/Builder3D.cpp @@ -304,7 +304,7 @@ void Builder3D::saveToLog() // So, we send the string directly to the observer that handles the Inventor stuff. //Console().Log("Vdbg: %s \n",result.str().c_str()); ILogger* obs = Base::Console().Get("StatusBar"); - if (obs != nullptr){ + if (obs){ obs->SendLog(result.str().c_str(), Base::LogStyle::Log); } } diff --git a/src/Base/ExceptionFactory.cpp b/src/Base/ExceptionFactory.cpp index f574597573..40ff217394 100644 --- a/src/Base/ExceptionFactory.cpp +++ b/src/Base/ExceptionFactory.cpp @@ -32,14 +32,14 @@ ExceptionFactory* ExceptionFactory::_pcSingleton = nullptr; ExceptionFactory& ExceptionFactory::Instance() { - if (_pcSingleton == nullptr) + if (!_pcSingleton) _pcSingleton = new ExceptionFactory; return *_pcSingleton; } void ExceptionFactory::Destruct () { - if (_pcSingleton != nullptr) + if (_pcSingleton) delete _pcSingleton; _pcSingleton = nullptr; } diff --git a/src/Base/Factory.cpp b/src/Base/Factory.cpp index 7864c4b367..b176bb3883 100644 --- a/src/Base/Factory.cpp +++ b/src/Base/Factory.cpp @@ -82,14 +82,14 @@ ScriptFactorySingleton* ScriptFactorySingleton::_pcSingleton = nullptr; ScriptFactorySingleton& ScriptFactorySingleton::Instance() { - if (_pcSingleton == nullptr) + if (!_pcSingleton) _pcSingleton = new ScriptFactorySingleton; return *_pcSingleton; } void ScriptFactorySingleton::Destruct () { - if (_pcSingleton != nullptr) + if (_pcSingleton) delete _pcSingleton; _pcSingleton = nullptr; } diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index de13ebfe7e..1e0bc29d5b 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -619,12 +619,12 @@ std::vector FileInfo::getDirectoryContent() const #elif defined (FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD) DIR* dp(nullptr); struct dirent* dentry(nullptr); - if ((dp = opendir(FileName.c_str())) == nullptr) + if (!(dp = opendir(FileName.c_str()))) { return List; } - while ((dentry = readdir(dp)) != nullptr) + while ((dentry = readdir(dp))) { std::string dir = dentry->d_name; if (dir != "." && dir != "..") diff --git a/src/Base/Interpreter.cpp b/src/Base/Interpreter.cpp index 5a476094b7..8fb406aea0 100644 --- a/src/Base/Interpreter.cpp +++ b/src/Base/Interpreter.cpp @@ -170,7 +170,7 @@ SystemExitException::SystemExitException() if (value) { code = PyObject_GetAttrString(value, "code"); - if (code != nullptr && value != Py_None) { + if (code && value != Py_None) { Py_DECREF(value); value = code; } @@ -239,10 +239,10 @@ std::string InterpreterSingleton::runString(const char *sCmd) PyGILStateLocker locker; module = PP_Load_Module("__main__"); /* get module, init python */ - if (module == nullptr) + if (!module) throw PyException(); /* not incref'd */ dict = PyModule_GetDict(module); /* get dict namespace */ - if (dict == nullptr) + if (!dict) throw PyException(); /* not incref'd */ @@ -316,10 +316,10 @@ Py::Object InterpreterSingleton::runStringObject(const char *sCmd) PyGILStateLocker locker; module = PP_Load_Module("__main__"); /* get module, init python */ - if (module == nullptr) + if (!module) throw PyException(); /* not incref'd */ dict = PyModule_GetDict(module); /* get dict namespace */ - if (dict == nullptr) + if (!dict) throw PyException(); /* not incref'd */ @@ -342,7 +342,7 @@ void InterpreterSingleton::systemExit() PyErr_Fetch(&exception, &value, &tb); fflush(stdout); - if (value == nullptr || value == Py_None) + if (!value || value == Py_None) goto done; if (PyExceptionInstance_Check(value)) { /* The error code should be in the `code' attribute. */ @@ -382,10 +382,10 @@ void InterpreterSingleton::runInteractiveString(const char *sCmd) PyGILStateLocker locker; module = PP_Load_Module("__main__"); /* get module, init python */ - if (module == nullptr) + if (!module) throw PyException(); /* not incref'd */ dict = PyModule_GetDict(module); /* get dict namespace */ - if (dict == nullptr) + if (!dict) throw PyException(); /* not incref'd */ presult = PyRun_String(sCmd, Py_single_input, dict, dict); /* eval direct */ @@ -435,20 +435,20 @@ void InterpreterSingleton::runFile(const char*pxFileName, bool local) Py_INCREF(dict); // avoid to further distinguish between local and global dict } - if (PyDict_GetItemString(dict, "__file__") == nullptr) { - PyObject *f = PyUnicode_FromString(pxFileName); - if (f == nullptr) { + if (!PyDict_GetItemString(dict, "__file__")) { + PyObject *pyObj = PyUnicode_FromString(pxFileName); + if (!pyObj) { fclose(fp); Py_DECREF(dict); return; } - if (PyDict_SetItemString(dict, "__file__", f) < 0) { - Py_DECREF(f); + if (PyDict_SetItemString(dict, "__file__", pyObj) < 0) { + Py_DECREF(pyObj); fclose(fp); Py_DECREF(dict); return; } - Py_DECREF(f); + Py_DECREF(pyObj); } PyObject *result = PyRun_File(fp, pxFileName, Py_file_input, dict, dict); @@ -731,7 +731,7 @@ void InterpreterSingleton::runMethod(PyObject *pobject, const char *method, PyGILStateLocker locker; pmeth = PyObject_GetAttrString(pobject, method); - if (pmeth == nullptr) { /* get callable object */ + if (!pmeth) { /* get callable object */ va_end(argslist); throw AttributeError("Error running InterpreterSingleton::RunMethod() method not defined"); /* bound method? has self */ } @@ -739,7 +739,7 @@ void InterpreterSingleton::runMethod(PyObject *pobject, const char *method, pargs = Py_VaBuildValue(argfmt, argslist); /* args: c->python */ va_end(argslist); - if (pargs == nullptr) { + if (!pargs) { Py_DECREF(pmeth); throw TypeError("InterpreterSingleton::RunMethod() wrong arguments"); } @@ -765,10 +765,10 @@ PyObject * InterpreterSingleton::getValue(const char * key, const char * result_ PyGILStateLocker locker; module = PP_Load_Module("__main__"); /* get module, init python */ - if (module == nullptr) + if (!module) throw PyException(); /* not incref'd */ dict = PyModule_GetDict(module); /* get dict namespace */ - if (dict == nullptr) + if (!dict) throw PyException(); /* not incref'd */ diff --git a/src/Base/Parameter.cpp b/src/Base/Parameter.cpp index 98b0bc714d..8840aeb958 100644 --- a/src/Base/Parameter.cpp +++ b/src/Base/Parameter.cpp @@ -390,7 +390,7 @@ std::vector > ParameterGrp::GetGroups(void) /// test if this group is empty bool ParameterGrp::IsEmpty() const { - if ( _pGroupNode->getFirstChild() ) + if (_pGroupNode->getFirstChild()) return false; else return true; @@ -399,10 +399,10 @@ bool ParameterGrp::IsEmpty() const /// test if a special sub group is in this group bool ParameterGrp::HasGroup(const char* Name) const { - if ( _GroupMap.find(Name) != _GroupMap.end() ) + if (_GroupMap.find(Name) != _GroupMap.end()) return true; - if ( FindElement(_pGroupNode,"FCParamGroup",Name) != nullptr ) + if (FindElement(_pGroupNode,"FCParamGroup",Name)) return true; return false; diff --git a/src/Base/PyObjectBase.cpp b/src/Base/PyObjectBase.cpp index a8e1b32780..05811bdfcc 100644 --- a/src/Base/PyObjectBase.cpp +++ b/src/Base/PyObjectBase.cpp @@ -107,7 +107,7 @@ static void PyBaseProxy_dealloc(PyObject* self) { /* Clear weakrefs first before calling any destructors */ - if (reinterpret_cast(self)->weakreflist != nullptr) + if (reinterpret_cast(self)->weakreflist) PyObject_ClearWeakRefs(self); Py_TYPE(self)->tp_free(self); } @@ -413,7 +413,7 @@ PyObject *PyObjectBase::_getattr(const char *attr) // As fallback solution use Python's default method to get generic attributes PyObject *w, *res; w = PyUnicode_InternFromString(attr); - if (w != nullptr) { + if (w) { res = PyObject_GenericGetAttr(this, w); Py_XDECREF(w); return res; @@ -433,7 +433,7 @@ int PyObjectBase::_setattr(const char *attr, PyObject *value) PyObject *w; // As fallback solution use Python's default method to get generic attributes w = PyUnicode_InternFromString(attr); // new reference - if (w != nullptr) { + if (w) { // call methods from tp_getset if defined int res = PyObject_GenericSetAttr(this, w, value); Py_DECREF(w); diff --git a/src/Base/gzstream.cpp b/src/Base/gzstream.cpp index 3236c124ed..85f7e3fdd2 100644 --- a/src/Base/gzstream.cpp +++ b/src/Base/gzstream.cpp @@ -67,7 +67,7 @@ gzstreambuf* gzstreambuf::open( const char* name, int open_mode, int comp) *fmodeptr++ = 'b'; *fmodeptr = '\0'; file = gzopen( name, fmode); - if (file == nullptr) + if (!file) return (gzstreambuf*)nullptr; opened = 1; return this; diff --git a/src/Base/swigpyrun.inl b/src/Base/swigpyrun.inl index 172198820d..42f9308b85 100644 --- a/src/Base/swigpyrun.inl +++ b/src/Base/swigpyrun.inl @@ -35,8 +35,8 @@ int createSWIGPointerObj_T(const char* TypeName, void* obj, PyObject** ptr, int throw Base::RuntimeError(str.str()); } - *ptr = SWIG_NewPointerObj(obj,swig_type,own); - if (*ptr == nullptr) + *ptr = SWIG_NewPointerObj(obj, swig_type, own); + if (!*ptr) throw Base::RuntimeError("Cannot convert into requested type"); // success @@ -77,13 +77,13 @@ void cleanupSWIG_T(const char* TypeName) PyObject *module, *dict; PyObject *modules = PyImport_GetModuleDict(); module = PyDict_GetItemString(modules, "__builtin__"); - if (module != nullptr && PyModule_Check(module)) { + if (module && PyModule_Check(module)) { dict = PyModule_GetDict(module); PyDict_SetItemString(dict, "_", Py_None); } module = PyDict_GetItemString(modules, "__main__"); - if (module != nullptr && PyModule_Check(module)) { + if (module && PyModule_Check(module)) { PyObject* dict = PyModule_GetDict(module); if (!dict) return;