Skip to content

The Python C API should only define macros with a name starting wit Py #157695

Closed

Activity

  1. vstinner commented on Sep 17, 2026

    @vstinner
    MemberAuthor

    The following Include/ header files are not included by Python.h and defines many macros which don't start with Py prefix:

    • opcode.h
    • opcode_ids.h
    • errcode.h
    • osdefs.h
    • structmember.h

    To clean up the C API, a simple move would be to move these header files to the internal C API. Problem: they are actually used in the wild (well, as usual ;-)).

    I checked PyPI top 15,000 projects (at 2026-09-17) to find projects including these header files.

    Projects (10) including opcode.h:

    • coverage (7.16.1)
    • crosshair_tool (0.0.110)
    • ddtrace (4.15.0)
    • nuitka (4.2.1)
    • pygments (2.21.0)
    • pyobjc_core (12.2.2)
    • pywinpty (3.0.5)
    • rook (0.1.209)
    • slipcover (1.1.0)
    • yappi (1.7.6)

    I found no project including errcode.h.

    Projects (4) including osdefs.h:

    • freeze_core (0.7.5)
    • mod_wsgi (6.0.6)
    • nuitka (4.2.1)
    • scandir (1.10.0)

    Projects (169) including structmember.h:

    • MySQL-python (1.2.5)
    • PyICU-binary (2.7.4)
    • PyQt5 (5.15.11)
    • ... the list is quite long, I prefer to truncate it! :-)

    For example, I searched for include\s+["<]errcode\.h[">] for errcode.h include.

  2. vstinner commented on Sep 17, 2026

    @vstinner
    MemberAuthor

    This check is similar to "make smelly" which fails if libpython exports symbols with a name which doesn't start with "Py".

  3. vstinner commented on Sep 17, 2026

    @vstinner
    MemberAuthor
  4. vstinner commented on Sep 17, 2026

    @vstinner
    MemberAuthor

    See issue gh-149685 "Use _Py prefix for private C API added in 3.15" for a recent change (last May) about a similar issue.

  5. added 4 commits that reference this issue on Sep 19, 2026
  6. Locked-chess-official commented on Sep 22, 2026

    @Locked-chess-official
    Contributor

    I have an immature idea: For configures, we can move the private configure macros into a new file named pycore_pyconfig.h

  7. encukou commented on Sep 22, 2026

    @encukou
    Member

    Projects (169) including structmember.h:

    structmember.h has been deprecated in docs (which we now call soft deprectation) since 3.12. See also the comment in the header.
    IMO, exposing legacy non-Py_-prefixed names via an opt-in #include is perfectly fine.

  8. vstinner commented on Sep 22, 2026

    @vstinner
    MemberAuthor

    I'm not sure that autotools support multiple output files where some macros are defined in a file, and other macros are defined in another file.

    configure.ac uses AC_CONFIG_HEADERS([pyconfig.h]).

  9. 5 remaining items

  10. added 4 commits that reference this issue on Oct 6, 2026
  11. added a commit that references this issue on Nov 18, 2026
  12. vstinner commented on Nov 18, 2026

    @vstinner
    MemberAuthor

    I propose adding a check to prevent adding new macros which doesn't respect this convention.

    The initial issue has been fixed by adding Tools/build/check_capi_macros.py script to the main branch. I close the issue.

  13. added 5 commits that reference this issue on Nov 18, 2026
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

    buildThe build process and cross-buildextension-modulesC modules in the Modules dirinfraCI, GitHub Actions, buildbots, Dependabot, etc.interpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-API

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions