[Python-checkins] r67977 - in python/branches/release26-maint: Lib/test/test_bytes.py Misc/NEWS Objects/bytearrayobject.c

georg.brandl python-checkins at python.org
Sun Dec 28 12:55:24 CET 2008


Author: georg.brandl
Date: Sun Dec 28 12:55:24 2008
New Revision: 67977
Log:
Backport r67975: #4759: fix segfault in bytearray.translate(x, None).
Modified:
 python/branches/release26-maint/Lib/test/test_bytes.py
 python/branches/release26-maint/Misc/NEWS
 python/branches/release26-maint/Objects/bytearrayobject.c
Modified: python/branches/release26-maint/Lib/test/test_bytes.py
==============================================================================
--- python/branches/release26-maint/Lib/test/test_bytes.py	(original)
+++ python/branches/release26-maint/Lib/test/test_bytes.py	Sun Dec 28 12:55:24 2008
@@ -872,11 +872,19 @@
 
 def test_translate(self):
 b = b'hello'
+ ba = bytearray(b)
 rosetta = bytearray(range(0, 256))
 rosetta[ord('o')] = ord('e')
 c = b.translate(rosetta, b'l')
 self.assertEqual(b, b'hello')
 self.assertEqual(c, b'hee')
+ c = ba.translate(rosetta, b'l')
+ self.assertEqual(ba, b'hello')
+ self.assertEqual(c, b'hee')
+ c = b.translate(None, b'e')
+ self.assertEqual(c, b'hllo')
+ self.assertRaises(TypeError, b.translate, b'a'*256, None)
+ self.assertRaises(TypeError, ba.translate, b'a'*256, None)
 
 def test_split_bytearray(self):
 self.assertEqual(b'a b'.split(memoryview(b' ')), [b'a', b'b'])
Modified: python/branches/release26-maint/Misc/NEWS
==============================================================================
--- python/branches/release26-maint/Misc/NEWS	(original)
+++ python/branches/release26-maint/Misc/NEWS	Sun Dec 28 12:55:24 2008
@@ -12,6 +12,8 @@
 Core and Builtins
 -----------------
 
+- Issue #4759: fix a segfault for bytearray.translate(x, None).
+
 - Added test case to ensure attempts to read from a file opened for writing
 fail.
 
Modified: python/branches/release26-maint/Objects/bytearrayobject.c
==============================================================================
--- python/branches/release26-maint/Objects/bytearrayobject.c	(original)
+++ python/branches/release26-maint/Objects/bytearrayobject.c	Sun Dec 28 12:55:24 2008
@@ -1465,6 +1465,7 @@
 if (delobj != NULL) {
 if (_getbuffer(delobj, &vdel) < 0) {
 result = NULL;
+ delobj = NULL; /* don't try to release vdel buffer on exit */
 goto done;
 }
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /