]> granicus.if.org Git - python/commitdiff
Issue #5391: mmap.read_byte() should return unsigned value [0, 255]
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Thu, 4 Nov 2010 12:09:08 +0000 (12:09 +0000)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>
Thu, 4 Nov 2010 12:09:08 +0000 (12:09 +0000)
instead of signed value [-127, 128].

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

index 54a43f93df67286fb277fee77a4851911846dbeb..f78fed95a0523ee1b22bea2fd6b1bd8095063b11 100644 (file)
@@ -534,6 +534,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 680f1f1102a95ca9feecfd422957581d5aff40fd..13d7f5580af931e5e025c60e289e1701f0012726 100644 (file)
@@ -204,7 +204,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;