From 920d5eaaa68c8e1184fa7066f8e962c3b4e384db Mon Sep 17 00:00:00 2001 From: Sven Trenkel Date: Fri, 9 Jan 2015 21:28:24 +0000 Subject: [PATCH] Fix compiler warnings with Python3. https://github.com/collectd/collectd/issues/505 --- src/collectd-python.pod | 8 +++++--- src/python.c | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/collectd-python.pod b/src/collectd-python.pod index fc5376ed..ac88f036 100644 --- a/src/collectd-python.pod +++ b/src/collectd-python.pod @@ -57,9 +57,11 @@ modules, e.g. "time". =item B I The default encoding for Unicode objects you pass to collectd. If you omit this -option it will default to B on I and B on I. -This is hardcoded in Python and will ignore everything else, including your -locale. +option it will default to B on I. On I it will +always be B, as this function was removed, so this will be silently +ignored. +These defaults are hardcoded in Python and will ignore everything else, +including your locale. =item B I diff --git a/src/python.c b/src/python.c index af2dc5b6..928c921b 100644 --- a/src/python.c +++ b/src/python.c @@ -1034,13 +1034,15 @@ PyMODINIT_FUNC PyInit_collectd(void) { #endif static int cpy_init_python() { - char *argv = ""; PyObject *sys; PyObject *module; #ifdef IS_PY3K + wchar_t *argv = {0}; /* Add a builtin module, before Py_Initialize */ PyImport_AppendInittab("collectd", PyInit_collectd); +#else + char *argv = ""; #endif Py_Initialize(); @@ -1117,9 +1119,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; -- 2.11.0