diff --git a/pywraps.hpp b/pywraps.hpp index caa8f60..b713c68 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 f25fb11..9d0454d 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 && PyLong_Check(item.o)) + attrs->color = PyLong_AsUnsignedLong(item.o); + } + { + newref_t item(PySequence_GetItem(pyres.result.o, 1)); + if (item && PyLong_Check(item.o)) + attrs->flags = PyInt_AsLong(item.o); + } } } }