summaryrefslogtreecommitdiff
path: root/src/pyutils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/pyutils.h')
-rw-r--r--src/pyutils.h4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/pyutils.h b/src/pyutils.h
index 641dbd3b..323ffe02 100644
--- a/src/pyutils.h
+++ b/src/pyutils.h
@@ -130,8 +130,12 @@ template <typename T>
PyObject * str_to_py_unicode(const T& str)
{
using namespace boost::python;
+#if PY_MAJOR_VERSION >= 3
+ PyObject * uni = PyUnicode_FromString(str.c_str());
+#else
PyObject * pstr = PyString_FromString(str.c_str());
PyObject * uni = PyUnicode_FromEncodedObject(pstr, "UTF-8", NULL);
+#endif
return object(handle<>(borrowed(uni))).ptr();
}