From b9116a1142083f73047cf93f4c97447e5656a1d2 Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Thu, 23 Mar 2017 10:03:25 +0100 Subject: [PATCH] Python 3.4: redefine Py_DecodeLocale --- src/SUITApp/SUITApp_init_python.cxx | 29 ++++++++++++++++++++++++++ tools/PyInterp/src/PyInterp_Interp.cxx | 29 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/src/SUITApp/SUITApp_init_python.cxx b/src/SUITApp/SUITApp_init_python.cxx index 06d2b8af0..7f5d7021c 100644 --- a/src/SUITApp/SUITApp_init_python.cxx +++ b/src/SUITApp/SUITApp_init_python.cxx @@ -23,6 +23,35 @@ #include "SUITApp_init_python.hxx" #include +#if PY_VERSION_HEX < 0x03050000 +static wchar_t* +Py_DecodeLocale(const char *arg, size_t *size) +{ + wchar_t *res; + unsigned char *in; + wchar_t *out; + size_t argsize = strlen(arg) + 1; + + if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t)) + return NULL; + res = (wchar_t*) PyMem_RawMalloc(argsize*sizeof(wchar_t)); + if (!res) + return NULL; + + in = (unsigned char*)arg; + out = res; + while(*in) + if(*in < 128) + *out++ = *in++; + else + *out++ = 0xdc00 + *in++; + *out = 0; + if (size != NULL) + *size = out - res; + return res; +} +#endif + bool SUIT_PYTHON::initialized = false; void SUIT_PYTHON::init_python(int argc, char **argv) diff --git a/tools/PyInterp/src/PyInterp_Interp.cxx b/tools/PyInterp/src/PyInterp_Interp.cxx index 27703c2a0..4b8f8fe76 100644 --- a/tools/PyInterp/src/PyInterp_Interp.cxx +++ b/tools/PyInterp/src/PyInterp_Interp.cxx @@ -40,6 +40,35 @@ #define TOP_HISTORY_PY "--- top of history ---" #define BEGIN_HISTORY_PY "--- begin of history ---" +#if PY_VERSION_HEX < 0x03050000 +static wchar_t* +Py_DecodeLocale(const char *arg, size_t *size) +{ + wchar_t *res; + unsigned char *in; + wchar_t *out; + size_t argsize = strlen(arg) + 1; + + if (argsize > PY_SSIZE_T_MAX/sizeof(wchar_t)) + return NULL; + res = (wchar_t*) PyMem_RawMalloc(argsize*sizeof(wchar_t)); + if (!res) + return NULL; + + in = (unsigned char*)arg; + out = res; + while(*in) + if(*in < 128) + *out++ = *in++; + else + *out++ = 0xdc00 + *in++; + *out = 0; + if (size != NULL) + *size = out - res; + return res; +} +#endif + /* The following functions are used to hook the Python interpreter output. -- 2.39.2