Skip to content

Commit 37f1791

Browse files
author
mga83
committed
Looks like Python3.4 and earlier need different startup code
git-svn-id: svn+ssh://serv0002.cs.diamond.ac.uk/home/subversion/repos/controls/diamond/trunk/support/pythonSoftIoc@166280 e099a375-04f9-0310-9d5f-a741eaff62e1
1 parent 1856082 commit 37f1791

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

softIocApp/softMain.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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())

0 commit comments

Comments
 (0)