From: Bert Vermeulen Date: Mon, 18 Nov 2013 09:44:28 +0000 (+0100) Subject: Don't try to load an already-loaded module X-Git-Tag: libsigrokdecode-0.3.0~221 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=aac68131f8ab9aa6dc1f1392a4f9a131a1c54d36;p=libsigrokdecode.git Don't try to load an already-loaded module Python silently uses the existing module anyway, but the library was counting it as an extra module. This was exposed by a test case in the test suite. --- diff --git a/decoder.c b/decoder.c index f6032f5..e3ffb01 100644 --- a/decoder.c +++ b/decoder.c @@ -260,6 +260,11 @@ SRD_API int srd_decoder_load(const char *module_name) if (!module_name) return SRD_ERR_ARG; + if (PyDict_GetItemString(PyImport_GetModuleDict(), module_name)) { + /* Module was already imported. */ + return SRD_OK; + } + srd_dbg("Loading protocol decoder '%s'.", module_name); py_basedec = py_method = py_attr = NULL;