]> granicus.if.org Git - python/commitdiff
Merged revisions 74673 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Sun, 6 Sep 2009 10:05:28 +0000 (10:05 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 6 Sep 2009 10:05:28 +0000 (10:05 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r74673 | mark.dickinson | 2009-09-06 11:03:31 +0100 (Sun, 06 Sep 2009) | 3 lines

  Issue #6846: bytearray.pop was returning ints in the range [-128, 128)
  instead of [0, 256).  Thanks Hagen Fürstenau for the report and fix.
........

Lib/test/test_bytes.py
Misc/NEWS
Objects/bytearrayobject.c

index 00aee028b18d49a1cc863865f55ba1b82855adb7..48b02583333f3b735dcafc2b8e92c0b50ec9977d 100644 (file)
@@ -691,6 +691,8 @@ class ByteArrayTest(BaseBytesTest):
         self.assertEqual(b.pop(-2), ord('r'))
         self.assertRaises(IndexError, lambda: b.pop(10))
         self.assertRaises(OverflowError, lambda: bytearray().pop())
+        # test for issue #6846
+        self.assertEqual(bytearray(b'\xff').pop(), 0xff)
 
     def test_nosort(self):
         self.assertRaises(AttributeError, lambda: bytearray().sort())
index aed5bf845bbcd6420e5335bbab6f83a6241e25aa..afaa55b0963f6001b7873a6edaa83651abdaf79c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,8 @@ What's New in Python 2.6.3
 Core and Builtins
 -----------------
 
+- Issue #6846: Fix bug where bytearray.pop() returns negative integers.
+
 - Issue #6707: dir() on an uninitialized module caused a crash.
 
 - Issue #6540: Fixed crash for bytearray.translate() with invalid parameters.
index 7eafce784f0a2cbf777c25013d4c58d3685c44b8..f6a5c160ecac5225093ae1274bc1334d6eec52e9 100644 (file)
@@ -2758,7 +2758,7 @@ bytes_pop(PyByteArrayObject *self, PyObject *args)
     if (PyByteArray_Resize((PyObject *)self, n - 1) < 0)
         return NULL;
 
-    return PyInt_FromLong(value);
+    return PyInt_FromLong((unsigned char)value);
 }
 
 PyDoc_STRVAR(remove__doc__,