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
{{ message }}
Repository navigation
[C-API] Add a function to access PyCodeObject.co_code in C #92154
Previously, you could access the co_code field in PyCodeObject directly to access the bytecode. This is no longer the case since 2bde682. Currently in 3.11a7+, C code cannot easily obtain the equivalent of co_code in 3.10. co_code_adaptive gets quickened bytecode which is not equivalent to the 3.10 behavior.
I would imagine many tools relying on the old behavior will break.
Pitch
I propose we expose some form of the currently internal _PyCode_GetCode.
Even if no function is added, please document at least the member removal in https://docs.python.org/dev/whatsnew/3.11.html (C API > Porting to Python 3.11) since the PyCodeObject structure is part of the public C API.
Activity
vstinner commentedon May 2, 2022
See also #91397 "[C API] Move the PyCodeObject structure to the internal C API (make the structure opaque)".
vstinner commentedon May 2, 2022
Even if no function is added, please document at least the member removal in https://docs.python.org/dev/whatsnew/3.11.html (C API > Porting to Python 3.11) since the PyCodeObject structure is part of the public C API.
markshannon commentedon May 2, 2022
Exposing
PyCode_GetCodemakes sense to me, as it equivalent tocode.co_code.@brandtbucher
brandtbucher commentedon May 2, 2022
Sounds good to me as well.
gh-92154: Expose PyCode_GetCode in the C API (GH-92168)
vstinner commentedon May 3, 2022
And I added the function to pythoncapi-compat: python/pythoncapi-compat@85d1bd8