File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed
Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 1717#include <unistd.h>
1818#include <stdlib.h>
1919#include <libgen.h>
20+ #include <locale.h>
2021
2122#include "dbAccess.h"
2223#include "iocInit.h"
@@ -64,11 +65,29 @@ int main(int argc, char *argv[])
6465{
6566#if PY_MAJOR_VERSION == 2
6667 char * * python_argv = argv ;
68+
6769#else
6870 /* Alas, for Python3 we need convert argv from char** to wchar_t**. */
69- wchar_t * * python_argv = PyMem_Malloc (sizeof (wchar_t * ) * argc );
71+ wchar_t * * python_argv = PyMem_Malloc (sizeof (wchar_t * ) * (argc + 1 ));
72+ python_argv [argc ] = NULL ;
73+
74+ #if PY_MINOR_VERSION < 5
75+ /* This is a tricky space: we're supposed to use Py_DecodeLocale(), but
76+ * these versions of Python3 don't implement it yet. Do the simplest
77+ * workaround we can. This code is lifted from Python 3.4 Modules/python.c
78+ * and simplified as much as possible. */
79+ char * oldloc = strdup (setlocale (LC_ALL , NULL ));
80+ setlocale (LC_ALL , "" );
81+ for (int i = 0 ; i < argc ; i ++ )
82+ python_argv [i ] = _Py_char2wchar (argv [i ], NULL );
83+ setlocale (LC_ALL , oldloc );
84+ free (oldloc );
85+
86+ #else
87+ /* This seems to be the "correct" Python 3 way. */
7088 for (int i = 0 ; i < argc ; i ++ )
7189 python_argv [i ] = Py_DecodeLocale (argv [i ], NULL );
90+ #endif
7291#endif
7392
7493 if (LoadAndRegisterDbd ())
You can’t perform that action at this time.
0 commit comments