]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
[PY3] Rewriting of Py_EncodeLocale and Py_DecodeLocale (python < 3.5)
authorGilles DAVID <gilles-g.david@edf.fr>
Thu, 30 Mar 2017 14:53:33 +0000 (16:53 +0200)
committerGilles DAVID <gilles-g.david@edf.fr>
Thu, 30 Mar 2017 14:53:33 +0000 (16:53 +0200)
src/SUITApp/SUITApp_init_python.cxx
tools/PyInterp/src/PyInterp_Interp.cxx
tools/PyInterp/src/PyInterp_Utils.h

index 7f5d7021c615fdec6cdc78e318dec148ba076a59..3724dd562f3ecacc73f235f0909820712faed73c 100644 (file)
 #include <QString>
 
 #if PY_VERSION_HEX < 0x03050000
+static char*
+Py_EncodeLocale(const wchar_t *arg, size_t *size)
+{
+       return _Py_wchar2char(arg, size);
+}
 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;
+       return _Py_char2wchar(arg, size);
 }
 #endif
 
index 4b8f8fe766059122c01860a840952a648c83c1d3..27703c2a010cf94a6e927a1659d28893d35eb055 100644 (file)
 #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.
index d47ff184697451fab277c7778f0c3da609aedc66..7ad22d962521bf792f4064d1f26b711b59750faa 100644 (file)
   #include <iostream>
 #endif
 
+#if PY_VERSION_HEX < 0x03050000
+static char*
+Py_EncodeLocale(const wchar_t *arg, size_t *size)
+{
+       return _Py_wchar2char(arg, size);
+}
+static wchar_t*
+Py_DecodeLocale(const char *arg, size_t *size)
+{
+       return _Py_char2wchar(arg, size);
+}
+#endif
+
 /**
  * \class PyLockWrapper
  * \brief Python GIL wrapper.