From ac219c129d04952fbd205c536533723d582d1ad2 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 23 Sep 2009 12:05:02 +0300 Subject: Turn rpmFdFromPyObject() into an object converter interface - permits direct validation and conversion from arg parsing --- python/rpmfd-py.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'python/rpmfd-py.c') diff --git a/python/rpmfd-py.c b/python/rpmfd-py.c index 2deb06793..868c293da 100644 --- a/python/rpmfd-py.c +++ b/python/rpmfd-py.c @@ -2,7 +2,7 @@ #include "rpmsystem-py.h" #include "rpmfd-py.h" -FD_t rpmFdFromPyObject(PyObject *obj) +int rpmFdFromPyObject(PyObject *obj, FD_t *fdp) { FD_t fd = NULL; @@ -13,10 +13,13 @@ FD_t rpmFdFromPyObject(PyObject *obj) fd = fdDup(fileno(fp)); } else { PyErr_SetString(PyExc_TypeError, "integer or file object expected"); - return NULL; + return 0; } if (fd == NULL || Ferror(fd)) { PyErr_SetFromErrno(PyExc_IOError); + Fclose(fd); + return 0; } - return fd; + *fdp = fd; + return 1; } -- cgit v1.2.3