Boost logo

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

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.size());

Rainer Deyke (root_at_[hidden])
Shareware computer games           - 
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor

Boost list run by bdawes at, gregod at, cpdaniel at, john at