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 — C API: Add PyType_GetModuleByDef() to the limited C API version 3.13 · Issue #116936 · python/cpython

C API: Add PyType_GetModuleByDef() to the limited C API version 3.13 #116936

New issue
Copy link
New issue
Copy link
Closed
Closed
C API: Add PyType_GetModuleByDef() to the limited C API version 3.13#116936
Copy link
Labels
topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

Description

@vstinner
vstinner
opened on Mar 17, 2024
Issue body actions

I propose adding PyType_GetModuleByDef() to the limited C API version 3.13. The function was added to Python 3.9, the function is now well tested. We could add it way earlier to the limited C API.

cc @encukou


The PyType_GetModuleByDef() function is needed to access the module state in C function which don't get a module as first parameter, but only an instance of a heap type. Heap types should be created with PyType_FromModuleAndSpec(module, spec, bases) to store the module in the type. PyType_GetModuleByDef(type) gives the module and then PyModule_GetState() gives the moulde state.

Examples of functions which don't get a module argument:

  • Class methods
  • Most slots, examples: tp_new, tp_richcompare, tp_iternext, etc.
  • PyGetSetDef getter and setter functions

Without PyType_GetModuleByDef(), many static types cannot be converted to heap types.

The following stdlib extensions use PyType_GetModuleByDef()

Modules/_asynciomodule.c
Modules/_bz2module.c
Modules/_collectionsmodule.c
Modules/_csv.c
Modules/_decimal/_decimal.c
Modules/_elementtree.c
Modules/_functoolsmodule.c
Modules/_io/_iomodule.h
Modules/_pickle.c
Modules/_queuemodule.c
Modules/_randommodule.c
Modules/_sqlite/module.h
Modules/_ssl.c
Modules/_ssl.h
Modules/_struct.c
Modules/_testmultiphase.c
Modules/_threadmodule.c
Modules/_xxinterpchannelsmodule.c
Modules/_zoneinfo.c
Modules/arraymodule.c
Modules/cjkcodecs/multibytecodec.c
Modules/clinic/_testmultiphase.c.h
Modules/itertoolsmodule.c
Modules/socketmodule.c
Python/Python-tokenize.c

Linked PRs

  • gh-116936: Add PyType_GetModuleByDef() to the limited C API #116937
Reacted by Erlend E. Aasland

Activity

  1. vstinner
    added 2 commits that reference this issue on Mar 17, 2024

    pythongh-116936: Add PyType_GetModuleByDef() to the limited C API

    ca04ea7

    pythongh-116936: Add PyType_GetModuleByDef() to the limited C API

    56316e2
  2. vstinner commented on Mar 17, 2024

    @vstinner
    vstinner
    on Mar 17, 2024
    MemberAuthor
    More actions

    Attached PR gh-116937 implements the change.

  3. vstinner commented on Mar 18, 2024

    @vstinner
    vstinner
    on Mar 18, 2024
    MemberAuthor
    More actions

    The function was added by issue gh-90771.

  4. erlend-aasland
    added
    topic-C-API
    type-featureA feature request or enhancementA feature request or enhancement
    on Mar 18, 2024
  5. encukou commented on Mar 19, 2024

    @encukou
    encukou
    on Mar 19, 2024
    Member
    More actions

    I agree. It can be implemented using only limited API, but the CPython implementation can pull tricks that make it worth calling as a function.

    I'll be interested in what other members of the C-API WG have to say.

  6. vstinner commented on Mar 19, 2024

    @vstinner
    vstinner
    on Mar 19, 2024
    MemberAuthor
    More actions

    It can be implemented using only limited API

    I don't think that it's possible in practice. For example, Python 3.13 adds BEGIN_TYPE_LOCK() with _PyCriticalSection which is not part of the stable ABI.

  7. encukou commented on Mar 20, 2024

    @encukou
    encukou
    on Mar 20, 2024
    Member
    More actions

    AFAIK, that's for the freethreading experiment. I hope that when the experiment is done, it won't require adding non-limited calls to stable ABI extensions.

  8. vstinner commented on Mar 21, 2024

    @vstinner
    vstinner
    on Mar 21, 2024
    MemberAuthor
    More actions

    @encukou:

    I'll be interested in what other members of the C-API WG have to say.

    Ok, I created issue capi-workgroup/decisions#20.

  9. vstinner
    added a commit that references this issue on Mar 25, 2024

    pythongh-116936: Add PyType_GetModuleByDef() to the limited C API

    f04bcf0
  10. vstinner commented on Mar 25, 2024

    @vstinner
    vstinner
    on Mar 25, 2024
    MemberAuthor
    More actions

    Ok, I created issue capi-workgroup/decisions#20.

    The C API Working Group approved this addition: capi-workgroup/decisions#20.

  11. vstinner
    added a commit that references this issue on Mar 25, 2024

    gh-116936: Add PyType_GetModuleByDef() to the limited C API (#116937)

    507896d
  12. vstinner commented on Mar 25, 2024

    @vstinner
    vstinner
    on Mar 25, 2024
    MemberAuthor
    More actions

    Implemented in change 507896d

  13. vstinner
    closed this as completedon Mar 25, 2024
  14. NGRsoftlab
    added 2 commits that reference this issue on Apr 2, 2024

    Squashed commit of the following:

    1b5fe4c

    Squashed commit of the following:

    a016a54
  15. diegorusso
    added a commit that references this issue on Apr 17, 2024

    pythongh-116936: Add PyType_GetModuleByDef() to the limited C API (py…

    a5bdc70
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

    topic-C-APItype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      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.