python / python/cpython

Implement PEP 793 – PyModExport

未關閉
#140,550 3 則留言 5 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

interpreter-core topic-C-API type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Feature or enhancement

Proposal:

See PEP 793. I'll copy the abstract for reference:

In this PEP, we propose a new entry point for C extension modules, by which one can define a module using an array of PyModuleDef_Slot structures without an enclosing PyModuleDef structure. This allows extension authors to avoid using a statically allocated PyObject, lifting the most common obstacle to making one compiled library file usable with both regular and free-threaded builds of CPython.

To make this viable, we also specify new module slot types to replace PyModuleDef’s fields, and to allow adding a token similar to the Py_tp_token used for type objects.

We also add an API for defining modules from slots dynamically.

The existing API (PyInit_*) is soft-deprecated. (That is: it will continue to work without warnings, and it’ll be fully documented and supported, but we plan to not add any new features to it.)


  • Initial implementation (#140556)
  • Docs:
    • Reference docs (#141197)
      • Soft-deprecate PyInit_* (#141197)
      • Better explanation of module state (#141197)
      • Give an example for tokens (#141197)
    • What's New
      • a notice for DYNLOADFILE users? (edit: This shouldn't have changed/broken more than usual.)
    • Porting guide HOWTO
      • Document that the export hook runs without GIL in FT builds (see #141780) (#151661)
    • Tutorial update (#142314)
    • Mentions in PyImport_AppendInittab & friends (#151661)
    • Make sure references to new API are linked:
      • PyMod_Execin PyImport_CreateModuleFromInitfunc docs is linked (#141197)
      • PyMODEXPORT_FUNC in blurb for #141672
      • blurb for #141780
  • xxlimited.c update (#142827)
    • Remove/replace _Py_OPAQUE_PYOBJECT in xxlimited.c (by 3.15.0 beta)

Optional stretch goals:

  • Remove the PyInit function from Lib/test/test_cext/extension.c (https://github.com/python/cpython/pull/141511)
  • Speed & size improvements
    • importdl: load the DLL once
    • bool for the GIL flag (#141519)
  • No longer require spec.name in PyModule_FromSlotsAndSpec
  • No longer require static allocation for Py_mod_methods
  • Add a PyModule_GetStateWithToken() function
Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs
  • gh-140556
  • gh-141056
  • gh-141197
  • gh-141511
  • gh-141519
  • gh-142583
  • gh-142827
  • gh-144340
  • gh-149397
  • gh-149785
  • gh-151661
  • gh-152064
  • gh-157493
  • gh-157494
  • gh-157539
  • gh-157560

See also:

  • gh-141672
  • gh-142314

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

檢視 PEP 793 提案以及尚未勾選的 stretch goal,尤其是 Lib/test/test_cext/extension.c 和 importdl 項目。先檢查連結的實作與文件工作,然後找出一個具體的剩餘目標及其現有的測試或進入點;當該目標已實作並由相關文件或測試涵蓋時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
c, python
領域
backend-api-design
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
20/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。