X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoder.c;h=71e9122181324fad0325314ddbf78eb75f2fc1a6;hb=d45058e87e7045fef1b7c4425de1917a554545f7;hp=f31202b1937ef5690dae41d8f7e18f713c171c9b;hpb=6a15597a7b3f901b566b7bfc8c484a14e0fb6a11;p=libsigrokdecode.git diff --git a/decoder.c b/decoder.c index f31202b..71e9122 100644 --- a/decoder.c +++ b/decoder.c @@ -40,19 +40,29 @@ /** @cond PRIVATE */ /* The list of protocol decoders. */ -SRD_PRIV GSList *pd_list = NULL; +static GSList *pd_list = NULL; /* srd.c */ -extern GSList *searchpaths; +extern SRD_PRIV GSList *searchpaths; /* session.c */ -extern GSList *sessions; +extern SRD_PRIV GSList *sessions; +extern SRD_PRIV int max_session_id; /* module_sigrokdecode.c */ extern SRD_PRIV PyObject *mod_sigrokdecode; /** @endcond */ +static gboolean srd_check_init(void) +{ + if (max_session_id < 0) { + srd_err("Library is not initialized."); + return FALSE; + } else + return TRUE; +} + /** * Returns the list of supported/loaded protocol decoders. * @@ -60,7 +70,7 @@ extern SRD_PRIV PyObject *mod_sigrokdecode; * * @return List of decoders, NULL if none are supported or loaded. * - * @since 0.1.0 (but the API changed in 0.2.0) + * @since 0.2.0 */ SRD_API const GSList *srd_decoder_list(void) { @@ -356,6 +366,17 @@ SRD_API int srd_decoder_load(const char *module_name) } Py_CLEAR(py_basedec); + /* + * Check that thіs decoder has the correct PD API version. + * PDs of different API versions are incompatible and cannot work. + */ + py_long = PyObject_GetAttrString(d->py_dec, "api_version"); + if (PyLong_AsLong(py_long) != 2) { + srd_err("Only PDs of API version 2 are supported."); + goto err_out; + } + Py_CLEAR(py_long); + /* Check for a proper start() method. */ if (!PyObject_HasAttrString(d->py_dec, "start")) { srd_err("Protocol decoder %s has no start() method Decoder "