summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2010-11-04 12:09:08 (GMT)
committerHirokazu Yamamoto <ocean-city@m2.ccsnet.ne.jp>2010-11-04 12:09:08 (GMT)
commit3cdd5cb959672ce24dcf8132f3e9bbe27f908dc7 (patch)
tree0cae2e90e716369ea660d7e00d9ad266f0454970
parent95c0700effc69b6b41a4a4ca104ee6b65a42be23 (diff)
downloadcpython-3cdd5cb959672ce24dcf8132f3e9bbe27f908dc7.zip
cpython-3cdd5cb959672ce24dcf8132f3e9bbe27f908dc7.tar.gz
cpython-3cdd5cb959672ce24dcf8132f3e9bbe27f908dc7.tar.bz2
Issue #5391: mmap.read_byte() should return unsigned value [0, 255]
instead of signed value [-127, 128].
-rw-r--r--Lib/test/test_mmap.py9
-rw-r--r--Modules/mmapmodule.c2
2 files changed, 10 insertions, 1 deletions
diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py
index 54a43f9..f78fed9 100644
--- a/Lib/test/test_mmap.py
+++ b/Lib/test/test_mmap.py
@@ -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"
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 680f1f1..13d7f55 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -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;