[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

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