Skip to content

Cannot include cpython/Include/internal/pycore_optimizer.h in C++ extension due to use of protected C++ keyword "not" #131331

Closed

Description

@tim-stephenson

Bug report

Bug description:

The code in cpython/Include/internal/pycore_optimizer.h causing problems

typedef struct {
    uint8_t tag;
    bool not;
    uint16_t value;
} JitOptTruthiness;

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Activity

  1. tim-stephenson commented on Mar 16, 2025

    @tim-stephenson
    Author

    My understanding is that there is no good way around this for C++ extensions: https://stackoverflow.com/questions/72177535/how-can-i-include-a-c-header-that-uses-a-c-keyword-as-an-identifier-in-c

  2. added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    buildThe build process and cross-build
    on Mar 16, 2025
  3. picnixz commented on Mar 16, 2025

    @picnixz
    Member

    AFAIK, cpython/Include/internal/pycore_optimizer.h is not meant to be included directly, nor from an extension module as it's internal. Is there an issue because of some indirect includes if one uses #include "Python.h"? or is this only caused when one tries to include that specific header?

    EDIT: I'm marking it as a release blocker if this implies that C++ extensions cannot be built anymore but if it's because of internal includes, then we can remove the label.

  4. picnixz commented on Mar 16, 2025

    @picnixz
    Member
  5. tim-stephenson commented on Mar 16, 2025

    @tim-stephenson
    Author
  6. added and removed
    pendingThe issue will be closed if no feedback is provided
    on Mar 16, 2025
  7. picnixz commented on Mar 16, 2025

    @picnixz
    Member

    I think it doesn't hurt on our side if just use something else than not. We can use not_. I'll make a PR for that.

    EDIT: However, I would like to mention that using internal headers is at one's own risk, though, in this case, the fix on our side is easy.

  8. self-assigned this
    on Mar 16, 2025
  9. markshannon commented on Mar 18, 2025

    @markshannon
    Member

    I would argue that allowing internal headers to be accessed in third-party code does hurt us.
    Accessing the internals without a clear understanding of the necessary invariants can leave the VM in a broken state.
    The resulting issues can be hard to debug and can consume of a lot of our time.

    Regarding the numba issue. If there is a feature that is needed but does not have a public API, then we need to tell extension developers to submit a feature request, like this one from the Cython developers.

  10. picnixz commented on Mar 18, 2025

    @picnixz
    Member

    I would argue that allowing internal headers to be accessed in third-party code does hurt us.

    Yes, in general, that's what I would say. But if the fix is simple enough and if it's easier than to make a feature request, then I'd say let's do it on our side. But I agree that I would prefer not to worry about compatibilty with projects including internal headers.

    Would you be willing to consider accepting my fix for this specific issue though?

  11. added a commit that references this issue on Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixesbuildThe build process and cross-buildinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-JITtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions