Kaydet (Commit) 3cdd5cb9 authored tarafından Hirokazu Yamamoto's avatar Hirokazu Yamamoto

Issue #5391: mmap.read_byte() should return unsigned value [0, 255]

instead of signed value [-127, 128].
üst 95c0700e
......@@ -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"
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment