]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
[PY3] Simplification of Py_EncodeLocale and Py_DecodeLocale
authorGilles DAVID <gilles-g.david@edf.fr>
Thu, 20 Apr 2017 14:58:26 +0000 (16:58 +0200)
committerGilles DAVID <gilles-g.david@edf.fr>
Thu, 20 Apr 2017 14:58:26 +0000 (16:58 +0200)
src/Container/Container_init_python.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx

index e4963c0a2ae8b3a2e35ad9d75c381fc27eaa3983..d5e58db8b55b23fc7b584dd2f7367b16c9552a3b 100644 (file)
 #include "Container_init_python.hxx"
 
 #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 4127b0b0eefc68220dcf2ff90c49c3f53c534b28..3892e1ec4526a3ff23191775882e05cca0f4dcde 100644 (file)
@@ -47,31 +47,15 @@ using namespace SALOMESDS;
 std::size_t DataScopeServerBase::COUNTER=0;
 
 #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