diff Modules/_struct.c @ 41891:b7cfb3fd8db0

Make struct tests pass.
author Guido van Rossum <guido@python.org>
date Sun, 27 May 2007 09:19:04 +0000
parents 24b60622b944
children e70cdce0e8b2
line wrap: on
line diff
--- a/Modules/_struct.c	Sun May 27 09:17:48 2007 +0000
+++ b/Modules/_struct.c	Sun May 27 09:19:04 2007 +0000
@@ -608,9 +608,14 @@
 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);