X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fpython.c;h=e7795c751ef757fc2c97611d0838035df3b79acf;hb=9b7dee8838f56233cea2854a7ddbcad2790609ce;hp=af2dc5b69d2f84b8dc83e5895fb126078470b652;hpb=b9ebf85bd59b7b314b2b37c8a3357ab51b534581;p=collectd.git diff --git a/src/python.c b/src/python.c index af2dc5b6..e7795c75 100644 --- a/src/python.c +++ b/src/python.c @@ -302,7 +302,7 @@ void cpy_log_exception(const char *context) { Py_XDECREF(traceback); return; } - list = PyObject_CallFunction(cpy_format_exception, "NNN", type, value, traceback); /* New reference. */ + list = PyObject_CallFunction(cpy_format_exception, "NNN", type, value, traceback); /* New reference. Steals references from "type", "value" and "traceback". */ if (list) l = PyObject_Length(list); for (i = 0; i < l; ++i) { @@ -322,9 +322,6 @@ void cpy_log_exception(const char *context) { } Py_XDECREF(list); PyErr_Clear(); - Py_DECREF(type); - Py_XDECREF(value); - Py_XDECREF(traceback); } static int cpy_read_callback(user_data_t *data) { @@ -1034,13 +1031,15 @@ PyMODINIT_FUNC PyInit_collectd(void) { #endif static int cpy_init_python() { - char *argv = ""; PyObject *sys; PyObject *module; #ifdef IS_PY3K + wchar_t *argv = L""; /* Add a builtin module, before Py_Initialize */ PyImport_AppendInittab("collectd", PyInit_collectd); +#else + char *argv = ""; #endif Py_Initialize(); @@ -1117,9 +1116,13 @@ static int cpy_config(oconfig_item_t *ci) { } else if (strcasecmp(item->key, "Encoding") == 0) { if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_STRING) continue; +#ifdef IS_PY3K + NOTICE("python: \"Encoding\" was used in the config file but Python3 was used, which does not support changing encodings. Ignoring this."); +#else /* Why is this even necessary? And undocumented? */ if (PyUnicode_SetDefaultEncoding(item->values[0].value.string)) cpy_log_exception("setting default encoding"); +#endif } else if (strcasecmp(item->key, "LogTraces") == 0) { if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN) continue; @@ -1153,8 +1156,8 @@ static int cpy_config(oconfig_item_t *ci) { cpy_log_exception("python initialization"); continue; } - if (PyList_Append(sys_path, dir_object) != 0) { - ERROR("python plugin: Unable to append \"%s\" to " + if (PyList_Insert(sys_path, 0, dir_object) != 0) { + ERROR("python plugin: Unable to prepend \"%s\" to " "python module path.", dir); cpy_log_exception("python initialization"); }