diff Python/modsupport.c @ 42119:4db0a0cc57ab

Change %c format specifier for PyArg_ParseTuple() so that it accepts a unicode character (an int * must be passed as the argument). Change %c format specifier for Py_BuildValue() so that it outputs a unicode object. Fix datetime.datetime.isoformat(), so that it works if sep is a unicode character > U+00FF.
author Walter Dörwald <walter@livinglogic.de>
date Wed, 20 Jun 2007 11:02:38 +0000
parents ba5d1a3977e9
children 1f7b66a9ffb0
line wrap: on
line diff
--- a/Python/modsupport.c	Wed Jun 20 09:25:34 2007 +0000
+++ b/Python/modsupport.c	Wed Jun 20 11:02:38 2007 +0000
@@ -385,9 +385,22 @@
 
 		case 'c':
 		{
-			char p[1];
-			p[0] = (char)va_arg(*p_va, int);
-			return PyString_FromStringAndSize(p, 1);
+			int i = va_arg(*p_va, int);
+			Py_UNICODE c;
+			if (i < 0 || i > PyUnicode_GetMax()) {
+#ifdef Py_UNICODE_WIDE
+				PyErr_SetString(PyExc_OverflowError,
+				                "%c arg not in range(0x110000) "
+				                "(wide Python build)");
+#else
+				PyErr_SetString(PyExc_OverflowError,
+				                "%c arg not in range(0x10000) "
+				                "(narrow Python build)");
+#endif
+				return NULL;
+			}
+			c = i;
+			return PyUnicode_FromUnicode(&c, 1);
 		}
 
 		case 's':