mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
gh-114685: Check flags in PyObject_GetBuffer() (GH-114707)
PyObject_GetBuffer() now raises a SystemError if called with PyBUF_READ or PyBUF_WRITE as flags. These flags should only be used with the PyMemoryView_* C API.
This commit is contained in:
parent
7a93db4425
commit
b7688ef71e
4 changed files with 19 additions and 2 deletions
|
@ -4585,6 +4585,12 @@ class TestPythonBufferProtocol(unittest.TestCase):
|
|||
buf.__release_buffer__(mv)
|
||||
self.assertEqual(buf.references, 0)
|
||||
|
||||
@unittest.skipIf(_testcapi is None, "requires _testcapi")
|
||||
def test_c_buffer_invalid_flags(self):
|
||||
buf = _testcapi.testBuf()
|
||||
self.assertRaises(SystemError, buf.__buffer__, PyBUF_READ)
|
||||
self.assertRaises(SystemError, buf.__buffer__, PyBUF_WRITE)
|
||||
|
||||
def test_inheritance(self):
|
||||
class A(bytearray):
|
||||
def __buffer__(self, flags):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue