summaryrefslogtreecommitdiffstats
path: root/Modules/_struct.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-05-27 09:19:04 (GMT)
committerGuido van Rossum <guido@python.org>2007-05-27 09:19:04 (GMT)
commite625fd5444bda7a6b619c256eaf86a2ff0d51c6c (patch)
treec281767e808229e87371b493f7b5b5692c3aed48 /Modules/_struct.c
parent54ad523f026afd4c06d567cfeeee0fb0e18ba444 (diff)
downloadcpython-e625fd5444bda7a6b619c256eaf86a2ff0d51c6c.zip
cpython-e625fd5444bda7a6b619c256eaf86a2ff0d51c6c.tar.gz
cpython-e625fd5444bda7a6b619c256eaf86a2ff0d51c6c.tar.bz2
Make struct tests pass.
Diffstat (limited to 'Modules/_struct.c')
-rw-r--r--Modules/_struct.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 08b3102..3100982 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -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);