]> granicus.if.org Git - python/commitdiff
Merged revisions 86159 via svnmerge from
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Thu, 4 Nov 2010 12:35:21 +0000 (12:35 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Thu, 4 Nov 2010 12:35:21 +0000 (12:35 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86159 | hirokazu.yamamoto | 2010-11-04 21:09:08 +0900 | 2 lines

  Issue #5391: mmap.read_byte() should return unsigned value [0, 255]
  instead of signed value [-127, 128].
........

Lib/test/test_mmap.py
Modules/mmapmodule.c

index b3869a6317fd9d89b0b08a3bed243efb87c843ce..b6d2ffbc2bf320269aa5dccf05449523d79ebaef 100644 (file)
@@ -536,6 +536,15 @@ class MmapTests(unittest.TestCase):
         m.seek(8)
         self.assertRaises(ValueError, m.write, b"bar")
 
+    def test_non_ascii_byte(self):
+        for b in (129, 200, 255): # > 128
+            m = mmap.mmap(-1, 1)
+            m.write_byte(b)
+            self.assertEquals(m[0], b)
+            m.seek(0)
+            self.assertEquals(m.read_byte(), b)
+            m.close()
+
     if os.name == 'nt':
         def test_tagname(self):
             data1 = b"0123456789"
index c39715a36412d76808d4326538dc758720a9b2ec..00051135d0846752d5696f77dfdd1157c5d6afb6 100644 (file)
@@ -205,7 +205,7 @@ mmap_read_byte_method(mmap_object *self,
     if (self->pos < self->size) {
         char value = self->data[self->pos];
         self->pos += 1;
-        return Py_BuildValue("b", value);
+        return Py_BuildValue("B", (unsigned char)value);
     } else {
         PyErr_SetString(PyExc_ValueError, "read byte out of range");
         return NULL;