From 8f056c7849944abdf2e5ee86e8668bc6c61834ca Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Wed, 18 Nov 2009 17:03:32 +0200 Subject: Put a bit of sanity into python spec methods - prep, build etc missing from spec are not errors - instead of returning NULLs (with no exception set!), just return None for anything that doesn't exist - dont bother with NULL checks, if s->spec is NULL then something else has screwed up big time --- python/spec-py.c | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/python/spec-py.c b/python/spec-py.c index d2c0b301b..ddb9739df 100644 --- a/python/spec-py.c +++ b/python/spec-py.c @@ -43,63 +43,54 @@ spec_dealloc(specObject * s) Py_TYPE(s)->tp_free((PyObject *)s); } -/* XXX TODO return something sensible if spec exists but component (eg %clean) - * does not. Possibly "" or None */ - static PyObject * spec_get_buildroot(specObject * s) { rpmSpec spec = specFromSpec(s); - if (spec != NULL && spec->buildRoot) { + if (spec->buildRoot) { return Py_BuildValue("s", spec->buildRoot); } - else { - return NULL; - } + Py_RETURN_NONE; } static PyObject * spec_get_prep(specObject * s) { rpmSpec spec = specFromSpec(s); - PyObject *res = NULL; - if (spec != NULL && spec->prep) { - res = Py_BuildValue("s",getStringBuf(spec->prep)); + if (spec->prep) { + return Py_BuildValue("s",getStringBuf(spec->prep)); } - return res; + Py_RETURN_NONE; } static PyObject * spec_get_build(specObject * s) { rpmSpec spec = specFromSpec(s); - PyObject *res = NULL; - if (spec != NULL && spec->build) { - res = Py_BuildValue("s",getStringBuf(spec->build)); + if (spec->build) { + return Py_BuildValue("s",getStringBuf(spec->build)); } - return res; + Py_RETURN_NONE; } static PyObject * spec_get_install(specObject * s) { rpmSpec spec = specFromSpec(s); - PyObject *res = NULL; - if (spec != NULL && spec->install) { - res = Py_BuildValue("s",getStringBuf(spec->install)); + if (spec->install) { + return Py_BuildValue("s",getStringBuf(spec->install)); } - return res; + Py_RETURN_NONE; } static PyObject * spec_get_clean(specObject * s) { rpmSpec spec = specFromSpec(s); - PyObject *res = NULL; if (spec != NULL && spec->clean) { - res = Py_BuildValue("s",getStringBuf(spec->clean)); + return Py_BuildValue("s",getStringBuf(spec->clean)); } - return res; + Py_RETURN_NONE; } static PyObject * -- cgit v1.2.3