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

Created on 2020-06-22 08:38 by vstinner, last changed 2020-07-02 16:13 by shihai1991.

Messages (8)
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) * 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) * Date: 2020-06-29 04:52
historical discuss: bpo17162
msg372542 - (view) Author: hai shi (shihai1991) * 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) * 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) * 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 ;)
History
Date User Action Args
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