changeset: 92397:d6c7ab5a2065 branch: 2.7 parent: 92394:ee969a717cb5 user: Serhiy Storchaka date: Thu Sep 11 10:56:59 2014 +0300 files: Lib/test/test_tcl.py Misc/NEWS Modules/_tkinter.c description: Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with empty string or tuple argument. On some platforms Tcl memory allocator returns NULL when allocating zero-sized block of memory. diff -r ee969a717cb5 -r d6c7ab5a2065 Lib/test/test_tcl.py --- a/Lib/test/test_tcl.py Thu Sep 11 10:38:08 2014 +0300 +++ b/Lib/test/test_tcl.py Thu Sep 11 10:56:59 2014 +0300 @@ -429,7 +429,6 @@ self.assertEqual(passValue((1, '2', (3.4,))), (1, '2', (3.4,)) if self.wantobjects else '1 2 3.4') - @unittest.skipIf(sys.platform.startswith("aix"), 'Issue #21951: crashes on AIX') def test_user_command(self): result = [] def testfunc(arg): @@ -456,9 +455,11 @@ check('string') check('string\xbd') check('string\xe2\x82\xac', u'string\u20ac') + check('') check(u'string') check(u'string\xbd') check(u'string\u20ac') + check(u'') check('str\xc0\x80ing', u'str\x00ing') check('str\xc0\x80ing\xe2\x82\xac', u'str\x00ing\u20ac') check(u'str\x00ing') diff -r ee969a717cb5 -r d6c7ab5a2065 Misc/NEWS --- a/Misc/NEWS Thu Sep 11 10:38:08 2014 +0300 +++ b/Misc/NEWS Thu Sep 11 10:56:59 2014 +0300 @@ -22,6 +22,9 @@ Library ------- +- Issue #21951: Fixed a crash in Tkinter on AIX when called Tcl command with + empty string or tuple argument. + - Issue #21951: Tkinter now most likely raises MemoryError instead of crash if the memory allocation fails. diff -r ee969a717cb5 -r d6c7ab5a2065 Modules/_tkinter.c --- a/Modules/_tkinter.c Thu Sep 11 10:38:08 2014 +0300 +++ b/Modules/_tkinter.c Thu Sep 11 10:56:59 2014 +0300 @@ -1052,6 +1052,8 @@ Py_ssize_t size, i; size = PyTuple_Size(value); + if (size == 0) + return Tcl_NewListObj(0, NULL); if (!CHECK_SIZE(size, sizeof(Tcl_Obj *))) { PyErr_SetString(PyExc_OverflowError, "tuple is too long"); return NULL; @@ -1075,6 +1077,8 @@ Tcl_UniChar *outbuf = NULL; Py_ssize_t i; size_t allocsize; + if (size == 0) + return Tcl_NewUnicodeObj((const void *)"", 0); if (!CHECK_SIZE(size, sizeof(Tcl_UniChar))) { PyErr_SetString(PyExc_OverflowError, "string is too long"); return NULL;