From 02c95291c3eadf0cfc601286eb92cbb7efceb517 Mon Sep 17 00:00:00 2001 From: Elias Bachaalany Date: Thu, 12 Jan 2023 21:27:42 -0800 Subject: [PATCH 1/2] + bugfix: IDAPython: Choose.OnGetLineAttr was broken - It was only accepting lists (it should accept both tuples and lists) --- pywraps/py_kernwin_choose.hpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/pywraps/py_kernwin_choose.hpp b/pywraps/py_kernwin_choose.hpp index f25fb11..52d38fd 100644 --- a/pywraps/py_kernwin_choose.hpp +++ b/pywraps/py_kernwin_choose.hpp @@ -478,15 +478,18 @@ void py_chooser_mixin_t::mixin_get_row( PyObject_CallMethod( self.o, (char *)S_ON_GET_LINE_ATTR, "i", int(n))); - if ( PyErr_Occurred() != nullptr ) - return; - if ( pyres.result != nullptr && PyList_Check(pyres.result.o) ) + if ( PyErr_Occurred() == nullptr && pyres.result != nullptr && PySequence_Check(pyres.result.o) ) { - PyObject *item; - if ( (item = PyList_GetItem(pyres.result.o, 0)) != nullptr ) - attrs->color = PyInt_AsLong(item); - if ( (item = PyList_GetItem(pyres.result.o, 1)) != nullptr ) - attrs->flags = PyInt_AsLong(item); + { + newref_t item(PySequence_GetItem(pyres.result.o, 0)); + if (item.o != nullptr && PyLong_Check(item.o)) + attrs->color = PyLong_AsUnsignedLong(item.o); + } + { + newref_t item(PySequence_GetItem(pyres.result.o, 1)); + if (item.o != nullptr && PyLong_Check(item.o)) + attrs->flags = PyInt_AsLong(item.o); + } } } } From 1284df518829bc93614b2858904907ad1ec77e1a Mon Sep 17 00:00:00 2001 From: Elias Bachaalany Date: Thu, 12 Jan 2023 22:36:10 -0800 Subject: [PATCH 2/2] added bool operator for `ref_t` and simplified the fix --- pywraps.hpp | 1 + pywraps/py_kernwin_choose.hpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pywraps.hpp b/pywraps.hpp index e07be82..54cfdd3 100644 --- a/pywraps.hpp +++ b/pywraps.hpp @@ -326,6 +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; } }; //------------------------------------------------------------------------- diff --git a/pywraps/py_kernwin_choose.hpp b/pywraps/py_kernwin_choose.hpp index 52d38fd..9d0454d 100644 --- a/pywraps/py_kernwin_choose.hpp +++ b/pywraps/py_kernwin_choose.hpp @@ -482,12 +482,12 @@ void py_chooser_mixin_t::mixin_get_row( { { newref_t item(PySequence_GetItem(pyres.result.o, 0)); - if (item.o != nullptr && PyLong_Check(item.o)) + if (item && PyLong_Check(item.o)) attrs->color = PyLong_AsUnsignedLong(item.o); } { newref_t item(PySequence_GetItem(pyres.result.o, 1)); - if (item.o != nullptr && PyLong_Check(item.o)) + if (item && PyLong_Check(item.o)) attrs->flags = PyInt_AsLong(item.o); } }