Panu Matilainen 5004ac
commit 0e0e332b466a9784620c483faa374067381e96ce
Panu Matilainen 5004ac
Author: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen 5004ac
Date:   Wed May 19 10:12:43 2010 +0300
Panu Matilainen 5004ac
Panu Matilainen 5004ac
    Handle non-existent dependency sets in python (RhBug:593553)
Panu Matilainen 5004ac
    - rpmdsNew() returns NULL if the requested dependency type doesn't
Panu Matilainen 5004ac
      exist in the header. The C-side API can handle NULL to all rpmds
Panu Matilainen 5004ac
      "methods" and this is how librpm deals with non-existent sets rather
Panu Matilainen 5004ac
      than waste memory on for empty ds structures. However the python side
Panu Matilainen 5004ac
      wasn't expecting NULL for legal requests (but not setting error either)
Panu Matilainen 5004ac
      and thus blowing up with SystemError exception.
Panu Matilainen 5004ac
    - Raise TypeError on illegal arguments to rpm.ds constructor, and present
Panu Matilainen 5004ac
      non-existent dependency sets as empty rpm.ds objects to python. This
Panu Matilainen 5004ac
      lets python callers use iteration over ds items regardless of whether
Panu Matilainen 5004ac
      the dependency actually exists or not. The alternative of returning
Panu Matilainen 5004ac
      None (or raising exceptions) would break existing code for no
Panu Matilainen 5004ac
      particularly good reason.
Panu Matilainen 5004ac
Panu Matilainen 5004ac
diff --git a/python/rpmds-py.c b/python/rpmds-py.c
Panu Matilainen 5004ac
index 771cd06..4587201 100644
Panu Matilainen 5004ac
--- a/python/rpmds-py.c
Panu Matilainen 5004ac
+++ b/python/rpmds-py.c
Panu Matilainen 5004ac
@@ -288,10 +288,11 @@ static PyObject * rpmds_new(PyTypeObject * subtype, PyObject *args, PyObject *kw
Panu Matilainen 5004ac
 	} else {
Panu Matilainen 5004ac
 	    ds = rpmdsNew(h, tagN, 0);
Panu Matilainen 5004ac
 	}
Panu Matilainen 5004ac
+    } else {
Panu Matilainen 5004ac
+	PyErr_SetString(PyExc_TypeError, "header or tuple expected");
Panu Matilainen 5004ac
+	return NULL;
Panu Matilainen 5004ac
     }
Panu Matilainen 5004ac
     
Panu Matilainen 5004ac
-    if (ds == NULL) return NULL;
Panu Matilainen 5004ac
-	
Panu Matilainen 5004ac
     return rpmds_Wrap(subtype, ds);
Panu Matilainen 5004ac
 }
Panu Matilainen 5004ac