From: Ovidiu Mircescu Date: Mon, 1 Oct 2018 12:29:08 +0000 (+0200) Subject: Porting SWIG to Python3. X-Git-Tag: V2_4_1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8ab8764737a35352c010970946ec6634737d94d2;p=tools%2Flibbatch.git Porting SWIG to Python3. --- diff --git a/src/Python/libBatch_Swig_typemap.i b/src/Python/libBatch_Swig_typemap.i index cbd1a23..5e23259 100644 --- a/src/Python/libBatch_Swig_typemap.i +++ b/src/Python/libBatch_Swig_typemap.i @@ -43,22 +43,35 @@ # %typemap(in) SWIGTYPE ; %{ +static std::string pystr2stdstr(PyObject * val) +{ + std::string str_val; + if (PyUnicode_Check(val)) + { + PyObject * temp_bytes = PyUnicode_AsEncodedString(val, "UTF-8", "strict"); + if (temp_bytes != NULL) + { + str_val = PyBytes_AS_STRING(temp_bytes); + Py_DECREF(temp_bytes); + } + } + return str_val; +} + // Helper function to initialize a Batch::Versatile from a PyObj static bool initVersatile(Batch::Versatile & newVersatile, PyObject * input) { if (PyList_Check(input)) { // c'est une liste for (Py_ssize_t i=0; i