From f316b98f45d23964056c10a7d99a3985ee5f2330 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber <thomas.pointhuber@gmx.at> Date: Mon, 6 Aug 2018 12:31:50 +0200 Subject: [PATCH] Fix conversation of Python 3 str -> wxString Conversation of a NoneType for example failed before --- common/swig/wx_python_helpers.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/common/swig/wx_python_helpers.cpp b/common/swig/wx_python_helpers.cpp index 0a1301b774..2d2b55fd8c 100644 --- a/common/swig/wx_python_helpers.cpp +++ b/common/swig/wx_python_helpers.cpp @@ -81,6 +81,11 @@ wxString* newWxStringFromPy( PyObject* src ) #endif { obj = PyObject_Str( src ); + +#if PY_MAJOR_VERSION >= 3 + uni_str = obj; // in case of Python 3 our string is already correctly encoded +#endif + must_unref_obj = true; if( PyErr_Occurred() ) @@ -101,7 +106,11 @@ wxString* newWxStringFromPy( PyObject* src ) } result = new wxString(); +#if PY_MAJOR_VERSION >= 3 + size_t len = PyUnicode_GET_LENGTH( uni_str ); +#else size_t len = PyUnicode_GET_SIZE( uni_str ); +#endif if( len ) {