Eliminate the ambigious tp_compare from rpm.hdr
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 28 Oct 2009 13:22:39 +0000 (15:22 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 28 Oct 2009 14:02:47 +0000 (16:02 +0200)
- Avoids another Python 3 incompatibility as it doesn't have tp_compare
  anymore
- We could add a compatible tp_richcompare, but comparisons like
  'if h1 < h2: do foo' are highly ambiguous, callers are better of
  using explicit rpm.versinCompare(h1, h2) instead

python/header-py.c

index 6f82dc7..9272fc8 100644 (file)
@@ -311,11 +311,6 @@ static PyObject * hdr_dsOfHeader(PyObject * s)
                        Py_BuildValue("(Oi)", s, RPMTAG_NEVR), NULL);
 }
 
-static int hdr_compare(hdrObject * a, hdrObject * b)
-{
-    return rpmVersionCompare(a->h, b->h);
-}
-
 static long hdr_hash(PyObject * h)
 {
     return (long) h;
@@ -527,7 +522,7 @@ PyTypeObject hdr_Type = {
        0,                              /* tp_print */
        (getattrfunc) 0,                /* tp_getattr */
        0,                              /* tp_setattr */
-       (cmpfunc) hdr_compare,          /* tp_compare */
+       0,                              /* tp_compare */
        0,                              /* tp_repr */
        0,                              /* tp_as_number */
        0,                              /* tp_as_sequence */
@@ -683,7 +678,7 @@ PyObject * versionCompare (PyObject * self, PyObject * args, PyObject * kwds)
            &h1, &hdr_Type, &h2))
        return NULL;
 
-    return Py_BuildValue("i", hdr_compare(h1, h2));
+    return Py_BuildValue("i", rpmVersionCompare(h1->h, h2->h));
 }
 
 static int compare_values(const char *str1, const char *str2)