2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-26 06:42:27 +00:00

map [plain] char '\0' <-> "" (Python string of length 0)

[SVN r9306]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2001-02-21 10:00:27 +00:00
parent 891e5be0b4
commit f7c63792f0

View File

@@ -162,21 +162,20 @@ unsigned short from_python(PyObject* p, boost::python::type<unsigned short> type
PyObject* to_python(char c)
{
return PyString_FromStringAndSize(&c, 1);
if (c == '\0') return PyString_FromString("");
return PyString_FromStringAndSize(&c, 1);
}
char from_python(PyObject* p, boost::python::type<char>)
{
if (! PyString_Check(p)) {
PyErr_SetString(PyExc_TypeError, "expected string with exactly one character");
int l = -1;
if (PyString_Check(p)) l = PyString_Size(p);
if (l < 0 || l > 1) {
PyErr_SetString(PyExc_TypeError, "expected string of length 0 or 1");
throw boost::python::argument_error();
}
const char* s = PyString_AsString(p);
if (! s || s[0] == '\0' || s[1] != '\0') {
PyErr_SetString(PyExc_ValueError, "expected string with exactly one character");
throw boost::python::argument_error();
}
return s[0];
if (l == 0) return '\0';
return PyString_AsString(p)[0];
}
PyObject* to_python(unsigned char i)