Make struct tests pass.

This commit is contained in:
Guido van Rossum 2007-05-27 09:19:04 +00:00
parent 54ad523f02
commit e625fd5444
3 changed files with 41 additions and 24 deletions

View file

@ -608,9 +608,14 @@ np_ubyte(char *p, PyObject *v, const formatdef *f)
static int
np_char(char *p, PyObject *v, const formatdef *f)
{
if (PyUnicode_Check(v)) {
v = _PyUnicode_AsDefaultEncodedString(v, NULL);
if (v == NULL)
return -1;
}
if (!PyString_Check(v) || PyString_Size(v) != 1) {
PyErr_SetString(StructError,
"char format require string of length 1");
"char format requires string of length 1");
return -1;
}
*p = *PyString_AsString(v);