summaryrefslogtreecommitdiff
path: root/python/rpmii-py.c
diff options
context:
space:
mode:
Diffstat (limited to 'python/rpmii-py.c')
-rw-r--r--python/rpmii-py.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/python/rpmii-py.c b/python/rpmii-py.c
index 9209b54e5..180741479 100644
--- a/python/rpmii-py.c
+++ b/python/rpmii-py.c
@@ -1,7 +1,9 @@
#include "rpmsystem-py.h"
#include <rpm/rpmdb.h>
+#include <rpm/rpmtd.h>
+#include "rpmtd-py.h"
#include "rpmii-py.h"
#include "header-py.h"
@@ -36,18 +38,25 @@ struct rpmiiObject_s {
PyObject *md_dict; /*!< to look like PyModuleObject */
PyObject *ref; /* for db/ts refcounting */
rpmdbIndexIterator ii;
+ rpmtd keytd;
};
static PyObject *
rpmii_iternext(rpmiiObject * s)
{
- char * key;
- size_t keylen;
- if (s->ii == NULL || (rpmdbIndexIteratorNext(s->ii, (const void**)&key, &keylen)) != 0) {
- s->ii = rpmdbIndexIteratorFree(s->ii);
- return NULL;
+ PyObject *keyo = NULL;
+
+ if (s->ii != NULL) {
+ if (rpmdbIndexIteratorNextTd(s->ii, s->keytd) == 0) {
+ /* The keys must never be arrays so rpmtd_AsPyObj() wont work */
+ keyo = rpmtd_ItemAsPyobj(s->keytd, rpmtdClass(s->keytd));
+ rpmtdFreeData(s->keytd);
+ } else {
+ s->ii = rpmdbIndexIteratorFree(s->ii);
+ }
}
- return PyBytes_FromStringAndSize(key, keylen);
+
+ return keyo;
};
static PyObject *
@@ -75,6 +84,7 @@ static struct PyMethodDef rpmii_methods[] = {
static void rpmii_dealloc(rpmiiObject * s)
{
s->ii = rpmdbIndexIteratorFree(s->ii);
+ rpmtdFree(s->keytd);
Py_DECREF(s->ref);
Py_TYPE(s)->tp_free((PyObject *)s);
}
@@ -88,6 +98,9 @@ static PyNumberMethods rpmii_as_number = {
0, /* nb_add */
0, /* nb_subtract */
0, /* nb_multiply */
+#if PY_MAJOR_VERSION < 3
+ 0, /* nb_divide */
+#endif
0, /* nb_remainder */
0, /* nb_divmod */
0, /* nb_power */
@@ -102,7 +115,7 @@ static char rpmii_doc[] =
PyTypeObject rpmii_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
- PYTHON_MODULENAME".ii", /* tp_name */
+ "rpm.ii", /* tp_name */
sizeof(rpmiiObject), /* tp_size */
0, /* tp_itemsize */
(destructor) rpmii_dealloc, /* tp_dealloc */
@@ -150,6 +163,7 @@ PyObject * rpmii_Wrap(PyTypeObject *subtype, rpmdbIndexIterator ii, PyObject *s)
iio->ii = ii;
iio->ref = s;
+ iio->keytd = rpmtdNew();
Py_INCREF(iio->ref);
return (PyObject *) iio;
}