Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-04 07:20:42


----- Original Message -----
From: <rwgk_at_[hidden]>

> The following is already in the CVS tree:
>
> PyObject* to_python(const std::string& s)
> {
> return PyString_FromStringAndSize(s.data(), s.size());
> }
>
> std::string from_python(PyObject* p, boost::python::type<std::string>)
> {
> return std::string(PyString_AsString(p), PyString_Size(p));
> }
>
> Looking at this again, it seems to me that the from_python()
> converter needs some work. Either something like
> const char* s = PyString_AsString(p);
> if (!s)
> throw boost::python::argument_error();
> or maybe
> if (! PyString_Check(p)) ...

I like the latter one. Would you care to make the fix?

> I believe that PyString_AsStringAndSize is not available in
> Python 1.5.2 and should therefore not be used.

Sounds right to me.

-Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk