]> sigrok.org Git - libsigrokdecode.git/blobdiff - decode.c
Fix some compiler warnings.
[libsigrokdecode.git] / decode.c
index 057515f35509b50323780cf376565641f1da9832..b1acff476a7a9568f4ca6d56222154c088638083 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -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,29 @@ 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);
+       Py_XDECREF(py_mod);
+
+       if (PyErr_Occurred())
+               PyErr_Print(); /* Returns void. */
+
+       return ret;
 }
 
 /**
@@ -156,22 +157,14 @@ int sigrokdecode_load_decoder(const char *name,
                              struct sigrokdecode_decoder **dec)
 {
        struct sigrokdecode_decoder *d;
-       PyObject *py_name, *py_mod, *py_func, *py_res /* , *py_tuple */;
+       PyObject *py_mod, *py_func, *py_res /* , *py_tuple */;
        int r;
 
-       /* Get the name of the decoder module as Python string. */
-       if (!(py_name = PyString_FromString(name))) { /* NEWREF */
-               PyErr_Print(); /* Returns void. */
-               return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
-       }
-
        /* "Import" the Python module. */
-       if (!(py_mod = PyImport_Import(py_name))) { /* NEWREF */
+       if (!(py_mod = PyImport_ImportModule(name))) { /* NEWREF */
                PyErr_Print(); /* Returns void. */
-               Py_XDECREF(py_name);
                return SIGROKDECODE_ERR_PYTHON; /* TODO: More specific error? */
        }
-       Py_XDECREF(py_name);
 
        /* Get the 'register' function name as Python callable object. */
        py_func = PyObject_GetAttrString(py_mod, "register"); /* NEWREF */
@@ -307,7 +300,6 @@ err_run_decref_args:
        Py_XDECREF(py_args);
 err_run_decref_func:
        Py_XDECREF(py_func);
-err_run_decref_mod:
        Py_XDECREF(py_mod);
 
        if (PyErr_Occurred())