]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Python 3.4: redefine Py_DecodeLocale
authorGilles DAVID <gilles-g.david@edf.fr>
Wed, 22 Mar 2017 10:12:45 +0000 (11:12 +0100)
committerGilles DAVID <gilles-g.david@edf.fr>
Wed, 22 Mar 2017 10:12:48 +0000 (11:12 +0100)
The code from decode_ascii_surrogateescape in Python 3.5 was reused.

src/Container/Container_init_python.cxx
src/SALOMESDS/SALOMESDS_DataScopeServer.cxx

index 42ab6eaac4da809830ff83bc05fbf21bd7510f63..e4963c0a2ae8b3a2e35ad9d75c381fc27eaa3983 100644 (file)
 #include "utilities.h"
 #include "Container_init_python.hxx"
 
+#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
+
 void KERNEL_PYTHON::init_python(int argc, char **argv)
 {
   if (Py_IsInitialized())
index f8e9b9b7694a800cdd33d4da44add878c4d8e4df..f55c903bc7524d8e77606444081a3a162e4e8b90 100644 (file)
@@ -46,6 +46,35 @@ using namespace SALOMESDS;
 
 std::size_t DataScopeServerBase::COUNTER=0;
 
+#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
+
 void DataScopeKiller::shutdown()
 {
   Py_Finalize();