Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[C-API] Add a function to access PyCodeObject.co_code in C #92154

Closed
Fidget-Spinner opened this issue May 2, 2022 · 5 comments · Fixed by #92168
Closed

[C-API] Add a function to access PyCodeObject.co_code in C #92154

Fidget-Spinner opened this issue May 2, 2022 · 5 comments · Fixed by #92168
Labels
topic-C-API type-feature A feature request or enhancement

Comments

@Fidget-Spinner
Copy link
Member

Feature or enhancement

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.

Previous discussion

Related to #91397.
See also coverage.py issue nedbat/coveragepy#1367

CC @vstinner @nedbat @brandtbucher @markshannon

@Fidget-Spinner Fidget-Spinner added type-feature A feature request or enhancement topic-C-API labels May 2, 2022
@vstinner
Copy link
Member

vstinner commented May 2, 2022

See also #91397 "[C API] Move the PyCodeObject structure to the internal C API (make the structure opaque)".

@vstinner
Copy link
Member

vstinner commented 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
Copy link
Member

Exposing PyCode_GetCode makes sense to me, as it equivalent to code.co_code.

@brandtbucher

@brandtbucher
Copy link
Member

Sounds good to me as well.

@vstinner
Copy link
Member

vstinner commented May 3, 2022

And I added the function to pythoncapi-compat: python/pythoncapi-compat@85d1bd8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-C-API type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants