X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=controller.c;h=c913fd259355d905546a26c8d6437f88a09a215d;hp=845208a7c2f5041a9e471ba101f58b932ecb56c0;hb=58572aed02d81e2cc75749c2c4b516538b5ca9b9;hpb=be873260307fb879200ace642c15164c39234007 diff --git a/controller.c b/controller.c index 845208a..c913fd2 100644 --- a/controller.c +++ b/controller.c @@ -118,10 +118,19 @@ int srd_exit(void) /** - * Add search directories for the protocol decoders. + * Add an additional search directory for the protocol decoders. + * + * The specified directory is prepended (not appended!) to Python's sys.path, + * in order to search for sigrok protocol decoders in the specified + * directories first, and in the generic Python module directories (and in + * the current working directory) last. This avoids conflicts if there are + * Python modules which have the same name as a sigrok protocol decoder in + * sys.path or in the current working directory. * * TODO: add path from env var SIGROKDECODE_PATH, config etc * TODO: Should take directoryname/path as input. + * + * @return TODO. */ int set_modulepath(void) { @@ -143,9 +152,8 @@ int set_modulepath(void) 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); + s = g_strdup_printf("import sys; sys.path.insert(0, r'%s')", path); ret = PyRun_SimpleString(s); @@ -655,7 +663,7 @@ int pd_add(struct srd_decoder_instance *di, int output_type, /* pdo_id is just a simple index, nothing is deleted from this list anyway. */ pdo->pdo_id = g_slist_length(di->pd_output); pdo->output_type = output_type; - pdo->decoder = di->decoder; + pdo->di = di; pdo->proto_id = g_strdup(proto_id); di->pd_output = g_slist_append(di->pd_output, pdo);