This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Mark.Shannon, scoder, vstinner
Date 2020-05-07.15:13:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1588864413.79.0.329464661042.issue40421@roundup.psfhosted.org>
In-reply-to
Content
> Please don't add any setter functions, that would a major change to the VM and would need a PEP.

There is no such "major change". PyFrameObject structure was fully exposed in the public C API since the earliest Python version.

I don't see how adding setter is a major change, since it's already possible to directly modify *any* field of PyFrameObject without any kind of protection.

My plan is to have two milestones:

A) Make the structure opaque, so it's not longer possible to directly access it.

B) Deprecate or remove a few getter or setter functions, or move them to the internal C API.


I don't think that moving directly to step (B) is a realistic migration plan. So far, nobody analyzed all C extensions on PyPI to see how PyFrameObject is accessed.

I prefer to move slowly, step by step.

Breaking C extensions which currently *modify* directly PyFrameObject on purpose doesn't seem like a reasonable option to me.

--

I'm trying to distinguish functions which should be "safe"/"portable" from the ones which may be too "CPython specific":

* I added Include/pyframe.h which is included by Include/Python.h for "safe"/"portable" functions:

  * PyFrame_GetLineNumber()
  * PyFrame_GetCode()

* All other functions are added to Include/cpython/frameobject.h which is excluded from the limited C API:

  * PyFrame_GetBack()

Note: Compared to accessing directly PyFrameObject.f_code, PyFrame_GetCode() also avoids the issue of borrowed references since it returns a strong reference.

PyFrame_GetBack() looks specific to the current implementation of CPython. Another implementation might decide to not chain frames. Or maybe don't provide an easy way to traverse the chain of frames. Or at least, it might be a different API than PyFrame_GetBack().

--

> Also, could you remove PyFrame_GetLastInstr(PyFrameObject *frame)?

I didn't add it :-) It's the pending PR 19764.

I didn't merge it since it's unclear to me if it's a good idea to directly expose it or not. Cython uses it, but Cython also abuses CPython internals in general, usually for best performances :-)

*Maybe* one compromise would be to add a private _PyFrame_GetLastInstr() to ease migration to step (A) (replace direct access to the structure with function calls).
History
Date User Action Args
2020-05-07 15:13:33vstinnersetrecipients: + vstinner, scoder, Mark.Shannon
2020-05-07 15:13:33vstinnersetmessageid: <1588864413.79.0.329464661042.issue40421@roundup.psfhosted.org>
2020-05-07 15:13:33vstinnerlinkissue40421 messages
2020-05-07 15:13:33vstinnercreate