Skip to content

[C API] Don't define the COMPILER macro in the public C API #141341

Closed

Description

@vstinner

On Windows, pyconfig.h defines the COMPILER macro. I propose to rename it to _Py_COMPILER to avoid name conflicts: see https://discuss.python.org/t/pre-pep-use-a-header-file-that-can-undefine-the-macros-defined-by-python-h/104784 for such conflict in practice.

Linked PRs

Activity

  1. added 2 commits that reference this issue on Nov 10, 2025
  2. added
    build
    type-bug
    on Nov 10, 2025
  3. picnixz commented on Nov 10, 2025

    @picnixz
    Member

    I personally think it's a bug but I'm not confident in changing this on bugfixes branches.

  4. vstinner commented on Nov 10, 2025

    @vstinner
    MemberAuthor

    I personally think it's a bug but I'm not confident in changing this on bugfixes branches.

    There might be projects in the wild which use the COMPILER macro. It sounds unlikely since the macro is only defined on Windows. But I'm not comfortable to backport the change to stable branches.

  5. Locked-chess-official commented on Nov 10, 2025

    @Locked-chess-official
    Contributor

    There might be projects in the wild which use the COMPILER macro. It sounds unlikely since the macro is only defined on Windows.

    If the projects use the macros which were defined by "pyconfig.h" but don't start with "Py", it is undocumental so that if these projects crash, there is no wonder.
    Considerring that may be there are the other macros that don't start with "Py" or "_Py" and conflict with other project, I wrote the package "python_undef" to handle it. I think that finally all of the macros that doesn't match PEP7 should be renamed.

  6. encukou commented on Nov 10, 2025

    @encukou
    Member

    See this message from Guido: https://discuss.python.org/t/finishing-the-great-renaming/54082/3

    (FWIW, I've not followed up on that thread for a long time -- I'm waiting for the PEP-743 resolution so I don't need to do renames & deprecations/removal in two steps.)

  7. added a commit that references this issue on Nov 10, 2025
  8. vstinner commented on Nov 10, 2025

    @vstinner
    MemberAuthor

    This problem exists since Python 2.7 (if not longer), so I don't think that there is an urgency to fix it in stable branches. There is a simple workaround: add #undef COMPILER after #include <Python.h>. I close the issue.

  9. added a commit that references this issue on Dec 6, 2025
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

    OS-windowsbuildtopic-C-APItype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions