summaryrefslogtreecommitdiff
path: root/python/rpmii-py.c
diff options
context:
space:
mode:
authorwangbiao <biao716.wang@samsung.com>2023-11-16 18:17:42 +0900
committerwangbiao <biao716.wang@samsung.com>2023-11-16 18:17:42 +0900
commitc30d127e8780dc678168ee121b9f2eeb1a8aaafa (patch)
treecdc9ddc3123edd5741e5151f3076c9bfc9535916 /python/rpmii-py.c
parent258ff2bdb80c458b743417c427f66fa5f27bf7c5 (diff)
downloadlibrpm-tizen-c30d127e8780dc678168ee121b9f2eeb1a8aaafa.tar.gz
librpm-tizen-c30d127e8780dc678168ee121b9f2eeb1a8aaafa.tar.bz2
librpm-tizen-c30d127e8780dc678168ee121b9f2eeb1a8aaafa.zip
Upgrade version to 4.14tizen/4.14.1.1.tizen20230628
Change-Id: I21bf1a3a7c25cbec43022202cf2e5865b603a309 Signed-off-by: wangbiao <biao716.wang@samsung.com>
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;
}