GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ``tp_dict`` slot of static builtin types is ``NULL`` in 3.12, without mention in the changelog or an alternative · Issue #105227 · python/cpython

tp_dict slot of static builtin types is NULL in 3.12, without mention in the changelog or an alternative #105227

New issue
Copy link
New issue
Copy link
Closed
Closed
tp_dict slot of static builtin types is NULL in 3.12, without mention in the changelog or an alternative#105227
Copy link
Labels
3.12only security fixesonly security fixesdeferred-blockertopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@ronaldoussoren
ronaldoussoren
opened on Jun 2, 2023
Issue body actions

PyObjC contains some functionality that needs to walk the entire MRO of classes and access the tp_dict slot. As of Python 3.12 beta 1 this code crashes due to the slot being NULL on static builtin types.

The code in PyObjC walks the MRO to implement tp_getattro for the proxy of Objective-C classes to replicate PyObject_GenericGetAttr with some customisations, as wel as in the implementation of an alternative to super (again with customisations in the attribute resolution path). All code paths only need read-only access to the tp_dict of static builtin types, although some code needs to be able to update the tp_dict of classes created by PyObjC.

There is currently no documented alternative for directly accessing tp_dict, and because of this I've changed PyObjC to use the private API _PyType_GetDict.

Some alternatives I've looked into:

  • Use PyObject_GetAttrString(someType, "__dict__"): This increases the complexity of the PyObjC code bases and requires changes to long stable code:

    • Needs to introduce a different code path for accessing the __dict__ slot of non-PyObjC subclasses

    • Needs to switch to the abstract Mapping API instead of the PyDict API, which likely has a performance impact

    • Changes to reference counting invariants in the code

  • Use _PyType_GetDict on Python 3.12 or later: This works, but introduces a reliance on a private CPython API that might disappear at any moment (even micro releases), for example by no longer exporting the function from shared libraries.

Proposal: Rename _PyType_GetDict to either PyUnstable_Type_GetDict or PyType_GetDict, while keeping the current interface (e.g. returning a borrowed reference and never raising an exception).

This is a follow-up from #105020

@ericsnowcurrently

Linked PRs

  • gh-105227: Add PyType_GetDict() #105747
  • [3.12] gh-105227: Add PyType_GetDict() (GH-105747) #106600

Activity

  1. ronaldoussoren
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    3.12only security fixesonly security fixes
    on Jun 2, 2023
  2. ronaldoussoren commented on Jun 2, 2023

    @ronaldoussoren
    ronaldoussoren
    on Jun 2, 2023
    ContributorAuthor
    More actions

    @Yhg1s : Would it be acceptable to introduce such a new API in an upcoming 3.12 beta release?

  3. ronaldoussoren
    added
    deferred-blocker
    on Jun 12, 2023
  4. ezio-melotti
    added this to Release and Deferred blockers 🚫on Jun 12, 2023
  5. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on Jun 12, 2023
  6. ronaldoussoren commented on Jun 12, 2023

    @ronaldoussoren
    ronaldoussoren
    on Jun 12, 2023
    ContributorAuthor
    More actions

    @Yhg1s, I've added the deferred blocker label because this issue is a seemingly intentional regression from 3.11 without a documented replacement.

    I'm currently using a private API and that doesn't feel right.

    Reacted by Eric Snow
  7. erlend-aasland
    added
    topic-C-API
    on Jun 12, 2023
  8. ericsnowcurrently commented on Jun 13, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Jun 13, 2023
    Member
    More actions

    FWIW, I'm in favor of adding PyType_GetDict(). I've put up a PR: gh-105747.

    Reacted by Erlend E. Aasland
  9. ronaldoussoren commented on Jun 14, 2023

    @ronaldoussoren
    ronaldoussoren
    on Jun 14, 2023
    ContributorAuthor
    More actions

    I agree that its is better to return a new reference instead of a borrowed reference in APIs like this, but that can make life harder for anyone transitioning to the new way of working. In my particular case it does make transitioning harder because I'll have to add refcount updates where I didn't have to do before. That said, this is not a big problem.

    Reacted by Eric Snow
  10. miss-islington
    added a commit that references this issue on Jul 10, 2023

    pythongh-105227: Add PyType_GetDict() (pythonGH-105747)

    7771a2d
  11. encukou
    added a commit that references this issue on Jul 10, 2023

    gh-105227: Add PyType_GetDict() (GH-105747)

    a840806
  12. encukou commented on Jul 10, 2023

    @encukou
    encukou
    on Jul 10, 2023
    Member
    More actions

    @ericsnowcurrently, when you get back, could you review (and maybe improve) the docs?

    Reacted by Eric Snow
  13. encukou
    added a commit that references this issue on Jul 10, 2023

    [3.12] gh-105227: Add PyType_GetDict() (GH-105747) (#106600)

    41057b2
  14. ericsnowcurrently commented on Jul 17, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Jul 17, 2023
    Member
    More actions

    The docs seem fine to me, after your changes. My original changes were likely unnecessarily specific. :) Was there something in particular you were concerned about?

  15. ericsnowcurrently commented on Jul 17, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Jul 17, 2023
    Member
    More actions

    If you think more should be done, feel free to re-open this.

  16. ericsnowcurrently
    closed this as completedon Jul 17, 2023
  17. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on Jul 17, 2023
  18. exg
    added a commit that references this issue on Oct 3, 2023

    Fix crash with python 3.12

    32f91dd
  19. navytux
    added a commit that references this issue on Apr 4, 2025

    golang_str: Fix SIGSEGV on import on py3.12

    4524dfc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixesonly security fixesdeferred-blockertopic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    • Release and Deferred blockers 🚫
      Status
      Done
      Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.