Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tim-stephenson opened this issue Mar 16, 2025 · 7 comments
Assignees
Labels
3.14 new features, bugs and security fixes build The build process and cross-build interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-JIT type-bug An unexpected behavior, bug, or error

Comments

@tim-stephenson
Copy link

tim-stephenson commented Mar 16, 2025

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

@tim-stephenson tim-stephenson added the type-bug An unexpected behavior, bug, or error label Mar 16, 2025
@tim-stephenson
Copy link
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

@picnixz picnixz added interpreter-core (Objects, Python, Grammar, and Parser dirs) build The build process and cross-build labels Mar 16, 2025
@picnixz
Copy link
Member

picnixz commented Mar 16, 2025

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.

@picnixz
Copy link
Member

picnixz commented Mar 16, 2025

cc @brandtbucher

@tim-stephenson
Copy link
Author

@picnixz picnixz added topic-JIT and removed pending The issue will be closed if no feedback is provided labels Mar 16, 2025
@picnixz
Copy link
Member

picnixz commented Mar 16, 2025

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.

@markshannon
Copy link
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.

@picnixz
Copy link
Member

picnixz commented Mar 18, 2025

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?

@picnixz picnixz added the 3.14 new features, bugs and security fixes label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.14 new features, bugs and security fixes build The build process and cross-build interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-JIT type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants