From: Serhiy Storchaka Date: Sun, 31 May 2015 08:56:48 +0000 (+0300) Subject: Fixed the array module in unicode disabled build (regression of issue20014). X-Git-Tag: v2.7.11rc1~284 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dc967c137cb5e2e0f558cedbb94a13256db3fb75;p=thirdparty%2FPython%2Fcpython.git Fixed the array module in unicode disabled build (regression of issue20014). --- diff --git a/Lib/test/test_array.py b/Lib/test/test_array.py index 7256b9489c42..105cf7394640 100644 --- a/Lib/test/test_array.py +++ b/Lib/test/test_array.py @@ -18,7 +18,9 @@ class ArraySubclassWithKwargs(array.array): array.array.__init__(self, typecode) tests = [] # list to accumulate all tests -typecodes = "cubBhHiIlLfd" +typecodes = "cbBhHiIlLfd" +if test_support.have_unicode: + typecodes += "u" class BadConstructorTest(unittest.TestCase): @@ -837,6 +839,7 @@ class CharacterTest(StringTest): self.assertEqual(s.color, "red") self.assertEqual(s.__dict__.keys(), ["color"]) + @test_support.requires_unicode def test_nounicode(self): a = array.array(self.typecode, self.example) self.assertRaises(ValueError, a.fromunicode, unicode('')) diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index c37644d45c6e..3ed8a33ad764 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -1940,8 +1940,10 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds) if (PyString_Check(typecode) && PyString_GET_SIZE(typecode) == 1) c = (unsigned char)*PyString_AS_STRING(typecode); +#ifdef Py_USING_UNICODE else if (PyUnicode_Check(typecode) && PyUnicode_GET_SIZE(typecode) == 1) c = *PyUnicode_AS_UNICODE(typecode); +#endif else { PyErr_Format(PyExc_TypeError, "array() argument 1 or typecode must be char (string or "