diff --git a/idapython.cpp b/idapython.cpp index 5ef96b2..84180ea 100644 --- a/idapython.cpp +++ b/idapython.cpp @@ -701,7 +701,7 @@ void convert_idc_args() // Get reference to the IDC module (it is imported by init.py) ref_t py_mod(PyW_TryImportModule(S_IDC_MODNAME)); - if ( py_mod != nullptr ) + if ( py_mod ) PyObject_SetAttrString(py_mod.o, S_IDC_ARGS_VARNAME, py_args.o); } @@ -1129,8 +1129,7 @@ ref_t idapython_plugin_t::get_sys_displayhook() ref_t h; if ( config.repl_use_sys_displayhook ) { - ref_t py_sys(PyW_TryImportModule("sys")); - if ( py_sys != nullptr ) + if ( ref_t py_sys = ref_t(PyW_TryImportModule("sys")) ) h = PyW_TryGetAttrString(py_sys.o, "displayhook"); } return h; @@ -1425,7 +1424,7 @@ bool idapython_plugin_t::_extlang_create_object( // Get a reference to the module ref_t py_mod(PyW_TryImportModule(modname)); - if ( py_mod == nullptr ) + if ( !py_mod ) { errbuf->sprnt("Could not import module '%s'!", modname); break; @@ -1435,7 +1434,7 @@ bool idapython_plugin_t::_extlang_create_object( ref_t py_res; if ( nargs == 1 && args[0].vtype == VT_PVOID ) py_res = try_create_swig_wrapper(py_mod, clsname, args[0].pvoid); - if ( py_res != nullptr ) + if ( py_res ) { PyObject_SetAttrString(py_res.o, S_PY_IDCCVT_ID_ATTR, PyLong_FromLong(PY_ICID_OPAQUE)); } @@ -1443,7 +1442,7 @@ bool idapython_plugin_t::_extlang_create_object( { // Get the class reference ref_t py_cls(PyW_TryGetAttrString(py_mod.o, clsname)); - if ( py_cls == nullptr ) + if ( !py_cls ) { errbuf->sprnt("Could not find class type '%s'!", clsname); break; @@ -1491,7 +1490,7 @@ bool idapython_plugin_t::_extlang_eval_snippet( globals, globals, nullptr)); - ok = result != nullptr && !PyErr_Occurred(); //-V560 is always true: !PyErr_Occurred() + ok = result && !PyErr_Occurred(); //-V560 is always true: !PyErr_Occurred() if ( !ok ) handle_python_error(errbuf); } @@ -1612,7 +1611,7 @@ bool idapython_plugin_t::_extlang_call_method( } ref_t py_method(PyW_TryGetAttrString(py_obj.o, method_name)); - if ( py_method == nullptr || !PyCallable_Check(py_method.o) ) + if ( !py_method || !PyCallable_Check(py_method.o) ) { errbuf->sprnt("The input object does not have a callable method called '%s'", method_name); break; @@ -1624,8 +1623,7 @@ bool idapython_plugin_t::_extlang_call_method( // to be converted to an unsigned python long if ( streq(method_name, "run") ) { - ref_t py_ida_idaapi_mod(PyW_TryImportModule(S_IDA_IDAAPI_MODNAME)); - if ( py_ida_idaapi_mod != nullptr ) + if ( ref_t py_ida_idaapi_mod = ref_t(PyW_TryImportModule(S_IDA_IDAAPI_MODNAME)) ) { if ( is_instance_of(py_obj.o, py_ida_idaapi_mod.o, "plugin_t") || is_instance_of(py_obj.o, py_ida_idaapi_mod.o, "plugmod_t") ) @@ -1661,14 +1659,14 @@ bool idapython_plugin_t::_extlang_get_attr( { // Get a reference to the module ref_t py_mod(PyW_TryImportModule(S_MAIN)); - if ( py_mod == nullptr ) + if ( !py_mod ) break; // Object specified: // - (1) string contain attribute name in the main module // - (2) opaque object (we use it as is) ref_t py_obj; - if ( obj != nullptr ) + if ( obj ) { // (1) Get attribute from main module if ( obj->vtype == VT_STR ) @@ -1688,7 +1686,7 @@ bool idapython_plugin_t::_extlang_get_attr( } } // Get the attribute reference - if ( py_obj == nullptr ) + if ( !py_obj ) break; } // No object specified: @@ -1704,17 +1702,17 @@ bool idapython_plugin_t::_extlang_get_attr( cvt = CIP_FAILED; // Get the class newref_t cls(PyObject_GetAttrString(py_obj.o, "__class__")); - if ( cls == nullptr ) + if ( !cls ) break; // Get its name newref_t name(PyObject_GetAttrString(cls.o, "__name__")); - if ( name == nullptr ) + if ( !name ) break; // Convert name object to string object newref_t string(PyObject_Str(name.o)); - if ( string == nullptr ) + if ( !string ) break; // Convert name python string to a C string @@ -1729,7 +1727,7 @@ bool idapython_plugin_t::_extlang_get_attr( ref_t py_attr(PyW_TryGetAttrString(py_obj.o, attr)); // No attribute? - if ( py_attr == nullptr ) + if ( !py_attr ) { cvt = CIP_FAILED; break; @@ -1773,7 +1771,7 @@ bool idapython_plugin_t::_extlang_set_attr( { // Get a reference to the module ref_t py_mod(PyW_TryImportModule(S_MAIN)); - if ( py_mod == nullptr ) + if ( !py_mod ) break; ref_t py_obj; if ( obj != nullptr ) @@ -1790,7 +1788,7 @@ bool idapython_plugin_t::_extlang_set_attr( py_obj = ref_t(); } // No object to set_attr on? - if ( py_obj == nullptr ) + if ( !py_obj ) break; } else @@ -1860,7 +1858,7 @@ bool idapython_plugin_t::_cli_execute_line(const char *line) // Compile as an expression qstring qstr(line); newref_t py_code(my_CompileString(insert_encoding_cookie(&qstr), "", Py_eval_input)); - if ( py_code == nullptr || PyErr_Occurred() ) + if ( !py_code || PyErr_Occurred() ) { // Not an expression? PyErr_Clear(); @@ -1873,7 +1871,7 @@ bool idapython_plugin_t::_cli_execute_line(const char *line) PyObject *py_globals = _get_module_globals(); newref_t py_result(PyEval_EvalCode(py_code.o, py_globals, py_globals)); - if ( py_result == nullptr || PyErr_Occurred() ) //-V560 is always false: PyErr_Occurred() + if ( !py_result || PyErr_Occurred() ) //-V560 is always false: PyErr_Occurred() { PyErr_Print(); } @@ -1923,7 +1921,7 @@ bool idapython_plugin_t::_cli_find_completions( PYW_GIL_GET; ref_t py_fc(get_idaapi_attr(S_IDAAPI_FINDCOMPLETIONS)); - if ( py_fc == nullptr ) + if ( !py_fc ) return false; newref_t py_res(PyObject_CallFunction(py_fc.o, "si", line, x)); //lint !e605 !e1776 @@ -1952,7 +1950,7 @@ bool idapython_plugin_t::_handle_file( { PYW_GIL_CHECK_LOCKED_SCOPE(); ref_t py_executor_func(get_idaapi_attr(idaapi_executor_func_name)); - if ( py_executor_func == nullptr ) + if ( !py_executor_func ) { errbuf->sprnt("Could not find %s.%s ?!", S_IDA_IDAAPI_MODNAME, idaapi_executor_func_name); return false; @@ -1985,7 +1983,7 @@ bool idapython_plugin_t::_handle_file( // Failure at this point means the script was interrupted bool interrupted = false; - if ( PyW_GetError(errbuf) || py_ret == nullptr ) + if ( PyW_GetError(errbuf) || !py_ret ) { PyErr_Clear(); if ( errbuf->empty() ) @@ -2087,7 +2085,7 @@ bool idapython_plugin_t::_check_python_dir() void idapython_plugin_t::_prepare_sys_path() { borref_t path(PySys_GetObject((char *) "path")); - if ( path == nullptr || !PySequence_Check(path.o) ) + if ( !path || !PySequence_Check(path.o) ) return; qstring new_path; @@ -2098,7 +2096,7 @@ void idapython_plugin_t::_prepare_sys_path() { qstring path_el_utf8; newref_t path_el(PySequence_GetItem(path.o, i)); - if ( path_el != nullptr + if ( path_el && PyUnicode_Check(path_el.o) && PyUnicode_as_qstring(&path_el_utf8, path_el.o) ) { @@ -2161,11 +2159,11 @@ bool idapython_plugin_t::_run_init_py() contents.resize(effsz); newref_t code(my_CompileString(contents.c_str(), path, Py_file_input)); - if ( code == nullptr ) + if ( !code ) return false; newref_t result(PyEval_EvalCode(code.o, __main__globals, __main__globals)); - return result != nullptr && !PyErr_Occurred(); + return result && !PyErr_Occurred(); } //------------------------------------------------------------------------ diff --git a/pywraps.cpp b/pywraps.cpp index 5c8b645..d036cab 100644 --- a/pywraps.cpp +++ b/pywraps.cpp @@ -137,7 +137,7 @@ static Py_ssize_t pyvar_walk_list( py_item = newref_t(PySequence_GetItem(o, i)); else py_item = borref_t(PyList_GetItem(o, i)); - bool ok = py_item != nullptr && cb(py_item, i, ud) == CIP_OK; + bool ok = py_item && cb(py_item, i, ud) == CIP_OK; if ( ok ) { // We cannot have, at the same time, a 'successful conversion', and @@ -326,7 +326,7 @@ static void free_compiled_form_instances(void) msg("WARNING: Form \"%s\" was not Free()d. Force-freeing.\n", title.c_str()); // Will call 'py_unregister_compiled_form()', and thus trim the vector down. newref_t result(PyObject_CallMethod(ref.o, (char *)"Free", "()")); - if ( result == nullptr && PyErr_Occurred() != nullptr ) + if ( !result && PyErr_Occurred() != nullptr ) { msg("WARNING: Couldn't free form object at %p:\n", ref.o); PyErr_Print(); @@ -655,7 +655,7 @@ static int pyvar_to_idcvar2( { newref_t py_dir(PyObject_Dir(py_var.o)); Py_ssize_t size = PyList_Size(py_dir.o); - if ( py_dir == nullptr || !PyList_Check(py_dir.o) || size == 0 ) + if ( !py_dir || !PyList_Check(py_dir.o) || size == 0 ) return CIP_FAILED; // Create the IDC object idcv_object(idc_var); @@ -680,7 +680,7 @@ static int pyvar_to_idcvar2( idc_value_t v; newref_t attr(PyObject_GetAttrString(py_var.o, field_name)); - if ( attr == nullptr ) + if ( !attr ) return CIP_FAILED; else if ( pyvar_to_idcvar1(attr, &v, gvar_sn, visited) < CIP_OK ) return CIP_FAILED; @@ -763,7 +763,7 @@ int ida_export idcvar_to_pyvar( else { // Recycle? - if ( *py_var != nullptr ) + if ( *py_var ) { // Recycling an int64 object? if ( !is_pyidc_cvt_type_int64(py_var->o) ) @@ -776,7 +776,7 @@ int ida_export idcvar_to_pyvar( if ( py_cls == nullptr ) return CIP_FAILED; *py_var = newref_t(PyObject_CallFunctionObjArgs(py_cls.o, PyLong_FromLongLong(idc_var.i64), nullptr)); - if ( PyW_GetError() || *py_var == nullptr ) + if ( PyW_GetError() || !*py_var ) return CIP_FAILED; } break; @@ -796,7 +796,7 @@ int ida_export idcvar_to_pyvar( return CIP_IMMUTABLE; // Cannot recycle immutable object case VT_LONG: // Cannot recycle immutable objects - if ( *py_var != nullptr ) + if ( *py_var ) { // Recycling an int64 object? if ( !is_pyidc_cvt_type_int64(py_var->o) ) @@ -808,7 +808,7 @@ int ida_export idcvar_to_pyvar( *py_var = newref_t(cvt_to_pylong(idc_var.num)); break; case VT_FLOAT: - if ( *py_var == nullptr ) + if ( !*py_var ) { double x; if ( processor_t::realcvt(&x, (fpvalue_t*)&idc_var.e, (sizeof(x)/2-1)|010) != 1 ) @@ -822,7 +822,7 @@ int ida_export idcvar_to_pyvar( case VT_REF: { - if ( *py_var == nullptr ) + if ( !*py_var ) { ref_t py_cls(get_idaapi_attr_by_id(PY_CLSID_CVT_BYREF)); if ( py_cls == nullptr ) @@ -830,7 +830,7 @@ int ida_export idcvar_to_pyvar( // Create a byref object with None value. We populate it later *py_var = newref_t(PyObject_CallFunctionObjArgs(py_cls.o, Py_None, nullptr)); - if ( PyW_GetError() || *py_var == nullptr ) + if ( PyW_GetError() || !*py_var ) return CIP_FAILED; } int t = get_pyidc_cvt_type(py_var->o); @@ -892,7 +892,7 @@ int ida_export idcvar_to_pyvar( // Call constructor obj = newref_t(PyObject_CallFunctionObjArgs(py_cls.o, nullptr)); - if ( PyW_GetError() || obj == nullptr ) + if ( PyW_GetError() || !obj ) return CIP_FAILED; } else @@ -1146,16 +1146,14 @@ ref_t ida_export create_linked_class_instance( void *lnk) { PYW_GIL_CHECK_LOCKED_SCOPE(); - newref_t py_module(PyImport_ImportModule(modname)); ref_t result; - if ( py_module != nullptr ) + if ( newref_t py_module = newref_t(PyImport_ImportModule(modname)) ) { - ref_t py_class = PyW_TryGetAttrString(py_module.o, clsname); - if ( py_class != nullptr ) + if ( ref_t py_class = ref_t(PyW_TryGetAttrString(py_module.o, clsname)) ) { newref_t py_lnk(PyCapsule_New(lnk, VALID_CAPSULE_NAME, nullptr)); ref_t py_obj = newref_t(PyObject_CallFunctionObjArgs(py_class.o, py_lnk.o, nullptr)); - if ( !PyW_GetError() && py_obj != nullptr ) + if ( !PyW_GetError() && py_obj ) result = py_obj; } } @@ -1224,7 +1222,7 @@ ref_t ida_export PyW_TryImportModule(const char *name) { PYW_GIL_CHECK_LOCKED_SCOPE(); newref_t result(PyImport_ImportModule(name)); - if ( result == nullptr && PyErr_Occurred() != nullptr ) + if ( !result && PyErr_Occurred() != nullptr ) PyErr_Clear(); return result; } @@ -1314,7 +1312,7 @@ bool ida_export PyW_GetNumber(PyObject *py_var, uint64 *num, bool *is_64) { newref_t py_mask(Py_BuildValue("K", 0xFFFFFFFFFFFFFFFFull)); newref_t py_num(PyNumber_And(py_var, py_mask.o)); - if ( py_num != nullptr && py_mask != nullptr ) + if ( py_num && py_mask ) { PyErr_Clear(); ull = PyLong_AsUnsignedLongLong(py_num.o); @@ -1362,7 +1360,7 @@ bool ida_export PyW_ObjectToString(PyObject *obj, qstring *out) { PYW_GIL_CHECK_LOCKED_SCOPE(); newref_t py_str(PyObject_Str(obj)); - bool ok = py_str != nullptr; + bool ok = py_str; if ( ok ) PyUnicode_as_qstring(out, py_str.o); else @@ -1400,10 +1398,10 @@ bool ida_export PyW_GetError(qstring *out, bool clear_err) } // and fallback to simple stringification if needed - if ( py_ret == nullptr ) + if ( !py_ret ) py_ret = newref_t(PyObject_Str(err_value)); - if ( py_ret != nullptr ) + if ( py_ret ) PyUnicode_as_qstring(out, py_ret.o); else *out = "IDAPython: unknown error"; @@ -1544,10 +1542,10 @@ PyObject *ida_export py_customidamemo_t_create_groups( if ( !PyDict_Check(item.o) ) continue; borref_t nodes(PyDict_GetItemString(item.o, "nodes")); - if ( nodes.o == nullptr || !PySequence_Check(nodes.o) ) + if ( !nodes || !PySequence_Check(nodes.o) ) continue; borref_t text(PyDict_GetItemString(item.o, "text")); - if ( text.o == nullptr || !PyUnicode_Check(text.o) ) + if ( !text || !PyUnicode_Check(text.o) ) continue; group_crinfo_t gi; Py_ssize_t nodes_cnt = PySequence_Size(nodes.o); @@ -1825,18 +1823,16 @@ ref_t ida_export try_create_swig_wrapper(ref_t mod, const char *clsname, void *c ssize_t ida_export get_callable_arg_count(ref_t callable) { PYW_GIL_CHECK_LOCKED_SCOPE(); - newref_t py_module(PyImport_ImportModule("inspect")); ssize_t cnt = -1; - if ( py_module != nullptr ) + if ( newref_t py_module = newref_t(PyImport_ImportModule("inspect")) ) { - ref_t py_fun = PyW_TryGetAttrString(py_module.o, "getfullargspec"); - if ( py_fun != nullptr ) + if ( ref_t py_fun = ref_t(PyW_TryGetAttrString(py_module.o, "getfullargspec")) ) { newref_t py_tuple(PyObject_CallFunctionObjArgs(py_fun.o, callable.o, nullptr)); - if ( py_tuple != nullptr && PyTuple_Check(py_tuple.o) ) + if ( py_tuple && PyTuple_Check(py_tuple.o) ) { borref_t py_args(PyTuple_GetItem(py_tuple.o, 0)); - if ( py_args != nullptr && PySequence_Check(py_args.o) ) + if ( py_args && PySequence_Check(py_args.o) ) cnt = PySequence_Length(py_args.o); } } diff --git a/pywraps.hpp b/pywraps.hpp index b713c68..719458b 100644 --- a/pywraps.hpp +++ b/pywraps.hpp @@ -326,7 +326,7 @@ struct ref_t bool operator==(const ref_t &other) const { return o == other.o; } bool operator!=(const ref_t &other) const { return !((*this) == other); } - explicit operator bool() const { return o != nullptr; } + operator bool() const { return o != nullptr; } }; //------------------------------------------------------------------------- @@ -1200,9 +1200,9 @@ protected: ref_t py_id; if ( PyObject_HasAttrString(self, "id") ) py_id = newref_t(PyObject_GetAttrString(self, "id")); - if ( py_id == nullptr || !PyUnicode_Check(py_id.o) ) + if ( !py_id || !PyUnicode_Check(py_id.o) ) py_id = newref_t(PyObject_Repr(self)); - if ( py_id != nullptr && PyUnicode_Check(py_id.o) ) + if ( !py_id && PyUnicode_Check(py_id.o) ) PyUnicode_as_qstring(&identifier, py_id.o); } @@ -1215,16 +1215,16 @@ protected: *p++ = '\0'; newref_t py_mod(PyImport_ImportModule(buf.c_str())); #ifdef TESTABLE_BUILD - QASSERT(30591, py_mod != nullptr); + QASSERT(30591, py_mod); #endif - if ( py_mod != nullptr ) + if ( py_mod ) { newref_t py_def_class(PyObject_GetAttrString(py_mod.o, p)); newref_t py_this_class(PyObject_GetAttrString(self, "__class__")); #ifdef TESTABLE_BUILD - QASSERT(30592, py_def_class != nullptr && py_this_class != nullptr); + QASSERT(30592, py_def_class && py_this_class); #endif - if ( py_def_class != nullptr && py_this_class != nullptr ) + if ( py_def_class && py_this_class ) { for ( size_t i = 0; i < count; ++i ) { @@ -1233,9 +1233,9 @@ protected: newref_t py_def_meth(PyObject_GetAttrString(py_def_class.o, cur.method_name)); newref_t py_this_meth(PyObject_GetAttrString(py_this_class.o, cur.method_name)); #ifdef TESTABLE_BUILD - QASSERT(30593, py_def_meth != nullptr && py_this_meth != nullptr); + QASSERT(30593, py_def_meth && py_this_meth); #endif - if ( py_def_meth != nullptr && py_this_meth != nullptr ) + if ( py_def_meth && py_this_meth ) { if ( PyObject_HasAttrString(py_def_meth.o, "__trampoline") > 0 ) _has_nondef = 2; @@ -1256,7 +1256,7 @@ protected: if ( PyObject_HasAttrString(self, "__class__") ) { newref_t py_this_class(PyObject_GetAttrString(self, "__class__")); - if ( py_this_class != nullptr + if ( py_this_class && PyObject_HasAttrString(py_this_class.o, forbidden_method_name) ) { msg("WARNING: The method \"%s::%s\" won't be called (it has been replaced with \"%s::%s\")\n", @@ -1270,9 +1270,9 @@ protected: size_t mappings_size, bool assert_all_reimplemented) const { - qstrvec_t missing_reimpls; qstring buf; #ifdef TESTABLE_BUILD + qstrvec_t missing_reimpls; buf.sprnt("%s(this=%p) \"%s\" {type=%d, cb=%p, flags=%x}", class_name, this, identifier.c_str(), int(type), listener.cb, flags); if ( has_fixed_method_set() ) @@ -1323,6 +1323,7 @@ protected: #else qnotused(mappings); qnotused(mappings_size); + qnotused(assert_all_reimplemented); #endif return PyUnicode_from_qstring(buf); } diff --git a/pywraps/py_bytes.hpp b/pywraps/py_bytes.hpp index 58173c6..a27b0db 100644 --- a/pywraps/py_bytes.hpp +++ b/pywraps/py_bytes.hpp @@ -21,7 +21,7 @@ static int idaapi py_visit_patched_bytes_cb( o, v)); PyW_ShowCbErr("visit_patched_bytes"); - return (py_result != nullptr && PyLong_Check(py_result.o)) ? PyLong_AsLong(py_result.o) : 0; + return (py_result && PyLong_Check(py_result.o)) ? PyLong_AsLong(py_result.o) : 0; } //------------------------------------------------------------------------- @@ -53,7 +53,7 @@ static bool py_do_get_bytes( // Allocate memory via Python newref_t py_bytes(PyBytes_FromStringAndSize(nullptr, Py_ssize_t(size))); - if ( py_bytes == nullptr ) + if ( !py_bytes ) break; bytevec_t mask; @@ -75,7 +75,7 @@ static bool py_do_get_bytes( newref_t py_mask(PyBytes_FromStringAndSize( (const char *) mask.begin(), mask.size())); - if ( py_mask == nullptr ) + if ( !py_mask ) break; py_mask.incref(); *out_py_mask = py_mask.o; diff --git a/pywraps/py_bytes_custdata.hpp b/pywraps/py_bytes_custdata.hpp index e132cf7..0af400a 100644 --- a/pywraps/py_bytes_custdata.hpp +++ b/pywraps/py_bytes_custdata.hpp @@ -31,7 +31,7 @@ class py_custom_data_type_t : public data_type_t bvsz_t(nbytes))); PyW_ShowCbErr(S_MAY_CREATE_AT); - return py_result != nullptr && PyObject_IsTrue(py_result.o); + return py_result && PyObject_IsTrue(py_result.o); } // !=nullptr means variable size datatype @@ -54,7 +54,7 @@ class py_custom_data_type_t : public data_type_t bvea_t(ea), bvasize_t(maxsize))); - if ( PyW_ShowCbErr(S_CALC_ITEM_SIZE) || py_result == nullptr ) + if ( PyW_ShowCbErr(S_CALC_ITEM_SIZE) || !py_result ) return 0; uint64 num = 0; @@ -191,7 +191,7 @@ private: newref_t py_value(PyBytes_FromStringAndSize( (const char *)value, Py_ssize_t(size))); - if ( py_value == nullptr ) + if ( !py_value ) return false; py_custom_data_format_t *_this = (py_custom_data_format_t *) ud; @@ -205,7 +205,7 @@ private: dtid)); // Error while calling the function? - if ( PyW_ShowCbErr(S_PRINTF) || py_result == nullptr ) + if ( PyW_ShowCbErr(S_PRINTF) || !py_result ) return false; bool ok = false; @@ -239,7 +239,7 @@ private: operand_num)); // Error while calling the function? - if ( PyW_ShowCbErr(S_SCAN) || py_result == nullptr ) + if ( PyW_ShowCbErr(S_SCAN) || !py_result ) return false; bool ok = false; diff --git a/pywraps/py_diskio.hpp b/pywraps/py_diskio.hpp index 87fcc93..0b6ee53 100644 --- a/pywraps/py_diskio.hpp +++ b/pywraps/py_diskio.hpp @@ -15,7 +15,7 @@ int idaapi py_enumerate_files_cb(const char *file, void *ud) (PyObject *)ud, py_file.o, nullptr)); - return (py_ret == nullptr || !PyNumber_Check(py_ret.o)) ? 1 /* stop enum on failure */ : PyInt_AsLong(py_ret.o); + return (!py_ret || !PyNumber_Check(py_ret.o)) ? 1 /* stop enum on failure */ : PyInt_AsLong(py_ret.o); } //------------------------------------------------------------------------- diff --git a/pywraps/py_graph.hpp b/pywraps/py_graph.hpp index c5c28a2..5b16642 100644 --- a/pywraps/py_graph.hpp +++ b/pywraps/py_graph.hpp @@ -120,7 +120,7 @@ private: "i", item2->n)); PyW_ShowCbErr(S_ON_CLICK); - return result == nullptr || !PyObject_IsTrue(result.o); + return !result || !PyObject_IsTrue(result.o); } // a graph node has been double clicked @@ -139,13 +139,13 @@ private: "i", item->node)); PyW_ShowCbErr(S_ON_DBL_CLICK); - return result == nullptr || !PyObject_IsTrue(result.o); + return !result || !PyObject_IsTrue(result.o); } // a graph viewer got focus void on_gotfocus(graph_viewer_t * /*view*/) { - if ( self.o == nullptr ) + if ( !self ) return; PYW_GIL_CHECK_LOCKED_SCOPE(); @@ -160,7 +160,7 @@ private: // a graph viewer lost focus void on_lostfocus(graph_viewer_t * /*view*/) { - if ( self.o == nullptr ) + if ( !self ) return; PYW_GIL_CHECK_LOCKED_SCOPE(); @@ -188,7 +188,7 @@ private: "O", py_nodes.o)); PyW_ShowCbErr(S_ON_CREATING_GROUP); - return (py_result == nullptr || !PyLong_Check(py_result.o)) + return (!py_result || !PyLong_Check(py_result.o)) ? 1 : PyLong_AsLong(py_result.o); } @@ -416,7 +416,7 @@ void py_graph_t::on_user_refresh(mutable_graph_t *g) for ( j=0; j < qnumber(edge_ids); j++ ) { newref_t id(PySequence_GetItem(item.o, j)); - if ( id == nullptr || !PyLong_Check(id.o) ) + if ( !id || !PyLong_Check(id.o) ) break; int v = int(PyLong_AsLong(id.o)); if ( v > max_nodes ) @@ -453,7 +453,7 @@ bool py_graph_t::on_user_text(mutable_graph_t * /*g*/, int node, const char **st PYW_GIL_CHECK_LOCKED_SCOPE(); newref_t result(PyObject_CallMethod(self.o, (char *)S_ON_GETTEXT, "i", node)); PyW_ShowCbErr(S_ON_GETTEXT); - if ( result == nullptr ) + if ( !result ) return false; bgcolor_t cl = bg_color == nullptr ? DEFCOLOR : *bg_color; @@ -472,9 +472,9 @@ bool py_graph_t::on_user_text(mutable_graph_t * /*g*/, int node, const char **st newref_t py_str(PySequence_GetItem(result.o, 0)); newref_t py_color(PySequence_GetItem(result.o, 1)); - if ( py_str != nullptr && PyUnicode_Check(py_str.o) ) + if ( py_str && PyUnicode_Check(py_str.o) ) PyUnicode_as_qstring(&buf, py_str.o); - if ( py_color != nullptr && PyNumber_Check(py_color.o) ) + if ( py_color && PyNumber_Check(py_color.o) ) cl = bgcolor_t(PyLong_AsUnsignedLong(py_color.o)); c = node_cache.add(node, buf.c_str(), cl); diff --git a/pywraps/py_idaapi.hpp.in b/pywraps/py_idaapi.hpp.in index 8a2dbf3..1835744 100644 --- a/pywraps/py_idaapi.hpp.in +++ b/pywraps/py_idaapi.hpp.in @@ -76,11 +76,10 @@ void pycim_view_close(PyObject *self) //------------------------------------------------------------------------- static void _ida_idaapi_notify_init_term(int what) { - newref_t py_mod(PyImport_ImportModule("ida_idaapi")); - if ( py_mod != nullptr ) + if ( newref_t py_mod = newref_t(PyImport_ImportModule("ida_idaapi")) ) { newref_t py_obj(PyObject_GetAttrString(py_mod.o, NOTIFY_DISPATCHER_INSTANCE)); - if ( py_obj != nullptr && py_obj.o != Py_None ) + if ( py_obj && py_obj.o != Py_None ) PyObject_CallMethod(py_obj.o, NOTIFY_DISPATCHER_DISPATCH_METHOD, "i", what); } } diff --git a/pywraps/py_kernwin.hpp b/pywraps/py_kernwin.hpp index 176388d..09f9d14 100644 --- a/pywraps/py_kernwin.hpp +++ b/pywraps/py_kernwin.hpp @@ -70,7 +70,7 @@ static PyObject *py_register_timer(int interval, PyObject *py_callback) msg("Exception in timer callback. This timer will be unregistered.\n"); PyErr_Print(); } - else if ( py_result != nullptr ) + else if ( py_result ) { ret = PyLong_AsLong(py_result.o); } @@ -588,7 +588,7 @@ static int py_execute_sync(PyObject *py_callable, int reqf) { PYW_GIL_GET; newref_t py_result(PyObject_CallFunctionObjArgs(py_callable.o, nullptr)); - int ret = py_result == nullptr || !PyLong_Check(py_result.o) + int ret = !py_result || !PyLong_Check(py_result.o) ? -1 : PyLong_AsLong(py_result.o); // if the requesting thread decided not to wait for the request to @@ -771,59 +771,61 @@ public: PyObject *get_dict() { - newref_t json_module(PyImport_ImportModule("json")); - if ( json_module != nullptr ) + do { + newref_t json_module(PyImport_ImportModule("json")); + if ( !json_module ) + break; borref_t json_globals(PyModule_GetDict(json_module.o)); - if ( json_globals != nullptr ) + if ( !json_globals ) + break; + borref_t json_loads(PyDict_GetItemString(json_globals.o, "loads")); + if ( !json_loads ) + break; + + qstring clob; + if (!serialize_json(&clob, o)) + break; + + if ( newref_t dict = newref_t(PyObject_CallFunction(json_loads.o, "s", clob.c_str())) ) { - borref_t json_loads(PyDict_GetItemString(json_globals.o, "loads")); - if ( json_loads != nullptr ) - { - qstring clob; - if ( serialize_json(&clob, o) ) - { - newref_t dict(PyObject_CallFunction(json_loads.o, "s", clob.c_str())); - if ( dict != nullptr ) - { - dict.incref(); - return dict.o; - } - } - } + dict.incref(); + return dict.o; } - } + + } while ( false ); Py_RETURN_NONE; } static bool fill_jobj_from_dict(jobj_t *out, PyObject *dict) { - if ( PyDict_Check(dict) ) + do { + if ( !PyDict_Check(dict) ) + break; newref_t json_module(PyImport_ImportModule("json")); - if ( json_module != nullptr ) + if ( !json_module ) + break; + borref_t json_globals(PyModule_GetDict(json_module.o)); + if ( !json_globals ) + break; + + borref_t json_dumps(PyDict_GetItemString(json_globals.o, "dumps")); + if ( !json_dumps ) + break; + + newref_t str(PyObject_CallFunction(json_dumps.o, "O", dict)); + qstring buf; + if (PyUnicode_as_qstring(&buf, str.o)) { - borref_t json_globals(PyModule_GetDict(json_module.o)); - if ( json_globals != nullptr ) + jvalue_t tmp; + if (parse_json_string(&tmp, buf.c_str()) == eOk) { - borref_t json_dumps(PyDict_GetItemString(json_globals.o, "dumps")); - if ( json_dumps != nullptr ) - { - newref_t str(PyObject_CallFunction(json_dumps.o, "O", dict)); - qstring buf; - if ( PyUnicode_as_qstring(&buf, str.o) ) - { - jvalue_t tmp; - if ( parse_json_string(&tmp, buf.c_str()) == eOk ) - { - out->swap(tmp.obj()); - return true; - } - } - } + out->swap(tmp.obj()); + return true; } } - } + } while ( false ); return false; } }; @@ -873,13 +875,13 @@ private: { borref_t el0(PyTuple_GetItem(o, 0)); qstring plug_hint; - if ( el0 != nullptr + if ( el0 && PyUnicode_Check(el0.o) && PyUnicode_as_qstring(&plug_hint, el0.o) && !plug_hint.empty() ) { borref_t el1(PyTuple_GetItem(o, 1)); - if ( el1 != nullptr && PyLong_Check(el1.o) ) + if ( el1 && PyLong_Check(el1.o) ) { long lns = PyLong_AsLong(el1.o); if ( lns > 0 ) @@ -1109,7 +1111,7 @@ PyObject *py_set_nav_colorizer(PyObject *new_py_colorizer) { PYW_GIL_GET; - if ( py_colorizer == nullptr ) // Shouldn't happen. + if ( !py_colorizer ) // Shouldn't happen. return 0; newref_t pyres = PyObject_CallFunction( py_colorizer.o, "KK", @@ -1117,7 +1119,7 @@ PyObject *py_set_nav_colorizer(PyObject *new_py_colorizer) (unsigned long long) nbytes); PyW_ShowCbErr("nav_colorizer"); uint32 rc = 0; - bool ok = pyres.o != nullptr && PyLong_Check(pyres.o); + bool ok = pyres && PyLong_Check(pyres.o); if ( ok ) { int overflow = 0; @@ -1188,7 +1190,7 @@ uint32 py_call_nav_colorizer( return 0; borref_t py_fun(PyDict_GetItemString(dict, "fun")); borref_t py_ud(PyDict_GetItemString(dict, "ud")); - if ( py_fun == nullptr + if ( py_fun || !PyCapsule_IsValid(py_fun.o, VALID_CAPSULE_NAME) || !PyCapsule_IsValid(py_ud.o, VALID_CAPSULE_NAME) ) { @@ -1364,7 +1366,7 @@ static void py_ss_restore_callback(const char *err_msg, void *userdata) Py_DECREF(o); // We cannot raise an exception in the callback, just print it. - if ( result == nullptr ) + if ( !result ) PyErr_Print(); } @@ -1372,7 +1374,7 @@ static void py_ss_restore_callback(const char *err_msg, void *userdata) # def get_navband_pixel(ea): """ - Maps an address, onto a pixel coordinate within the navband + Maps an address, onto a pixel coordinate within the navigation band @param ea: The address to map @return: a list [pixel, is_vertical] diff --git a/pywraps/py_kernwin_choose.hpp b/pywraps/py_kernwin_choose.hpp index 9d0454d..4f5d920 100644 --- a/pywraps/py_kernwin_choose.hpp +++ b/pywraps/py_kernwin_choose.hpp @@ -143,35 +143,35 @@ bool py_chooser_props_t::is_valid_cb( const char *name) { newref_t py_o_class(PyObject_GetAttrString(o, "__class__")); - bool ok = py_o_class != nullptr; + bool ok = py_o_class; #ifdef TESTABLE_BUILD QASSERT(30706, ok); #endif if ( ok ) { newref_t py_oclass_meth(PyObject_GetAttrString(py_o_class.o, name)); - ok = py_oclass_meth != nullptr && PyCallable_Check(py_oclass_meth.o); + ok = py_oclass_meth && PyCallable_Check(py_oclass_meth.o); #ifdef TESTABLE_BUILD QASSERT(30707, ok); #endif if ( ok ) { newref_t py_ida_kernwin(PyImport_ImportModule("ida_kernwin")); - ok = py_ida_kernwin != nullptr; + ok = py_ida_kernwin; #ifdef TESTABLE_BUILD QASSERT(30708, ok); #endif if ( ok ) { newref_t py_chooser(PyObject_GetAttrString(py_ida_kernwin.o, "Choose")); - ok = py_chooser != nullptr; + ok = py_chooser; #ifdef TESTABLE_BUILD QASSERT(30709, ok); #endif if ( ok ) { newref_t py_def_cb(PyObject_GetAttrString(py_chooser.o, name)); - ok = py_def_cb != nullptr; + ok = py_def_cb; #ifdef TESTABLE_BUILD QASSERT(30710, ok); #endif @@ -240,21 +240,18 @@ bool py_chooser_props_t::do_extract_from_pyobject( { // get list item: [name, width] borref_t list(PyList_GetItem(cols_attr.o, i)); - borref_t v(PyList_GetItem(list.o, 0)); - // Extract string - if ( v != nullptr ) + if ( borref_t v = borref_t(PyList_GetItem(list.o, 0)) ) PyUnicode_as_qstring(&out->header_strings[i], v.o); out->header[i] = out->header_strings[i].c_str(); // Extract width int width; - borref_t v2(PyList_GetItem(list.o, 1)); // No width? Guess width from column title - if ( v2 == nullptr ) - width = ::qustrlen(out->header_strings[i].c_str()); - else + if ( borref_t v2 = borref_t(PyList_GetItem(list.o, 1)) ) width = PyInt_AsLong(v2.o); + else + width = ::qustrlen(out->header_strings[i].c_str()); out->widths[i] = width; } @@ -435,8 +432,7 @@ void py_chooser_mixin_t::mixin_get_row( // Go over the List returned by Python and convert to C strings for ( int i = chobj->columns - 1; i >= 0; --i ) { - newref_t item(PySequence_GetItem(list.result.o, Py_ssize_t(i))); - if ( item != nullptr ) + if ( newref_t item = newref_t(PySequence_GetItem(list.result.o, Py_ssize_t(i))) ) { if ( !PyUnicode_Check(item.o) ) { @@ -634,13 +630,13 @@ class py_chooser_t : public chooser_t, public py_chooser_mixin_t { { newref_t item(PySequence_GetItem(pyres.result.o, 0)); - if ( item.o != nullptr && PyLong_Check(item.o) ) + if ( item && PyLong_Check(item.o) ) ret.changed = cbres_t(PyLong_AsLong(item.o)); } if ( ret.changed != NOTHING_CHANGED ) { newref_t item(PySequence_GetItem(pyres.result.o, 1)); - if ( item.o != nullptr && PyLong_Check(item.o) ) + if ( item && PyLong_Check(item.o) ) ret.idx = ssize_t(PyLong_AsSsize_t(item.o)); } } diff --git a/pywraps/py_kernwin_cli.hpp b/pywraps/py_kernwin_cli.hpp index 2e320d0..58ec0d7 100644 --- a/pywraps/py_kernwin_cli.hpp +++ b/pywraps/py_kernwin_cli.hpp @@ -80,7 +80,7 @@ private: "s", line)); PyW_ShowCbErr(S_ON_EXECUTE_LINE); - return result != nullptr && PyObject_IsTrue(result.o); + return result && PyObject_IsTrue(result.o); } //-------------------------------------------------------------------------- @@ -114,7 +114,7 @@ private: *vk_key, shift)); - bool ok = result != nullptr && PyTuple_Check(result.o); + bool ok = result && PyTuple_Check(result.o); PyW_ShowCbErr(S_ON_KEYDOWN); @@ -124,7 +124,7 @@ private: if ( sz > 0 ) { borref_t _r(PyTuple_GetItem(result.o, 0)); - if ( _r != nullptr && PyUnicode_Check(_r.o) ) + if ( _r && PyUnicode_Check(_r.o) ) PyUnicode_as_qstring(line, _r.o); } @@ -134,7 +134,7 @@ private: if ( sz > col ) \ { \ borref_t _r(PyTuple_GetItem(result.o, col)); \ - if ( _r != nullptr && PyThingy##_Check(_r.o) ) \ + if ( _r && PyThingy##_Check(_r.o) ) \ *out = PyThingy##_##AsThingy(_r.o); \ } \ } while ( false ) @@ -171,7 +171,7 @@ private: line, x)); - bool ok = result != nullptr && PyUnicode_Check(result.o); + bool ok = result && PyUnicode_Check(result.o); PyW_ShowCbErr(S_ON_COMPLETE_LINE); if ( ok ) PyUnicode_as_qstring(completion, result.o); diff --git a/pywraps/py_kernwin_custview.hpp b/pywraps/py_kernwin_custview.hpp index 1b5e3f7..e600c6f 100644 --- a/pywraps/py_kernwin_custview.hpp +++ b/pywraps/py_kernwin_custview.hpp @@ -313,7 +313,7 @@ class py_simplecustview_t shift)); PyW_ShowCbErr(S_ON_KEYDOWN); - return py_result != nullptr && PyObject_IsTrue(py_result.o); + return py_result && PyObject_IsTrue(py_result.o); } //-------------------------------------------------------------------------- @@ -329,7 +329,7 @@ class py_simplecustview_t bvsz_t(ln))); PyW_ShowCbErr(S_ON_HINT); - bool ok = py_result != nullptr + bool ok = py_result && PyTuple_Check(py_result.o) && PyTuple_Size(py_result.o) == 2; if ( ok ) @@ -352,7 +352,7 @@ class py_simplecustview_t PY_BV_SZ, bvsz_t(menu_id))); PyW_ShowCbErr(S_ON_POPUP_MENU); - return py_result != nullptr && PyObject_IsTrue(py_result.o); + return py_result && PyObject_IsTrue(py_result.o); } //-------------------------------------------------------------------------- diff --git a/pywraps/py_nalt.hpp b/pywraps/py_nalt.hpp index 395c617..81dbf46 100644 --- a/pywraps/py_nalt.hpp +++ b/pywraps/py_nalt.hpp @@ -37,7 +37,7 @@ static int idaapi py_import_enum_cb( py_name.o, py_ord.o, nullptr)); - return py_result != nullptr && PyObject_IsTrue(py_result.o) ? 1 : 0; + return py_result && PyObject_IsTrue(py_result.o) ? 1 : 0; } // diff --git a/pywraps/py_typeinf.hpp b/pywraps/py_typeinf.hpp index 62f8abc..15938b7 100644 --- a/pywraps/py_typeinf.hpp +++ b/pywraps/py_typeinf.hpp @@ -575,7 +575,7 @@ PyObject *py_print_decls(text_sink_t &printer, til_t *til, PyObject *py_ordinals for ( Py_ssize_t i = 0; i < nords; ++i ) { borref_t item(PyList_GetItem(py_ordinals, i)); - if ( item == nullptr || !PyLong_Check(item.o) ) + if ( !item || !PyLong_Check(item.o) ) { qstring msg; msg.sprnt("ordinals[%d] is not a valid value", int(i)); diff --git a/pywraps/py_ua.hpp b/pywraps/py_ua.hpp index 4c9a6bc..dd1de86 100644 --- a/pywraps/py_ua.hpp +++ b/pywraps/py_ua.hpp @@ -53,11 +53,9 @@ bool py_construct_macro(insn_t &insn, bool enable, PyObject *build_macro) { PyObject *py_builder = macro_builders.top().o; ref_t py_res; - ref_t py_mod(PyW_TryImportModule(SWIG_name)); - if ( py_mod != nullptr ) + if ( ref_t py_mod = ref_t(PyW_TryImportModule(SWIG_name)) ) { - ref_t py_insn = try_create_swig_wrapper(py_mod, "insn_t", &insn); - if ( py_insn != nullptr ) + if ( ref_t py_insn = ref_t(try_create_swig_wrapper(py_mod, "insn_t", &insn)) ) { py_res = newref_t( PyObject_CallFunction( diff --git a/swig/kernwin.i b/swig/kernwin.i index eeb0268..98fecf6 100644 --- a/swig/kernwin.i +++ b/swig/kernwin.i @@ -245,11 +245,11 @@ struct py_action_handler_t : public action_handler_t : pyah(borref_t(_o)), has_activate(false), has_update(false) { ref_t act(PyW_TryGetAttrString(pyah.o, "activate")); - if ( act != nullptr && PyCallable_Check(act.o) > 0 ) + if ( act && PyCallable_Check(act.o) > 0 ) has_activate = true; ref_t upd(PyW_TryGetAttrString(pyah.o, "update")); - if ( upd != nullptr && PyCallable_Check(upd.o) > 0 ) + if ( upd && PyCallable_Check(upd.o) > 0 ) has_update = true; } virtual idaapi ~py_action_handler_t() @@ -267,7 +267,7 @@ struct py_action_handler_t : public action_handler_t PYW_GIL_GET_AND_REPORT_ERROR; newref_t pyctx(SWIG_InternalNewPointerObj(SWIG_as_voidptr(ctx), SWIGTYPE_p_action_ctx_base_t, 0)); newref_t pyres(PyObject_CallMethod(pyah.o, (char *)"activate", (char *) "O", pyctx.o)); - return PyErr_Occurred() != nullptr ? 0 : ((pyres != nullptr && PyLong_Check(pyres.o)) ? PyLong_AsLong(pyres.o) : 0); + return PyErr_Occurred() != nullptr ? 0 : ((pyres && PyLong_Check(pyres.o)) ? PyLong_AsLong(pyres.o) : 0); } virtual action_state_t idaapi update(action_update_ctx_t *ctx) { @@ -276,7 +276,7 @@ struct py_action_handler_t : public action_handler_t PYW_GIL_GET_AND_REPORT_ERROR; newref_t pyctx(SWIG_InternalNewPointerObj(SWIG_as_voidptr(ctx), SWIGTYPE_p_action_ctx_base_t, 0)); newref_t pyres(PyObject_CallMethod(pyah.o, (char *)"update", (char *) "O", pyctx.o)); - return PyErr_Occurred() != nullptr ? AST_DISABLE_ALWAYS : ((pyres != nullptr && PyLong_Check(pyres.o)) ? action_state_t(PyLong_AsLong(pyres.o)) : AST_DISABLE); + return PyErr_Occurred() != nullptr ? AST_DISABLE_ALWAYS : ((pyres && PyLong_Check(pyres.o)) ? action_state_t(PyLong_AsLong(pyres.o)) : AST_DISABLE); } private: