* 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
| 338 | * @since 0.1.0 |
| 339 | */ |
| 340 | SRD_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 | |
| 372 | err: |
| 373 | PyGILState_Release(gstate); |
| 374 | |
| 375 | return SRD_ERR_PYTHON; |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Return the list of protocol decoder search paths. |
no test coverage detected