Backported fixes

This commit is contained in:
Arnaud Diederen
2020-10-12 12:52:15 +02:00
parent a0a90d7b07
commit 99d9079ed5
2 changed files with 23 additions and 1 deletions
Binary file not shown.
+23 -1
View File
@@ -272,6 +272,7 @@ struct py_chooser_mixin_t
py_chooser_mixin_t(PyObject *_self, py_chooser_props_t &_props)
: self(borref_t(_self))
{
_instances.add_unique(this);
props.swap(_props);
}
~py_chooser_mixin_t()
@@ -280,6 +281,7 @@ struct py_chooser_mixin_t
self = newref_t(NULL);
dirspec = newref_t(NULL);
dirtree = newref_t(NULL);
_instances.del(this);
}
bool has_feature(feature_t f) const { return props.has_feature(f); }
@@ -287,6 +289,8 @@ struct py_chooser_mixin_t
py_chooser_props_t &props,
PyObject *o);
static py_chooser_mixin_t *find_by_pyobj(PyObject *o);
protected:
const void *mixin_get_obj_id(size_t *len) const { *len = sizeof(self.o); return self.o; }
void *mixin_get_chooser_obj() { return self.o; }
@@ -302,8 +306,14 @@ protected:
dirtree_t *mixin_get_dirtree(const chooser_base_t *chobj);
inode_t mixin_index_to_inode(size_t n) const;
void mixin_init_chooser_base_from_props(chooser_base_t *cb);
private:
static qvector<py_chooser_mixin_t*> _instances;
};
//-------------------------------------------------------------------------
qvector<py_chooser_mixin_t*> py_chooser_mixin_t::_instances;
//-------------------------------------------------------------------------
bool py_chooser_mixin_t::mixin_init(chooser_base_t *chobj)
{
@@ -693,6 +703,16 @@ chooser_base_t *py_chooser_mixin_t::create_concrete_instance(
return chobj;
}
//-------------------------------------------------------------------------
py_chooser_mixin_t * py_chooser_mixin_t::find_by_pyobj(
PyObject *o)
{
for ( auto m : _instances )
if ( m->mixin_get_chooser_obj() == o )
return m;
return nullptr;
}
//-------------------------------------------------------------------------
PyObject *choose_choose(PyObject *self)
{
@@ -789,7 +809,9 @@ PyObject *choose_create_embedded_chobj(PyObject *self)
PyObject *choose_find(const char *title)
{
PyObject *o = static_cast<PyObject*>(::get_chooser_obj(title));
if ( o == NULL )
if ( o == nullptr )
Py_RETURN_NONE;
if ( py_chooser_mixin_t::find_by_pyobj(o) == nullptr )
Py_RETURN_NONE;
Py_INCREF(o);
return o;