Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 477a02f

Browse files
committed
minor mods: use the bool operator on ref_t and co.
1 parent 4d3da67 commit 477a02f

16 files changed

+160
-170
lines changed

idapython.cpp

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,7 @@ void convert_idc_args()
701701

702702
// Get reference to the IDC module (it is imported by init.py)
703703
ref_t py_mod(PyW_TryImportModule(S_IDC_MODNAME));
704-
if ( py_mod != nullptr )
704+
if ( py_mod )
705705
PyObject_SetAttrString(py_mod.o, S_IDC_ARGS_VARNAME, py_args.o);
706706
}
707707

@@ -1129,8 +1129,7 @@ ref_t idapython_plugin_t::get_sys_displayhook()
11291129
ref_t h;
11301130
if ( config.repl_use_sys_displayhook )
11311131
{
1132-
ref_t py_sys(PyW_TryImportModule("sys"));
1133-
if ( py_sys != nullptr )
1132+
if ( ref_t py_sys = ref_t(PyW_TryImportModule("sys")) )
11341133
h = PyW_TryGetAttrString(py_sys.o, "displayhook");
11351134
}
11361135
return h;
@@ -1425,7 +1424,7 @@ bool idapython_plugin_t::_extlang_create_object(
14251424

14261425
// Get a reference to the module
14271426
ref_t py_mod(PyW_TryImportModule(modname));
1428-
if ( py_mod == nullptr )
1427+
if ( !py_mod )
14291428
{
14301429
errbuf->sprnt("Could not import module '%s'!", modname);
14311430
break;
@@ -1435,15 +1434,15 @@ bool idapython_plugin_t::_extlang_create_object(
14351434
ref_t py_res;
14361435
if ( nargs == 1 && args[0].vtype == VT_PVOID )
14371436
py_res = try_create_swig_wrapper(py_mod, clsname, args[0].pvoid);
1438-
if ( py_res != nullptr )
1437+
if ( py_res )
14391438
{
14401439
PyObject_SetAttrString(py_res.o, S_PY_IDCCVT_ID_ATTR, PyLong_FromLong(PY_ICID_OPAQUE));
14411440
}
14421441
else
14431442
{
14441443
// Get the class reference
14451444
ref_t py_cls(PyW_TryGetAttrString(py_mod.o, clsname));
1446-
if ( py_cls == nullptr )
1445+
if ( !py_cls )
14471446
{
14481447
errbuf->sprnt("Could not find class type '%s'!", clsname);
14491448
break;
@@ -1491,7 +1490,7 @@ bool idapython_plugin_t::_extlang_eval_snippet(
14911490
globals,
14921491
globals,
14931492
nullptr));
1494-
ok = result != nullptr && !PyErr_Occurred(); //-V560 is always true: !PyErr_Occurred()
1493+
ok = result && !PyErr_Occurred(); //-V560 is always true: !PyErr_Occurred()
14951494
if ( !ok )
14961495
handle_python_error(errbuf);
14971496
}
@@ -1612,7 +1611,7 @@ bool idapython_plugin_t::_extlang_call_method(
16121611
}
16131612

16141613
ref_t py_method(PyW_TryGetAttrString(py_obj.o, method_name));
1615-
if ( py_method == nullptr || !PyCallable_Check(py_method.o) )
1614+
if ( !py_method || !PyCallable_Check(py_method.o) )
16161615
{
16171616
errbuf->sprnt("The input object does not have a callable method called '%s'", method_name);
16181617
break;
@@ -1624,8 +1623,7 @@ bool idapython_plugin_t::_extlang_call_method(
16241623
// to be converted to an unsigned python long
16251624
if ( streq(method_name, "run") )
16261625
{
1627-
ref_t py_ida_idaapi_mod(PyW_TryImportModule(S_IDA_IDAAPI_MODNAME));
1628-
if ( py_ida_idaapi_mod != nullptr )
1626+
if ( ref_t py_ida_idaapi_mod = ref_t(PyW_TryImportModule(S_IDA_IDAAPI_MODNAME)) )
16291627
{
16301628
if ( is_instance_of(py_obj.o, py_ida_idaapi_mod.o, "plugin_t")
16311629
|| is_instance_of(py_obj.o, py_ida_idaapi_mod.o, "plugmod_t") )
@@ -1661,14 +1659,14 @@ bool idapython_plugin_t::_extlang_get_attr(
16611659
{
16621660
// Get a reference to the module
16631661
ref_t py_mod(PyW_TryImportModule(S_MAIN));
1664-
if ( py_mod == nullptr )
1662+
if ( !py_mod )
16651663
break;
16661664

16671665
// Object specified:
16681666
// - (1) string contain attribute name in the main module
16691667
// - (2) opaque object (we use it as is)
16701668
ref_t py_obj;
1671-
if ( obj != nullptr )
1669+
if ( obj )
16721670
{
16731671
// (1) Get attribute from main module
16741672
if ( obj->vtype == VT_STR )
@@ -1688,7 +1686,7 @@ bool idapython_plugin_t::_extlang_get_attr(
16881686
}
16891687
}
16901688
// Get the attribute reference
1691-
if ( py_obj == nullptr )
1689+
if ( !py_obj )
16921690
break;
16931691
}
16941692
// No object specified:
@@ -1704,17 +1702,17 @@ bool idapython_plugin_t::_extlang_get_attr(
17041702
cvt = CIP_FAILED;
17051703
// Get the class
17061704
newref_t cls(PyObject_GetAttrString(py_obj.o, "__class__"));
1707-
if ( cls == nullptr )
1705+
if ( !cls )
17081706
break;
17091707

17101708
// Get its name
17111709
newref_t name(PyObject_GetAttrString(cls.o, "__name__"));
1712-
if ( name == nullptr )
1710+
if ( !name )
17131711
break;
17141712

17151713
// Convert name object to string object
17161714
newref_t string(PyObject_Str(name.o));
1717-
if ( string == nullptr )
1715+
if ( !string )
17181716
break;
17191717

17201718
// Convert name python string to a C string
@@ -1729,7 +1727,7 @@ bool idapython_plugin_t::_extlang_get_attr(
17291727

17301728
ref_t py_attr(PyW_TryGetAttrString(py_obj.o, attr));
17311729
// No attribute?
1732-
if ( py_attr == nullptr )
1730+
if ( !py_attr )
17331731
{
17341732
cvt = CIP_FAILED;
17351733
break;
@@ -1773,7 +1771,7 @@ bool idapython_plugin_t::_extlang_set_attr(
17731771
{
17741772
// Get a reference to the module
17751773
ref_t py_mod(PyW_TryImportModule(S_MAIN));
1776-
if ( py_mod == nullptr )
1774+
if ( !py_mod )
17771775
break;
17781776
ref_t py_obj;
17791777
if ( obj != nullptr )
@@ -1790,7 +1788,7 @@ bool idapython_plugin_t::_extlang_set_attr(
17901788
py_obj = ref_t();
17911789
}
17921790
// No object to set_attr on?
1793-
if ( py_obj == nullptr )
1791+
if ( !py_obj )
17941792
break;
17951793
}
17961794
else
@@ -1860,7 +1858,7 @@ bool idapython_plugin_t::_cli_execute_line(const char *line)
18601858
// Compile as an expression
18611859
qstring qstr(line);
18621860
newref_t py_code(my_CompileString(insert_encoding_cookie(&qstr), "<string>", Py_eval_input));
1863-
if ( py_code == nullptr || PyErr_Occurred() )
1861+
if ( !py_code || PyErr_Occurred() )
18641862
{
18651863
// Not an expression?
18661864
PyErr_Clear();
@@ -1873,7 +1871,7 @@ bool idapython_plugin_t::_cli_execute_line(const char *line)
18731871
PyObject *py_globals = _get_module_globals();
18741872
newref_t py_result(PyEval_EvalCode(py_code.o, py_globals, py_globals));
18751873

1876-
if ( py_result == nullptr || PyErr_Occurred() ) //-V560 is always false: PyErr_Occurred()
1874+
if ( !py_result || PyErr_Occurred() ) //-V560 is always false: PyErr_Occurred()
18771875
{
18781876
PyErr_Print();
18791877
}
@@ -1923,7 +1921,7 @@ bool idapython_plugin_t::_cli_find_completions(
19231921
PYW_GIL_GET;
19241922

19251923
ref_t py_fc(get_idaapi_attr(S_IDAAPI_FINDCOMPLETIONS));
1926-
if ( py_fc == nullptr )
1924+
if ( !py_fc )
19271925
return false;
19281926

19291927
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(
19521950
{
19531951
PYW_GIL_CHECK_LOCKED_SCOPE();
19541952
ref_t py_executor_func(get_idaapi_attr(idaapi_executor_func_name));
1955-
if ( py_executor_func == nullptr )
1953+
if ( !py_executor_func )
19561954
{
19571955
errbuf->sprnt("Could not find %s.%s ?!", S_IDA_IDAAPI_MODNAME, idaapi_executor_func_name);
19581956
return false;
@@ -1985,7 +1983,7 @@ bool idapython_plugin_t::_handle_file(
19851983

19861984
// Failure at this point means the script was interrupted
19871985
bool interrupted = false;
1988-
if ( PyW_GetError(errbuf) || py_ret == nullptr )
1986+
if ( PyW_GetError(errbuf) || !py_ret )
19891987
{
19901988
PyErr_Clear();
19911989
if ( errbuf->empty() )
@@ -2087,7 +2085,7 @@ bool idapython_plugin_t::_check_python_dir()
20872085
void idapython_plugin_t::_prepare_sys_path()
20882086
{
20892087
borref_t path(PySys_GetObject((char *) "path"));
2090-
if ( path == nullptr || !PySequence_Check(path.o) )
2088+
if ( !path || !PySequence_Check(path.o) )
20912089
return;
20922090

20932091
qstring new_path;
@@ -2098,7 +2096,7 @@ void idapython_plugin_t::_prepare_sys_path()
20982096
{
20992097
qstring path_el_utf8;
21002098
newref_t path_el(PySequence_GetItem(path.o, i));
2101-
if ( path_el != nullptr
2099+
if ( path_el
21022100
&& PyUnicode_Check(path_el.o)
21032101
&& PyUnicode_as_qstring(&path_el_utf8, path_el.o) )
21042102
{
@@ -2161,11 +2159,11 @@ bool idapython_plugin_t::_run_init_py()
21612159
contents.resize(effsz);
21622160

21632161
newref_t code(my_CompileString(contents.c_str(), path, Py_file_input));
2164-
if ( code == nullptr )
2162+
if ( !code )
21652163
return false;
21662164

21672165
newref_t result(PyEval_EvalCode(code.o, __main__globals, __main__globals));
2168-
return result != nullptr && !PyErr_Occurred();
2166+
return result && !PyErr_Occurred();
21692167
}
21702168

21712169
//------------------------------------------------------------------------

0 commit comments

Comments
 (0)