Index: Objects/abstract.c =================================================================== --- Objects/abstract.c (révision 83197) +++ Objects/abstract.c (copie de travail) @@ -267,6 +267,11 @@ "expected a single-segment buffer object"); return -1; } + if (pb->bf_releasebuffer != NULL) { + PyErr_SetString(PyExc_TypeError, + "expected a read-only buffer object"); + return -1; + } len = (*pb->bf_getcharbuffer)(obj, 0, &pp); if (len < 0) return -1; Index: Objects/bytearrayobject.c =================================================================== --- Objects/bytearrayobject.c (révision 83197) +++ Objects/bytearrayobject.c (copie de travail) @@ -91,18 +91,6 @@ return 1; } -static Py_ssize_t -bytearray_buffer_getcharbuf(PyByteArrayObject *self, Py_ssize_t index, const char **ptr) -{ - if ( index != 0 ) { - PyErr_SetString(PyExc_SystemError, - "accessing non-existent bytes segment"); - return -1; - } - *ptr = PyByteArray_AS_STRING(self); - return Py_SIZE(self); -} - static int bytearray_getbuffer(PyByteArrayObject *obj, Py_buffer *view, int flags) { @@ -2796,7 +2784,7 @@ (readbufferproc)bytearray_buffer_getreadbuf, (writebufferproc)bytearray_buffer_getwritebuf, (segcountproc)bytearray_buffer_getsegcount, - (charbufferproc)bytearray_buffer_getcharbuf, + (charbufferproc)NULL, (getbufferproc)bytearray_getbuffer, (releasebufferproc)bytearray_releasebuffer, }; Index: Lib/test/test_io.py =================================================================== --- Lib/test/test_io.py (révision 83198) +++ Lib/test/test_io.py (copie de travail) @@ -1507,9 +1507,9 @@ def process_word(self): output = '' if self.buffer[0] == ord('i'): - self.i = min(99, int(self.buffer[1:] or 0)) # set input length + self.i = min(99, int(bytes(self.buffer[1:]) or 0)) # set input length elif self.buffer[0] == ord('o'): - self.o = min(99, int(self.buffer[1:] or 0)) # set output length + self.o = min(99, int(bytes(self.buffer[1:]) or 0)) # set output length else: output = self.buffer.decode('ascii') if len(output) < self.o: Index: Lib/test/test_bytes.py =================================================================== --- Lib/test/test_bytes.py (révision 83197) +++ Lib/test/test_bytes.py (copie de travail) @@ -787,7 +787,7 @@ # Issue #7561: operations on empty bytearrays could crash in many # situations, due to a fragile implementation of the # PyByteArray_AS_STRING() C macro. - self.assertRaises(ValueError, int, bytearray(b'')) + self.assertRaises(TypeError, int, bytearray(b'')) class AssortedBytesTest(unittest.TestCase):