-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Cython cannot use "pycore_frame.h" in Py3.14a4 #130931
Comments
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 |
Cython directly accesses frames in three places:
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 For exceptions, all we'd need (AFAICT) is a The coroutine support then needs to inject frames into the current stack. For this, we currently read and write There was a Cython ticket about this created by @markshannon a while ago that also never got anywhere. |
@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! |
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 |
Ok if it's just removing the designated initializers that should be easy enough to do. I'll take this up. |
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). |
I 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) |
Seems right to me. |
I'm not sure I understand the renaming of Line 22 in e5527f2
Lines 12 to 15 in e5527f2
|
We should add getters and setters, but not expose the structure members in the public C API. |
It's possible to call |
@vstinner we cant use PyObject_SetAttrString because frame is not a PyObject since 3.11 |
I'm talking about Are you talking about |
Yes I think the current problem is in _PyInterpreterFrame not PyFrameObject |
I wrote PR gh-131246 to add |
Cython works on #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) |
Move _PyInterpreterFrame and associated functions to a new pycore_interpframe.h header.
Add tests on PyFrame_GetBack() and PyFrame_SetBack().
Add tests on PyFrame_GetBack() and PyFrame_SetBack().
Aha, I created PR gh-131252 to add |
I'm fairly sure we just use |
Declare _PyInterpreterFrame and _PyRuntimeState types before declaring their structure members. Break reference cycles between header files.
Move _PyInterpreterFrame and associated functions to a new pycore_interpframe.h header.
Move _PyInterpreterFrame and associated functions to a new pycore_interpframe.h header.
Declare _PyInterpreterFrame and _PyRuntimeState types before declaring their structure members. Break reference cycles between header files.
Move _PyInterpreterFrame and associated functions to a new pycore_interpframe.h header.
I don't think making internal headers usable by anything other than CPython is a good idea. We also change those headers frequently, and if Cython relies on these headers, then Cython is perpetually broken on main. If there is functionality that is needed, then please request a new API. |
Move _PyInterpreterFrame and associated functions to a new pycore_interpframe.h header.
Cython only uses
I agree that it's a bad practice to use the internal C API outside CPython in general, and that's why I proposed two PRs to add functions needed by Cython:
The problem is that it will take time to get these PRs merged, get Cython updated to use them, get a Cython release, and then update code generated by Cython in projects using Cython. That's why I also proposed #131249 to simplify |
Those setter functions are just as bad. Setting the back pointer of a frame object is not, in general, possible as frames are mostly allocated in a contiguous block of memory. |
Move _PyInterpreterFrame and associated functions to a new pycore_interpframe.h header.
For exceptions, should we expose something like the existing
That could create a synthetic code object, a “finished” frame, and traceback entry. Then, when this use case doesn't need users calling |
I'd rather push a normal frame with "function like" and "code like" objects.
No need for a fake code object. |
@da-woods probably knows better, but I believe there's some value in an API that's only called when unwinding an exception. I don't think Cython will want to allocate function-like & code-like objects for every call. |
Cython can push the frame only when an exception is raised with the above API, but we can add a However, it should take function-like and code-like parameters for general consistency and integration with int PyTraceback_Add(PyObject *funclike, PyObject *codelike, int line)
{
PyThreadState *tstate = PyThreadState_GET();
if ((Py_PushExtensionFrame(tstate, funclike, codelike) < 0) return -1;
int err = PyTraceBack_AtLine(line);
Py_PopExtensionFrame(tstate);
return err;
} |
That's probably even better for Cython, which uses a cache to avoid creating duplicate code objects! I assume |
Very little, I think merely having a It isn't CPython that we need to worry about, but coverage, debuggers and other tools. What do they need? |
Bug report
Bug description:
It's this time of the year again. As discussed before (e.g. #123747), Cython
#include
s CPython'spycore_frame.h
to 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.h
was apparently added in #118450:What can we do to resolve this?
CPython versions tested on:
3.14
Operating systems tested on:
Windows
Linked PRs
The text was updated successfully, but these errors were encountered: