diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2011-01-27 23:12:34 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2011-01-27 23:12:34 +0100 |
commit | c7bb5dff3a5259ce7e59db7932580173462b00a1 (patch) | |
tree | 044bf66b7686ab750bf1883ec91f0139e2ad6ecd | |
parent | f7313eeaf3b64fafa792a225a2b70c745e8d5cc6 (diff) | |
download | libsigrokdecode-c7bb5dff3a5259ce7e59db7932580173462b00a1.tar.gz libsigrokdecode-c7bb5dff3a5259ce7e59db7932580173462b00a1.zip |
decode.c: Simplify the import code.
Use PyImport_ImportModule() instead of PyImport_Import(), so we don't
have to temporarily create a py_name object.
-rw-r--r-- | decode.c | 12 |
1 files changed, 2 insertions, 10 deletions
@@ -158,22 +158,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 */ |