Skip to content

Commit 8556089

Browse files
committed
Make get_string_from_python Python2 compatible
1 parent 132d21c commit 8556089

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/scorepy/pythonHelpers.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ auto cast_to_PyFunc(TFunc* func) -> detail::ReplaceArgsToPyObject_t<TFunc>*
7575

7676
inline CString get_string_from_python(PyObject& o)
7777
{
78+
#if PY_MAJOR_VERSION >= 3
7879
Py_ssize_t len;
7980
const char* s = PyUnicode_AsUTF8AndSize(&o, &len);
8081
return CString(s, len);
82+
#else
83+
const char* s = PyString_AsString(&o);
84+
return CString(s);
85+
#endif
8186
}
8287

8388
/// Pair of a C-String and it's length useful for PyArg_ParseTuple with 's#'

0 commit comments

Comments
 (0)