bpo-45459: Add Py_buffer to limited API (GH-29991)

- [x] ``Py_buffer`` struct
- [x] ``PyBuffer_*()`` API functions
- [x] ``PyBUF_*`` constants
- [x] ``Py_bf_getbuffer`` and ``Py_bf_releasebuffer`` type slots
- [x] ``PyMemoryView_FromBuffer()`` API
- [x] tests for limited API
- [x] ``make regen-limited-abi``
- [x] documentation update
- [ ] export ``PyPickleBuffer*()`` API ???
This commit is contained in:
Christian Heimes 2022-02-02 17:03:10 +02:00 committed by GitHub
parent 08f8301b21
commit f66c857572
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 308 additions and 131 deletions

View file

@ -28,6 +28,14 @@ SYMBOL_NAMES = (
"PyBaseObject_Type",
"PyBool_FromLong",
"PyBool_Type",
"PyBuffer_FillContiguousStrides",
"PyBuffer_FillInfo",
"PyBuffer_FromContiguous",
"PyBuffer_GetPointer",
"PyBuffer_IsContiguous",
"PyBuffer_Release",
"PyBuffer_SizeFromFormat",
"PyBuffer_ToContiguous",
"PyByteArrayIter_Type",
"PyByteArray_AsString",
"PyByteArray_Concat",
@ -381,6 +389,7 @@ SYMBOL_NAMES = (
"PyMemberDescr_Type",
"PyMember_GetOne",
"PyMember_SetOne",
"PyMemoryView_FromBuffer",
"PyMemoryView_FromMemory",
"PyMemoryView_FromObject",
"PyMemoryView_GetContiguous",
@ -470,8 +479,10 @@ SYMBOL_NAMES = (
"PyObject_CallNoArgs",
"PyObject_CallObject",
"PyObject_Calloc",
"PyObject_CheckBuffer",
"PyObject_CheckReadBuffer",
"PyObject_ClearWeakRefs",
"PyObject_CopyData",
"PyObject_DelItem",
"PyObject_DelItemString",
"PyObject_Dir",
@ -489,6 +500,7 @@ SYMBOL_NAMES = (
"PyObject_GetAIter",
"PyObject_GetAttr",
"PyObject_GetAttrString",
"PyObject_GetBuffer",
"PyObject_GetItem",
"PyObject_GetIter",
"PyObject_HasAttr",

View file

@ -58,6 +58,17 @@ class TestXXLimited(CommonTests, unittest.TestCase):
with self.assertRaises(self.module.Error):
raise self.module.Error
def test_buffer(self):
xxo = self.module.Xxo()
self.assertEqual(xxo.x_exports, 0)
b1 = memoryview(xxo)
self.assertEqual(xxo.x_exports, 1)
b2 = memoryview(xxo)
self.assertEqual(xxo.x_exports, 2)
b1[0] = 1
self.assertEqual(b1[0], 1)
self.assertEqual(b2[0], 1)
class TestXXLimited35(CommonTests, unittest.TestCase):
module = xxlimited_35