- for (i = 0; i < PyList_Size(py_cur_path); i++) {
- g_string_append(new_path, G_SEARCHPATH_SEPARATOR_S);
- py_item = PyList_GetItem(py_cur_path, i);
- if (!PyUnicode_Check(py_item))
- /* Shouldn't happen. */
- continue;
- if (py_str_as_str(py_item, &item) != SRD_OK)
- continue;
- g_string_append(new_path, item);
- g_free(item);
+ if (!py_cur_path)
+ return SRD_ERR_PYTHON;
+
+ py_item = PyUnicode_FromString(path);
+ if (!py_item) {
+ srd_exception_catch("Failed to create Unicode object");
+ return SRD_ERR_PYTHON;
+ }
+ if (PyList_Insert(py_cur_path, 0, py_item) < 0) {
+ srd_exception_catch("Failed to insert path element");
+ Py_DECREF(py_item);
+ return SRD_ERR_PYTHON;