diff options
author | Bert Vermeulen <bert@biot.com> | 2013-11-18 01:21:16 +0100 |
---|---|---|
committer | Bert Vermeulen <bert@biot.com> | 2013-11-18 01:21:16 +0100 |
commit | e195c025c303e361d0cc5a207f9c9443fb8deced (patch) | |
tree | 86e05c7d93dc5b77c1510519659763929cc5eee5 | |
parent | 909fbf4181ab401a371265567505ffa1403f73d6 (diff) | |
download | libsigrokdecode-e195c025c303e361d0cc5a207f9c9443fb8deced.tar.gz libsigrokdecode-e195c025c303e361d0cc5a207f9c9443fb8deced.zip |
Check library initialization before handling decoders
-rw-r--r-- | decoder.c | 18 | ||||
-rw-r--r-- | libsigrokdecode-internal.h | 1 | ||||
-rw-r--r-- | srd.c | 10 |
3 files changed, 29 insertions, 0 deletions
@@ -253,6 +253,9 @@ SRD_API int srd_decoder_load(const char *module_name) struct srd_probe *p; GSList *l; + if (!srd_check_init()) + return SRD_ERR; + if (!module_name) return SRD_ERR_ARG; @@ -446,6 +449,12 @@ SRD_API char *srd_decoder_doc_get(const struct srd_decoder *dec) PyObject *py_str; char *doc; + if (!srd_check_init()) + return NULL; + + if (!dec) + return NULL; + if (!PyObject_HasAttrString(dec->py_mod, "__doc__")) return NULL; @@ -495,6 +504,12 @@ SRD_API int srd_decoder_unload(struct srd_decoder *dec) struct srd_session *sess; GSList *l; + if (!srd_check_init()) + return SRD_ERR; + + if (!dec) + return SRD_ERR_ARG; + srd_dbg("Unloading protocol decoder '%s'.", dec->name); /* @@ -548,6 +563,9 @@ SRD_API int srd_decoder_load_all(void) GError *error; const gchar *direntry; + if (!srd_check_init()) + return SRD_ERR; + if (!(dir = g_dir_open(DECODERS_DIR, 0, &error))) { srd_err("Unable to open %s for reading.", DECODERS_DIR); return SRD_ERR_DECODERS_DIR; diff --git a/libsigrokdecode-internal.h b/libsigrokdecode-internal.h index 8fd9e52..aa626ca 100644 --- a/libsigrokdecode-internal.h +++ b/libsigrokdecode-internal.h @@ -37,6 +37,7 @@ struct srd_session { /* srd.c */ SRD_PRIV int srd_decoder_searchpath_add(const char *path); +SRD_PRIV gboolean srd_check_init(void); /* session.c */ SRD_PRIV int session_is_valid(struct srd_session *sess); @@ -263,4 +263,14 @@ SRD_PRIV int srd_decoder_searchpath_add(const char *path) return SRD_OK; } +/* @private */ +SRD_PRIV gboolean srd_check_init(void) +{ + if (max_session_id < 0) { + srd_err("Library is not initialized."); + return FALSE; + } else + return TRUE; +} + /** @} */ |