python: Fix error handling.
authorJustus Winter <justus@g10code.com>
Thu, 16 Feb 2017 13:42:17 +0000 (14:42 +0100)
committerJustus Winter <justus@g10code.com>
Thu, 16 Feb 2017 13:42:17 +0000 (14:42 +0100)
* lang/python/gpgme.i (typemap gpgme_key_t[]): Set an error if a
non-key element is discovered.

Signed-off-by: Justus Winter <justus@g10code.com>
lang/python/gpgme.i

index c7fc14e..3e89bb1 100644 (file)
 
       /* Following code is from swig's python.swg.  */
       if ((SWIG_ConvertPtr(pypointer,(void **) &$1[i], $*1_descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) {
-       Py_DECREF(pypointer);
+        Py_DECREF(pypointer);
+       PyErr_Format(PyExc_TypeError,
+                     "arg %d: list must contain only gpgme_key_ts, got %s "
+                     "at position %d",
+                     $argnum, pypointer->ob_type->tp_name, i);
+        free($1);
        return NULL;
       }
       Py_DECREF(pypointer);