MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / srd_decoder_searchpath_add

Function srd_decoder_searchpath_add

libsigrokdecode4DSL/srd.c:340–376  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

338 * @since 0.1.0
339 */
340SRD_PRIV int srd_decoder_searchpath_add(const char *path)
341{
342 PyGILState_STATE gstate;
343
344 srd_dbg("Adding '%s' to module path.", path);
345
346 gstate = PyGILState_Ensure();
347
348 PyObject *py_cur_path, *py_item;
349 py_cur_path = PySys_GetObject("path");
350 if (!py_cur_path)
351 goto err;
352
353 py_item = PyUnicode_FromString(path);
354 if (!py_item) {
355 srd_exception_catch(NULL, "Failed to create Unicode object");
356 goto err;
357 }
358 if (PyList_Insert(py_cur_path, 0, py_item) < 0) {
359 srd_exception_catch(NULL, "Failed to insert path element");
360 Py_DECREF(py_item);
361 goto err;
362 }
363 Py_DECREF(py_item);
364
365 PyGILState_Release(gstate);
366
367 //append the directory to search list
368 searchpaths = g_slist_prepend(searchpaths, g_strdup(path));
369
370 return SRD_OK;
371
372err:
373 PyGILState_Release(gstate);
374
375 return SRD_ERR_PYTHON;
376}
377
378/**
379 * Return the list of protocol decoder search paths.

Callers 2

searchpath_add_xdg_dirFunction · 0.85
srd_initFunction · 0.85

Calls 1

srd_exception_catchFunction · 0.85

Tested by

no test coverage detected