[Base] remove superfluous nullptr checks

This commit is contained in:
Uwe
2022-07-18 03:16:22 +02:00
parent e69a920f18
commit 4b2ffd2eca
9 changed files with 36 additions and 36 deletions

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -619,12 +619,12 @@ std::vector<Base::FileInfo> 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 != "..")

View File

@@ -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 */

View File

@@ -390,7 +390,7 @@ std::vector<Base::Reference<ParameterGrp> > 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;

View File

@@ -107,7 +107,7 @@ static void
PyBaseProxy_dealloc(PyObject* self)
{
/* Clear weakrefs first before calling any destructors */
if (reinterpret_cast<PyBaseProxy*>(self)->weakreflist != nullptr)
if (reinterpret_cast<PyBaseProxy*>(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);

View File

@@ -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;

View File

@@ -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;