|
Boost : |
From: Rainer Deyke (root_at_[hidden])
Date: 2001-04-03 14:05:05
Both Python strings and 'std::string' support embedded '\0' characters.
However, 'boost::python::from_python(PyObject *,
boost::python::type<std::string>' fails to correctly convert Python strings
with embedded '\0' to 'std::string'. I propose the following alternate
implementation:
std::string from_python(PyObject *p, boost::python::type<std::string>)
{
int length;
char *s;
if (PyString_AsStringAndSize(p, &s, &length))
throw boost::python::argument_error();
return std::string(s, length);
}
There is a similar problem in 'boost::python::to_python(const
std::string&)'. I propose the following alternate implementation:
PyObject *to_python(const std::string& s)
{
return PyString_FromStringAndSize(s.data(), s.size());
}
-- Rainer Deyke (root_at_[hidden]) Shareware computer games - http://rainerdeyke.com "In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk