2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 18:12:43 +00:00

Allow embedded nulls in std::string <-> Python string conversions,

patch from greg Landrum <greglandrum@mindspring.com>.

Tests by Dave A.


[SVN r15945]
This commit is contained in:
Dave Abrahams
2002-10-16 20:24:38 +00:00
parent c389e057b4
commit 7fc441801d
3 changed files with 9 additions and 4 deletions

View File

@@ -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))

View File

@@ -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));
}
};

View File

@@ -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'