FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-92154: Expose PyCode_GetCode in the C API by Fidget-Spinner · Pull Request #92168 · python/cpython · GitHub

/ cpython Public

gh-92154: Expose PyCode_GetCode in the C API - #92168

Merged
Fidget-Spinner merged 5 commits into
python:mainfrom
Fidget-Spinner:pycode_getcode
May 3, 2022
Merged

gh-92154: Expose PyCode_GetCode in the C API#92168
Fidget-Spinner merged 5 commits into
python:mainfrom
Fidget-Spinner:pycode_getcode

Conversation

Fidget-Spinner commented May 2, 2022
edited
Loading

Copy link
Copy Markdown
Member

Fixes #92154.

Comment thread Objects/codeobject.c Outdated
PyCode_GetCode(PyObject *co)
{
if (!PyCode_Check(co)) {
PyErr_BadInternalCall();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I forgot if this or a TypeError is preferred for the C API (or no error setting at all?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Use PyCode_GetCode(PyCodeObject *co) and then you won't need the check.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would like to, but co_code was previously PyObject*, and I want this to be a drop-in replacement as far as possible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

PyErr_BadInternalCall() is fine, but I would even suggest replacing a runtime check with an assertion. The caller is responsible to pass the right type.

Copy link
Copy Markdown
Member Author

Also I frankly have no clue if we need to update stable_abi.toml. I'm not sure when it counts as stable ABI and when it doesn't.

Comment thread Doc/c-api/code.rst Outdated
Comment thread Doc/whatsnew/3.11.rst
Comment thread Doc/whatsnew/3.11.rst Outdated
Comment thread Doc/whatsnew/3.11.rst
Comment thread Objects/codeobject.c Outdated
PyCode_GetCode(PyObject *co)
{
if (!PyCode_Check(co)) {
PyErr_BadInternalCall();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

PyErr_BadInternalCall() is fine, but I would even suggest replacing a runtime check with an assertion. The caller is responsible to pass the right type.

vstinner commented May 3, 2022

Copy link
Copy Markdown
Member

Also I frankly have no clue if we need to update stable_abi.toml. I'm not sure when it counts as stable ABI and when it doesn't.

Include/cpython/ is the API excluded from the limited C API and so excluded from the stable ABI: https://devguide.python.org/c-api/

Please don't add this function to the stable ABI yet. Let's wait for one Python release, and then see if it's stable or not.

Comment thread Doc/c-api/code.rst Outdated

vstinner commented May 3, 2022

Copy link
Copy Markdown
Member

I prepared PR python/pythoncapi-compat#34 to add the function to pythoncapi-compat.

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants


Back | FazBrowse Home | New Git URL