diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2011-01-27 23:02:39 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2011-01-27 23:02:39 +0100 |
commit | f7313eeaf3b64fafa792a225a2b70c745e8d5cc6 (patch) | |
tree | 14002254cbb20966dd7308dbe15c297814cde807 | |
parent | 2557ad9d2de490cab14ae0b3a197de2b1c7f9f21 (diff) | |
download | libsigrokdecode-f7313eeaf3b64fafa792a225a2b70c745e8d5cc6.tar.gz libsigrokdecode-f7313eeaf3b64fafa792a225a2b70c745e8d5cc6.zip |
Some more simplifications in decode.c.
-rw-r--r-- | decode.c | 36 |
1 files changed, 19 insertions, 17 deletions
@@ -107,14 +107,12 @@ static int h_str(PyObject *py_res, PyObject *py_func, PyObject *py_mod, { PyObject *py_str; char *str; + int ret; py_str = PyMapping_GetItemString(py_res, (char *)key); if (!py_str || !PyString_Check(py_str)) { - if (PyErr_Occurred()) - PyErr_Print(); /* Returns void. */ - Py_XDECREF(py_func); - Py_XDECREF(py_mod); - return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */ + ret = SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */ + goto err_h_decref_func; } /* @@ -123,26 +121,30 @@ static int h_str(PyObject *py_res, PyObject *py_func, PyObject *py_mod, * must not be free()'d. */ if (!(str = PyString_AsString(py_str))) { - if (PyErr_Occurred()) - PyErr_Print(); /* Returns void. */ - Py_XDECREF(py_str); - Py_XDECREF(py_func); - Py_XDECREF(py_mod); - return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */ + ret = SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */ + goto err_h_decref_str; } if (!(*outstr = strdup(str))) { - if (PyErr_Occurred()) - PyErr_Print(); /* Returns void. */ - Py_XDECREF(py_str); - Py_XDECREF(py_func); - Py_XDECREF(py_mod); - return SIGROKDECODE_ERR_MALLOC; + ret = SIGROKDECODE_ERR_MALLOC; + goto err_h_decref_str; } Py_XDECREF(py_str); return SIGROKDECODE_OK; + +err_h_decref_str: + Py_XDECREF(py_str); +err_h_decref_func: + Py_XDECREF(py_func); +err_h_decref_mod: + Py_XDECREF(py_mod); + + if (PyErr_Occurred()) + PyErr_Print(); /* Returns void. */ + + return ret; } /** |