classification
Title: Support buffer protocol with type specs
Type: enhancement Stage: resolved
Components: C API Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, ncoghlan, paul.moore, petr.viktorin, pitrou, remi.lapeyre, scoder, skrah, vstinner
Priority: normal Keywords: patch

Created on 2020-05-22 07:51 by scoder, last changed 2020-06-07 07:29 by scoder. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 20648 merged scoder, 2020-06-05 07:45
PR 20683 merged miss-islington, 2020-06-06 19:35
PR 20685 merged remi.lapeyre, 2020-06-07 06:57
PR 20690 merged miss-islington, 2020-06-07 07:08
Messages (5)
msg369561 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2020-05-22 07:51
As far as I can see it in typeslots.h [1], the buffer protocol is still not supported when using type specs:

/* Disabled, see #10181 */
#undef Py_bf_getbuffer
#undef Py_bf_releasebuffer

It seems that the discussion in issue 10181 did not lead anywhere at the time (2010-2012).

I'm not talking about the limited API or the stable ABI here, I'm talking about using type specs to define an extension type. The work-around is to manually set "PyTypeObject->tp_as_buffer" after creating the type, but since PyType_Ready() then does not see that struct pointer, you also still have to make sure that the type correctly inherits the slots from the base type if you're not defining all of them yourself.

Can we just add support for the above slots?

[1] https://github.com/python/cpython/blob/ca829102213c466ffecb1e464be5c8cb3967d961/Include/typeslots.h#L2-L4
msg370194 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2020-05-28 11:35
Yes, it should be possible to wrap them in #if so they aren't part of the stable ABI.
msg370849 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2020-06-06 19:35
New changeset f7c4e236429606e1c982cacf24e10fc86ef4462f by scoder in branch 'master':
bpo-40724: Support setting buffer slots from type specs (GH-20648)
https://github.com/python/cpython/commit/f7c4e236429606e1c982cacf24e10fc86ef4462f
msg370878 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2020-06-07 07:06
New changeset 1e4fa91104a03c44baa241326102cbec42d387f1 by Miss Islington (bot) in branch '3.9':
bpo-40724: Support setting buffer slots from type specs (GH-20648) (GH-20683)
https://github.com/python/cpython/commit/1e4fa91104a03c44baa241326102cbec42d387f1
msg370879 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2020-06-07 07:28
New changeset 1d711f2e31e02b2e9cbe4f109bf79541f56c35a2 by Miss Islington (bot) in branch '3.9':
bpo-40724: Fix return type of test helper function heapctypewithbuffer_releasebuffer() (GH-20685) (GH-20690)
https://github.com/python/cpython/commit/1d711f2e31e02b2e9cbe4f109bf79541f56c35a2
History
Date User Action Args
2020-06-07 07:29:43scodersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-06-07 07:28:11scodersetmessages: + msg370879
2020-06-07 07:08:37miss-islingtonsetpull_requests: + pull_request19905
2020-06-07 07:06:44scodersetmessages: + msg370878
2020-06-07 06:57:16remi.lapeyresetnosy: + remi.lapeyre
pull_requests: + pull_request19904
2020-06-06 19:35:34miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request19895
2020-06-06 19:35:17scodersetmessages: + msg370849
2020-06-05 07:45:18scodersetkeywords: + patch
stage: patch review
pull_requests: + pull_request19868
2020-05-28 11:35:09petr.viktorinsetmessages: + msg370194
2020-05-22 07:51:02scodercreate