diff options
Diffstat (limited to 'pyhelpers/vector_uint8.hpp')
-rw-r--r-- | pyhelpers/vector_uint8.hpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/pyhelpers/vector_uint8.hpp b/pyhelpers/vector_uint8.hpp index 3f74e97445..d10a417c44 100644 --- a/pyhelpers/vector_uint8.hpp +++ b/pyhelpers/vector_uint8.hpp @@ -16,16 +16,21 @@ namespace { using namespace boost::python; -// Converts a vector<uint8_t> to/from Python str. +// Converts a vector<uint8_t> to Python2 str or Python3 bytes. struct vector_uint8t_to_str { static PyObject * convert(std::vector<uint8_t> const & v) { - str s(reinterpret_cast<char const *>(v.data()), v.size()); - return incref(s.ptr()); + auto bytes = PyBytes_FromStringAndSize( + reinterpret_cast<char const *>(v.data()), + v.size()); + Py_INCREF(bytes); + + return bytes; } }; +// Converts a vector<uint8_t> from Python2 str or Python3 bytes. struct vector_uint8t_from_python_str { vector_uint8t_from_python_str() |