-
-
Notifications
You must be signed in to change notification settings - Fork 437
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
frame->f_lasti will be removed in Python 3.11 #1241
Comments
Discussion on Python upstream about adding abstractions to PyFrameObject for coverage use cases: https://bugs.python.org/issue40421#msg403814 |
Adapting MyFrame_lasti() to Python 3.11 requires to dig into deep CPython internals, use the internal C API. Something like:
I would prefer to write an abstraction in the public C API for that, or maybe add a private function just for coverage. If possible, I would prefer to avoid accessing CPython internals in coverage. |
For the PyFrame_GetLineNumber() code path, maybe there is a simple fix. PyFrame_GetLineNumber() now handles negative f_lasti, and so ctracer doesn't have to handle it manually. I propose a fix like that:
|
Thanks for starting this: it's been on my list to ask about what to do about f_lasti disappearing. |
@markshannon Can you help here? |
@nedbat, that depends on what you use f_lasti for. I can see it in tracer.c: coveragepy/coverage/ctracer/tracer.c Lines 548 to 557 in 001f653
PyFrame_GetLineNumber deficiency; as Victor said this shouldn't be necessary in 3.10+.
And the other use is coveragepy/coverage/ctracer/tracer.c Lines 712 to 729 in 001f653
This assumes that the "current instruction" is part of the original bytecode, which is, AFAIK, not always the case any more. I'm not exactly sure what this code actually needs to do, but it doesn't look like you need |
Yes, I'm using lasti to distinguish between entering a frame for the first time, and re-entering the frame. Typing that out makes me wonder if I can do my own bookkeeping to distinguish between them... (never mind, I don't think there's enough information for me to track it on my own.) As an API, the unused third arg could provide the information that distinguishes call from resume and return from yield. |
I've worked around the problem in 9765493, but it's not pretty. |
This is now released as part of coverage 6.1.2. |
FYI it is intentional that the internal C API is accessible so debuggers and profilers can inspect structures without having to execute code. But I agree that adding a public C API would be a better solution for the long term :-) |
@vstinner I don't understand: is |
In general, you should not use the internal C API, unless you are writing a debugger or a profiler, which is your case :-) |
If you opt-in for the internal C API, be prepared for incompatible changes at any Python release, major (3.x) or minor (3.x.y). |
Describe the bug
In Python 3.11, the
f_lasti
member of PyFrameObject will be removed.AFAIK, the quickened interpreter uses a different strategy to track what it's executing; a byte offset into original bytecode would need to be computed from other data (and probably wouldn't make sense in some cases).
This is an early heads-up; you might want to be part of the conversation in CPython so a better API can be designed for
coverage
's use case.AFAICS, coverage uses
f_lasti
for generators, but I'm not really sure what the code is actually doing. Should CPython add API for telling just-started generator apart from a resuming generator, for example?To Reproduce
380c440875
)0eaeb99f2d
)pip freeze
output is emptypython3 setup.py build
Expected behavior
The extension compiles :)
The text was updated successfully, but these errors were encountered: