diff --git a/include/boost/python/converter/builtin_converters.hpp b/include/boost/python/converter/builtin_converters.hpp index aebfd459..3b3a473b 100644 --- a/include/boost/python/converter/builtin_converters.hpp +++ b/include/boost/python/converter/builtin_converters.hpp @@ -102,7 +102,7 @@ BOOST_PYTHON_TO_PYTHON_BY_VALUE(unsigned LONG_LONG, PyLong_FromUnsignedLongLong( BOOST_PYTHON_TO_PYTHON_BY_VALUE(char, converter::do_return_to_python(x)) BOOST_PYTHON_TO_PYTHON_BY_VALUE(char const*, converter::do_return_to_python(x)) -BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, PyString_FromString(x.c_str())) +BOOST_PYTHON_TO_PYTHON_BY_VALUE(std::string, PyString_FromStringAndSize(x.c_str(),x.size())) BOOST_PYTHON_TO_PYTHON_BY_VALUE(float, PyFloat_FromDouble(x)) BOOST_PYTHON_TO_PYTHON_BY_VALUE(double, PyFloat_FromDouble(x)) BOOST_PYTHON_TO_PYTHON_BY_VALUE(long double, PyFloat_FromDouble(x)) diff --git a/src/converter/builtin_converters.cpp b/src/converter/builtin_converters.cpp index b5916dde..ce842b12 100644 --- a/src/converter/builtin_converters.cpp +++ b/src/converter/builtin_converters.cpp @@ -222,9 +222,9 @@ namespace }; // Remember that this will be used to construct the result object - static char const* extract(PyObject* intermediate) + static std::string extract(PyObject* intermediate) { - return PyString_AsString(intermediate); + return std::string(PyString_AsString(intermediate),PyString_Size(intermediate)); } }; diff --git a/test/test_builtin_converters.py b/test/test_builtin_converters.py index f6caf56b..e4d8b335 100644 --- a/test/test_builtin_converters.py +++ b/test/test_builtin_converters.py @@ -1,4 +1,4 @@ -""" +r""" >>> from builtin_converters import * # Synthesize idendity functions in case long long not supported @@ -73,6 +73,11 @@ >>> rewrap_value_string('yo, wassup?') 'yo, wassup?' + wrap strings with embedded nulls: + +>>> rewrap_value_string('yo,\0wassup?') +'yo,\x00wassup?' + >>> rewrap_value_handle(1) 1 >>> x = 'hi'