[Python-checkins] r86159 - in python/branches/py3k: Lib/test/test_mmap.py Modules/mmapmodule.c

hirokazu.yamamoto python-checkins at python.org
Thu Nov 4 13:09:08 CET 2010


Author: hirokazu.yamamoto
Date: Thu Nov  4 13:09:08 2010
New Revision: 86159

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

Modified:
   python/branches/py3k/Lib/test/test_mmap.py
   python/branches/py3k/Modules/mmapmodule.c

Modified: python/branches/py3k/Lib/test/test_mmap.py
==============================================================================
--- python/branches/py3k/Lib/test/test_mmap.py	(original)
+++ python/branches/py3k/Lib/test/test_mmap.py	Thu Nov  4 13:09:08 2010
@@ -534,6 +534,15 @@
         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"

Modified: python/branches/py3k/Modules/mmapmodule.c
==============================================================================
--- python/branches/py3k/Modules/mmapmodule.c	(original)
+++ python/branches/py3k/Modules/mmapmodule.c	Thu Nov  4 13:09:08 2010
@@ -204,7 +204,7 @@
     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;


More information about the Python-checkins mailing list