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:
Panu Matilainen 2007-06-07 21:51:59 +03:00
parent 578e90f2f8
commit 48048a3930
4 changed files with 8 additions and 4 deletions

View File

@ -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);
}
/**

View File

@ -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;
}

View File

@ -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

View File

@ -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