Repository navigation
Cython cannot use "pycore_frame.h" in Py3.14a4 #130931
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Mar 6, 2025 - addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Mar 7, 2025 Added by @Fidget-Spinner & @colesbury, back in June.
What kind of public/unstable API would Cython need so it could avoid the internal headers?
I think we should be able to make it compliant with the C compiler Cython is using
What kind of public/unstable API would Cython need so it could avoid the internal headers?
Cython directly accesses frames in three places:
- profiling/tracing
- exceptions/tracebacks
- coroutines
We already got rid of direct frame usage for tracing in Py3.13+ by migrating to the new monitoring C-API. Sadly, that currently excludes coverage reporting since
coverage.pycannot use it with plugins yet (such as the Cython coverage plugin). That'll eventually come, I hope, but it's not a CPython issue. It just means that you cannot currently use coverage reporting of Cython code in Python 3.14, as long ascoverage.pyneeds this (old, pre-monitoring) code that requirespycore_frame.h(which doesn't currently compile in C++11):For exceptions, all we'd need (AFAICT) is a
PyFrame_SetLineNumber(frame, lineno). This has been mentioned before in #118720 but was never implemented.The coroutine support then needs to inject frames into the current stack. For this, we currently read and write
f_back:There was a Cython ticket about this created by @markshannon a while ago that also never got anywhere.
cython/cython#4484Reacted by Petr Viktorin@scoder could you please point out the C++ standard violations in your CPython alpha? The line number you posted for the alpha doesn't seem to match up with the current source. I think there's been some changes between then. Thanks!
The line number you posted for the alpha doesn't seem to match up with the current source.
Yeah, this output was copied from a Github Actions run of MSVC, which notoriously reports randomly displaced line numbers. I regularly end up looking broadly around the reported lines to guess my way towards potential code candidates for the reported errors and warnings. I have no idea how people can make productive use of such a compiler.
I actually failed to find any designated initializers in
pycore_frame.hmyself, but they are definitely used inpycore_stackref.h. The issue then is that they long existed in C99 but only came into C++ very late, in C++20. Usually not an issue for internal headers in a C project like CPython these days, unless someone needs to access internal headers from C++ code.Ok if it's just removing the designated initializers that should be easy enough to do. I'll take this up.
#define PyStackRef_True ((_PyStackRef){.bits = (uintptr_t)&_Py_TrueStruct }) #define PyStackRef_False ((_PyStackRef){.bits = ((uintptr_t)&_Py_FalseStruct) }) #define PyStackRef_None ((_PyStackRef){.bits = ((uintptr_t)&_Py_NoneStruct) })I'm afraid the compiler complaints are about two features: C7555 is for designated initializers but C4576 is for compound literals (the cast-like syntax).
Reacted by Ken JinI think I'm going to wait for @markshannon to land his PR on stackrefs first.
@encukou the cast-like syntax is going to be hard to fix without losing some performance on msvc. I'm not sure what to do for those. Any thoughts?
(I'm happy to do that, especially the docs part, if that seems right to y'all)
39 remaining items
- removedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Apr 16, 2025 To set expectations: I won't work on this in the foreseeable future. Happy to do reviews.
The initial issue (Cython cannot use "pycore_frame.h" in Py3.14a4) has been fixed. Can we close this issue?
- addedinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)buildThe build process and cross-buildThe build process and cross-buildtriagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.pendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is providedand removedbuildThe build process and cross-buildThe build process and cross-buildinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
on Oct 9, 2025 I believe so (sorry for all those labels; I thought it was a new issue)
- removedpendingThe issue will be closed if no feedback is providedThe issue will be closed if no feedback is provided
on Oct 9, 2025 I'd prefer keeping this open for #130931 (comment)
Couldn't we open a separate issue for this one in particular? it's burried in the list of comments and not visible by default. It's also a separate matter (a new feature that will need docs & co, nothing to do with the current title)
Reacted by Victor Stinner and Petr Viktorin
Bug report
Bug description:
It's this time of the year again. As discussed before (e.g. #123747), Cython
#includes CPython'spycore_frame.hto get access to certain frame features, e.g. their integration into tracebacks.I noticed that Cython generated code doesn't compile in CPython 3.14 alpha with the following kind of errors:
This is from one of our Windows CI runs. Py3.14a4 seems to be what Github Actions currently provides. Cython code expects C99 and something close to (but not necessarily as complete as) C++11 as compiler standards. It targets both C and C++, depending on user needs.
The dependency on
pycore_stackref.hwas apparently added in #118450:What can we do to resolve this?
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs