From 32e566da5d4b7282ee463f2e2ad1afb873da9bb7 Mon Sep 17 00:00:00 2001 From: Sergey Magidovich Date: Wed, 12 Apr 2017 13:56:51 +0300 Subject: Fix vector_uint8t_to_str to work woth both python 2 and 3. --- pyhelpers/vector_uint8.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'pyhelpers') 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 to/from Python str. +// Converts a vector to Python2 str or Python3 bytes. struct vector_uint8t_to_str { static PyObject * convert(std::vector const & v) { - str s(reinterpret_cast(v.data()), v.size()); - return incref(s.ptr()); + auto bytes = PyBytes_FromStringAndSize( + reinterpret_cast(v.data()), + v.size()); + Py_INCREF(bytes); + + return bytes; } }; +// Converts a vector from Python2 str or Python3 bytes. struct vector_uint8t_from_python_str { vector_uint8t_from_python_str() -- cgit v1.2.3