Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Magidovich <mgsergio@mapswithme.com>2017-04-12 13:56:51 +0300
committerSergey Magidovich <mgsergio@mapswithme.com>2017-04-12 13:56:51 +0300
commit32e566da5d4b7282ee463f2e2ad1afb873da9bb7 (patch)
treeadc6d7dc9f8620279ab0cfc303a2322d7e3cc3b6 /pyhelpers
parent2ecff49a9aaed92d42f9510ade1f7006eca80b24 (diff)
Fix vector_uint8t_to_str to work woth both python 2 and 3.
Diffstat (limited to 'pyhelpers')
-rw-r--r--pyhelpers/vector_uint8.hpp11
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()