diff --git a/python/header-py.c b/python/header-py.c index 91fb6ffde..f12cbbe80 100644 --- a/python/header-py.c +++ b/python/header-py.c @@ -4,6 +4,7 @@ #include #include #include /* XXX rpmtsCreate/rpmtsFree */ +#include #include "header-py.h" #include "rpmds-py.h" @@ -888,36 +889,27 @@ PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds) return Py_BuildValue("i", rpmVersionCompare(h1->h, h2->h)); } -static int compare_values(const char *str1, const char *str2) -{ - if (!str1 && !str2) - return 0; - else if (str1 && !str2) - return 1; - else if (!str1 && str2) - return -1; - return rpmvercmp(str1, str2); -} - PyObject * labelCompare (PyObject * self, PyObject * args) { const char *v1, *r1, *v2, *r2; const char *e1, *e2; - int rc; + PyObject *rco = NULL; if (!PyArg_ParseTuple(args, "(zzz)(zzz)", &e1, &v1, &r1, &e2, &v2, &r2)) return NULL; - if (e1 == NULL) e1 = "0"; - if (e2 == NULL) e2 = "0"; + rpmver rv1 = rpmverNew(e1, v1, r1); + rpmver rv2 = rpmverNew(e2, v2, r2); - rc = compare_values(e1, e2); - if (!rc) { - rc = compare_values(v1, v2); - if (!rc) - rc = compare_values(r1, r2); - } - return Py_BuildValue("i", rc); + if (rv1 && rv2) + rco = Py_BuildValue("i", rpmverCmp(rv1, rv2)); + else + PyErr_SetString(PyExc_ValueError, "invalid version label"); + + rpmverFree(rv1); + rpmverFree(rv2); + + return rco; } diff --git a/tests/rpmpython.at b/tests/rpmpython.at index 29f0bb4de..b8233161e 100644 --- a/tests/rpmpython.at +++ b/tests/rpmpython.at @@ -155,8 +155,29 @@ h['release'] = r h['epoch'] = e myprint(rpm.labelCompare((str(h['epoch']), h['version'], h['release']), (str(e), v, r))) +myprint(rpm.labelCompare((None, '1.0', '1'), + (None, '1.1', '2'))) +myprint(rpm.labelCompare((None, '1.0', '1'), + (None, '1.1', '1'))) +myprint(rpm.labelCompare((None, '1.1', '1'), + (None, '1.0', '1'))) +myprint(rpm.labelCompare((None, '1.1', '1'), + (None, '1.0', '2'))) +myprint(rpm.labelCompare(('1', '1.0', '1'), + ('0', '1.0', '1'))) +myprint(rpm.labelCompare(('0', '1.0', '1'), + ('1', '1.0', '1'))) +myprint(rpm.labelCompare(('0', '1.0', '1'), + (None, '1.0', '1'))) ], -[0] +[0 +-1 +-1 +1 +1 +1 +-1 +0] ) RPMPY_TEST([vfyflags API],[