python / cpython

The Python programming language
https://www.python.org
Other
62.84k stars 30.1k forks source link

Add PyFrame_SetLineNumber() for Cython #118720

Open methane opened 5 months ago

methane commented 5 months ago

Feature or enhancement

Proposal:

CPython hides PyFrameObject internals so Cython include pycore_frame.h to set f_lineno. Let's provide PyFrame_SetLineNumber() for Cython.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

https://github.com/python/cpython/pull/117551#issuecomment-2097718129

Ben4C commented 1 month ago

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.

This is what I have so far: https://github.com/Ben4C/cpython/commit/1e8209351649ae0e80943dbf4a08cd5ac6460983