Handle non-existent dependency sets in python (RhBug:593553)
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 19 May 2010 07:12:43 +0000 (10:12 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 19 May 2010 07:12:43 +0000 (10:12 +0300)
- rpmdsNew() returns NULL if the requested dependency type doesn't
  exist in the header. The C-side API can handle NULL to all rpmds
  "methods" and this is how librpm deals with non-existent sets rather
  than waste memory on for empty ds structures. However the python side
  wasn't expecting NULL for legal requests (but not setting error either)
  and thus blowing up with SystemError exception.
- Raise TypeError on illegal arguments to rpm.ds constructor, and present
  non-existent dependency sets as empty rpm.ds objects to python. This
  lets python callers use iteration over ds items regardless of whether
  the dependency actually exists or not. The alternative of returning
  None (or raising exceptions) would break existing code for no
  particularly good reason.

python/rpmds-py.c

index 771cd06..4587201 100644 (file)
@@ -288,10 +288,11 @@ static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kw
        } else {
            ds = rpmdsNew(h, tagN, 0);
        }
+    } else {
+       PyErr_SetString(PyExc_TypeError, "header or tuple expected");
+       return NULL;
     }
     
-    if (ds == NULL) return NULL;
-       
     return rpmds_Wrap(subtype, ds);
 }