Ts/db reference counting for match-iterators in python (rhbz#241751)
Adds additional refcounting to the python level ts/db object to avoid anonymous ts/db from getting deleted while still iterating over it.
This commit is contained in:
parent
578e90f2f8
commit
48048a3930
|
@ -126,7 +126,7 @@ rpmdb_Match (rpmdbObject * s, PyObject * args, PyObject * kwds)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
return rpmmi_Wrap( rpmdbInitIterator(s->db, tag, key, len) );
|
||||
return rpmmi_Wrap( rpmdbInitIterator(s->db, tag, key, len), (PyObject *)s);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -199,6 +199,7 @@ static void rpmmi_dealloc(/*@only@*/ /*@null@*/ rpmmiObject * s)
|
|||
{
|
||||
if (s) {
|
||||
s->mi = rpmdbFreeIterator(s->mi);
|
||||
Py_DECREF(s->ref);
|
||||
PyObject_Del(s);
|
||||
}
|
||||
}
|
||||
|
@ -271,7 +272,7 @@ PyTypeObject rpmmi_Type = {
|
|||
};
|
||||
/*@=fullinitblock@*/
|
||||
|
||||
rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi)
|
||||
rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi, PyObject *s)
|
||||
{
|
||||
rpmmiObject * mio = (rpmmiObject *) PyObject_New(rpmmiObject, &rpmmi_Type);
|
||||
|
||||
|
@ -280,6 +281,8 @@ rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi)
|
|||
return NULL;
|
||||
}
|
||||
mio->mi = mi;
|
||||
mio->ref = s;
|
||||
Py_INCREF(mio->ref);
|
||||
return mio;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ typedef struct rpmmiObject_s rpmmiObject;
|
|||
struct rpmmiObject_s {
|
||||
PyObject_HEAD
|
||||
PyObject *md_dict; /*!< to look like PyModuleObject */
|
||||
PyObject *ref; /* for db/ts refcounting */
|
||||
rpmdbMatchIterator mi;
|
||||
} ;
|
||||
|
||||
|
@ -21,7 +22,7 @@ struct rpmmiObject_s {
|
|||
extern PyTypeObject rpmmi_Type;
|
||||
|
||||
/*@null@*/
|
||||
rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi)
|
||||
rpmmiObject * rpmmi_Wrap(rpmdbMatchIterator mi, PyObject *s)
|
||||
/*@*/;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1397,7 +1397,7 @@ fprintf(stderr, "*** rpmts_Match(%p) ts %p\n", s, s->ts);
|
|||
}
|
||||
}
|
||||
|
||||
return rpmmi_Wrap( rpmtsInitIterator(s->ts, tag, key, len) );
|
||||
return rpmmi_Wrap( rpmtsInitIterator(s->ts, tag, key, len), (PyObject*)s);
|
||||
}
|
||||
|
||||
/** \ingroup py_c
|
||||
|
|
Loading…
Reference in New Issue