[issue46356] [C API] Enforce usage of PyFrame_GetBack()

STINNER Victor report at bugs.python.org
Wed Jan 12 12:02:21 EST 2022


STINNER Victor <vstinner at python.org> added the comment:

> I don't know how we can stop people from using them though.

The first option is to promote helper functions to abstract access to the PyFrameObject structure.

The second option is to make the whole structure opaque and enforce the usage of helper functions. Before being able to do that, we need to prepare Cython and a few more popular C extensions for that. Right now, Cython still has a lot of code accessing directly PyFrameObject members.

Well, we can discuss that in bpo-40421 ;-)


> If they don't know better than pulling data out of undocumented internal struct, then I'm not sure an underscore prefix is going to help. It won't do any harm, though.

I propose to rename f_back to trigger a build error for existing C extensions which access it directly. So developers have to decide how to handle the change: access the renamed member, or read the doc and use a better way, call PyFrame_GetBack() :-)

I dislike that this incompatible change is "silent" and that developers may only notice the change in production, when it's too late.

Or maybe most C extensions have a a good test suite and will notice the change before it's too late.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46356>
_______________________________________


More information about the Python-bugs-list mailing list