X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=controller.c;h=ebda088932ea4885f5b834c81e0b914773ee137e;hp=6bb7748ef05eee8b9890a665289f867a08833389;hb=21481b6609641fb3076290dad915a3a6259ce05a;hpb=0bdadba205a6d7688a2bb8d98ab342abe22acd6e diff --git a/controller.c b/controller.c index 6bb7748..ebda088 100644 --- a/controller.c +++ b/controller.c @@ -114,13 +114,36 @@ int srd_exit(void) * Add search directories for the protocol decoders. * * TODO: add path from env var SIGROKDECODE_PATH, config etc + * TODO: Should take directoryname/path as input. */ int set_modulepath(void) { int ret; + gchar *path, *s; - PyRun_SimpleString("import sys"); - ret = PyRun_SimpleString("sys.path.append(r'" DECODERS_DIR "');"); +#ifdef _WIN32 + gchar **splitted; + + /* + * On Windows/MinGW, Python's sys.path needs entries of the form + * 'C:\\foo\\bar' instead of '/foo/bar'. + */ + + splitted = g_strsplit(DECODERS_DIR, "/", 0); + path = g_build_pathv("\\\\", splitted); + g_strfreev(splitted); +#else + path = g_strdup(DECODERS_DIR); +#endif + + /* TODO: Prepend instead of appending. */ + /* TODO: Sanity check on 'path' (length, escape special chars, ...). */ + s = g_strdup_printf("import sys; sys.path.append(r'%s')", path); + + ret = PyRun_SimpleString(s); + + g_free(path); + g_free(s); return ret; } @@ -146,13 +169,17 @@ int srd_instance_set_options(struct srd_decoder_instance *di, int num_optkeys, ret, size, i; char *key, *value; - if (g_hash_table_size(options) == 0) - /* No options provided. */ - return SRD_OK; - - if(!PyObject_HasAttrString(di->decoder->py_dec, "options")) + if(!PyObject_HasAttrString(di->decoder->py_dec, "options")) { /* Decoder has no options. */ + if (g_hash_table_size(options) == 0) { + /* No options provided. */ + return SRD_OK; + } else { + srd_err("Protocol decoder has no options."); + return SRD_ERR_ARG; + } return SRD_OK; + } ret = SRD_ERR_PYTHON; key = NULL; @@ -177,6 +204,10 @@ int srd_instance_set_options(struct srd_decoder_instance *di, goto err_out; if (!(py_classval = PyList_GetItem(py_optlist, 1))) goto err_out; + if (!PyUnicode_Check(py_classval) && !PyLong_Check(py_classval)) { + srd_err("Options of type %s are not yet supported.", Py_TYPE(py_classval)->tp_name); + goto err_out; + } if ((value = g_hash_table_lookup(options, key))) { /* An override for this option was provided. */