Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C API] PyType_GetSlot() should accept static types #85245

Closed
vstinner opened this issue Jun 22, 2020 · 10 comments
Closed

[C API] PyType_GetSlot() should accept static types #85245

vstinner opened this issue Jun 22, 2020 · 10 comments

Comments

@vstinner
Copy link
Member

@vstinner vstinner commented Jun 22, 2020

BPO 41073
Nosy @vstinner, @encukou, @miss-islington, @shihai1991
PRs
  • #21395
  • #21931
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2020-11-10.20:54:53.529>
    created_at = <Date 2020-06-22.08:38:14.306>
    labels = ['expert-C-API', '3.10']
    title = '[C API] PyType_GetSlot() should accept static types'
    updated_at = <Date 2020-11-10.22:32:37.686>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-11-10.22:32:37.686>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-11-10.20:54:53.529>
    closer = 'petr.viktorin'
    components = ['C API']
    creation = <Date 2020-06-22.08:38:14.306>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41073
    keywords = ['patch']
    message_count = 10.0
    messages = ['372049', '372084', '372541', '372542', '372559', '372693', '372791', '372864', '380712', '380723']
    nosy_count = 4.0
    nosy_names = ['vstinner', 'petr.viktorin', 'miss-islington', 'shihai1991']
    pr_nums = ['21395', '21931']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue41073'
    versions = ['Python 3.10']

    @vstinner
    Copy link
    Member Author

    @vstinner vstinner commented Jun 22, 2020

    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))

    @shihai1991
    Copy link
    Member

    @shihai1991 shihai1991 commented Jun 22, 2020

    Hi, victor. If you have much bpo need to manage, I could take a look in this week :)

    @shihai1991
    Copy link
    Member

    @shihai1991 shihai1991 commented Jun 29, 2020

    historical discuss: bpo-17162

    @shihai1991
    Copy link
    Member

    @shihai1991 shihai1991 commented Jun 29, 2020

    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.

    @vstinner
    Copy link
    Member Author

    @vstinner vstinner commented Jun 29, 2020

    historical discuss: bpo-17162

    bpo-17162 added PyType_GetSlot(), but static types were not discussed there.

    @shihai1991
    Copy link
    Member

    @shihai1991 shihai1991 commented Jun 30, 2020

    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() :)

    @encukou
    Copy link
    Member

    @encukou encukou commented Jul 1, 2020

    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.

    @shihai1991
    Copy link
    Member

    @shihai1991 shihai1991 commented Jul 2, 2020

    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 ;)

    @miss-islington
    Copy link
    Contributor

    @miss-islington miss-islington commented Nov 10, 2020

    New changeset a13b26c by Hai Shi in branch 'master':
    bpo-41073: PyType_GetSlot() can now accept static types. (GH-21931)
    a13b26c

    @vstinner
    Copy link
    Member Author

    @vstinner vstinner commented Nov 10, 2020

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants