Skip to content

Commit

Permalink
Make get_string_from_python Python2 compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamefire committed Apr 21, 2021
1 parent 132d21c commit 8556089
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/scorepy/pythonHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ auto cast_to_PyFunc(TFunc* func) -> detail::ReplaceArgsToPyObject_t<TFunc>*

inline CString get_string_from_python(PyObject& o)
{
#if PY_MAJOR_VERSION >= 3
Py_ssize_t len;
const char* s = PyUnicode_AsUTF8AndSize(&o, &len);
return CString(s, len);
#else
const char* s = PyString_AsString(&o);
return CString(s);
#endif
}

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

0 comments on commit 8556089

Please sign in to comment.