From c328fcedc732946210a08cd668df87186842a0bb Mon Sep 17 00:00:00 2001 From: Gilles DAVID Date: Thu, 20 Apr 2017 16:58:26 +0200 Subject: [PATCH] [PY3] Simplification of Py_EncodeLocale and Py_DecodeLocale --- src/Container/Container_init_python.cxx | 28 +++++---------------- src/SALOMESDS/SALOMESDS_DataScopeServer.cxx | 28 +++++---------------- 2 files changed, 12 insertions(+), 44 deletions(-) diff --git a/src/Container/Container_init_python.cxx b/src/Container/Container_init_python.cxx index e4963c0a2..d5e58db8b 100644 --- a/src/Container/Container_init_python.cxx +++ b/src/Container/Container_init_python.cxx @@ -30,31 +30,15 @@ #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 diff --git a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx index 4127b0b0e..3892e1ec4 100644 --- a/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx +++ b/src/SALOMESDS/SALOMESDS_DataScopeServer.cxx @@ -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 -- 2.39.2