You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I've been working on this for a little while, but I'm a bit lost on implementing the changes.
From what I understand think I'm supposed to create a public API to set the f_fileno variable so I used PyAPI_FUNC(int) PyFrame_SetLineNumber(PyFrameObject *f, int lineno) in Include/cpython/frameobject.h which uses frame_setlineno from frameobject.c to change the f_lineno. I've been trying to get a test to pass to verify that this works in Lib/test/test_frame.py but I'm not sure if my approach or logic is correct.
I think is going to be very confusing if PyFrame_SetLineNumber has different behavior from setting the line number in Python frame.f_lineno = ....
The f_lineno field in the the frame object is a cache for the computed line number.
It may overwritten by the interpreter, so setting it will not work reliably.
I suppose that Cython sets f_lineno to produce a traceback with specific line number.
Yes - it's used directly after creating a frame for that purpose.
(It's also used in the old, pre-sys-monitoring code. I would not worry about replacing that usage because I think that's only on older Python versions)
Activity
Ben4C commentedon Aug 14, 2024
Hello, I've been working on this for a little while, but I'm a bit lost on implementing the changes.
From what I understand think I'm supposed to create a public API to set the
f_filenovariable so I usedPyAPI_FUNC(int) PyFrame_SetLineNumber(PyFrameObject *f, int lineno)inInclude/cpython/frameobject.hwhich usesframe_setlinenofromframeobject.cto change thef_lineno. I've been trying to get a test to pass to verify that this works inLib/test/test_frame.pybut I'm not sure if my approach or logic is correct.This is what I have so far: Ben4C@1e82093
pythongh-118720: Add PyFrame_SetLineNumber() function
pythongh-118720: Add PyFrame_SetLineNumber() function
pythongh-118720: Add PyFrame_SetLineNumber() function
vstinner commentedon Mar 14, 2025
This function was also discussed at #130931.
vstinner commentedon Mar 14, 2025
I wrote PR gh-131246 to add
PyFrame_SetLineNumber().markshannon commentedon Mar 17, 2025
I think is going to be very confusing if
PyFrame_SetLineNumberhas different behavior from setting the line number in Pythonframe.f_lineno = ....The
f_linenofield in the the frame object is a cache for the computed line number.It may overwritten by the interpreter, so setting it will not work reliably.
vstinner commentedon Mar 17, 2025
I wrote this function to replace the Cython macro:
#define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno)I suppose that Cython sets
f_linenoto produce a traceback with specific line number.cc @scoder @da-woods
da-woods commentedon Mar 17, 2025
Yes - it's used directly after creating a frame for that purpose.
(It's also used in the old, pre-sys-monitoring code. I would not worry about replacing that usage because I think that's only on older Python versions)
markshannon commentedon Mar 18, 2025
So what are the proposed semantics of
PyFrame_SetLineNumber(), how do we test it?