Enable kpythonpluginfactory to build for Python 3 as well. Should be
upstreamed after more testing.
Note: It is OK for the Python and Python3 versions to have the same name
because of the version specific ABI tags in Python 3 so files and the fact
that Python 3 interpreters will search for those first.
Copyright (C) 2012 Barry A. Warsaw <barry@python.org>
Index: pykde4-4.13.97/kpythonpluginfactory/kpythonpluginfactory.cpp
===================================================================
--- kpythonpluginfactory/kpythonpluginfactory.cpp.orig
+++ kpythonpluginfactory/kpythonpluginfactory.cpp
#include <kcomponentdata.h>
+#if PY_MAJOR_VERSION >= 3
This implements a plugin factory for running Python plugins. It also
supports io-slaves with a kdemain() entry point.
@@ -347,17 +351,48 @@ int kdemain( int argc, char **argv )
char *protocol = argv[1];
+ /* Python 3 requires wchar_t*s for its Py_SetProgramName() and
+ PySys_SetArgv() calls. Python 2 uses the typical char*s. This is
+ probably not the best way to do it, but the algorithm is based on
+ wchar_t **program_args = (wchar_t **)PyMem_Malloc(
+ sizeof(wchar_t *) * (argc + 1));
+ Py_FatalError("out of memory");
+ for (int i = 0; i < argc; i++) {
+ program_args[i] = (wchar_t *)PyMem_Malloc(
+ sizeof(wchar_t) * (strlen(argv[i]) + 1));
+ if (!program_args[i]) {
+ Py_FatalError("out of memory");
+ if (mbsrtowcs(program_args[i], &argv_i, strlen(argv[i]), NULL) < 0) {
+ /* The conversion failed. */
+ Py_FatalError("conversion to wchar_t* failed");
+ char **program_args = argv;
kDebug() << "Python kioslave starting";
KComponentData slave(protocol);
kDebug() << "Created KComponentData for protocol " << protocol;
QLibrary *pyLib = LoadPythonLibrary();
- Py_SetProgramName(argv[0]);