This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [C API] PyType_GetSlot() should accept static types
Type: Stage: resolved
Components: C API Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: miss-islington, petr.viktorin, shihai1991, vstinner
Priority: normal Keywords: patch

Created on 2020-06-22 08:38 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 21395 closed shihai1991, 2020-07-08 14:09
PR 21931 merged shihai1991, 2020-08-20 17:23
Messages (10)
msg372049 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-22 08:38
To fix bpo-40170, I would like to modify Py_TRASHCAN_BEGIN() macro to use PyType_GetSlot() to get the deallocator function, rather than accessing directly the PyTypeObject.tp_dealloc member. The problem is that currently PyType_GetSlot() only works on heap allocated types.

Would it be possible to add support for statically allocated types to PyType_GetSlot()?

Py_TRASHCAN_BEGIN() is currently defined as:

#define Py_TRASHCAN_BEGIN(op, dealloc) \
    Py_TRASHCAN_BEGIN_CONDITION(op, \
        Py_TYPE(op)->tp_dealloc == (destructor)(dealloc))
msg372084 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-06-22 11:07
Hi, victor. If you have much bpo need to manage, I could take a look in this week :)
msg372541 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-06-29 04:52
historical discuss: bpo17162
msg372542 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-06-29 04:56
I create a PR in: https://github.com/shihai1991/cpython/pull/13/commits.
Looks like It works.

If we extend PyType_GetSlot() to accept non-heaptype, we need find a way to judge the max slot of non-heaptype.
msg372559 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-06-29 10:32
> historical discuss: bpo17162

bpo-17162 added PyType_GetSlot(), but static types were not discussed there.
msg372693 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-06-30 14:01
> bpo-17162 added PyType_GetSlot(), but static types were not discussed there.
Thanks to correct my info. I paste this bpo just Larry have mentioned the static type in PyType_GetSlot() :)
msg372791 - (view) Author: Petr Viktorin (petr.viktorin) * (Python committer) Date: 2020-07-01 20:42
> If we extend PyType_GetSlot() to accept non-heaptype, we need find a way to judge the max slot of non-heaptype.

Static types can have some sub-slots structs but not others. A "max slot" will not help for types that have tp_as_mapping but not tp_as_number, for example.
You'll probably need some table like typeslots.inc to record which sub-slots struct each slot belongs to.
msg372864 - (view) Author: Hai Shi (shihai1991) * (Python triager) Date: 2020-07-02 16:13
> You'll probably need some table like typeslots.inc to record which sub-slots struct each slot belongs to.

Looks like it's a good way to solve this probleam, Let me try it ;)
msg380712 - (view) Author: miss-islington (miss-islington) Date: 2020-11-10 20:53
New changeset a13b26cac1519dad7bbc8651de7b826df7389d75 by Hai Shi in branch 'master':
bpo-41073: PyType_GetSlot() can now accept static types. (GH-21931)
https://github.com/python/cpython/commit/a13b26cac1519dad7bbc8651de7b826df7389d75
msg380723 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-11-10 22:32
> bpo-41073: PyType_GetSlot() can now accept static types. (GH-21931)

Nice! It will be simpler to use PyType_GetSlot() in an extension with the limited C API, without having to care if the type is a static type or a heap type.
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85245
2020-11-10 22:32:37vstinnersetmessages: + msg380723
2020-11-10 20:54:53petr.viktorinsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-11-10 20:53:54miss-islingtonsetnosy: + miss-islington
messages: + msg380712
2020-08-20 17:23:18shihai1991setpull_requests: + pull_request21044
2020-07-08 14:09:39shihai1991setkeywords: + patch
stage: patch review
pull_requests: + pull_request20543
2020-07-02 16:13:19shihai1991setmessages: + msg372864
2020-07-01 20:42:43petr.viktorinsetnosy: + petr.viktorin
messages: + msg372791
2020-06-30 14:01:33shihai1991setmessages: + msg372693
2020-06-29 10:32:16vstinnersetmessages: + msg372559
2020-06-29 04:56:21shihai1991setmessages: + msg372542
2020-06-29 04:52:22shihai1991setmessages: + msg372541
2020-06-22 11:07:48shihai1991setmessages: + msg372084
2020-06-22 11:02:58shihai1991setnosy: + shihai1991
2020-06-22 08:38:14vstinnercreate