gh-92154: Expose PyCode_GetCode in the C API#92168
gh-92154: Expose PyCode_GetCode in the C API#92168Fidget-Spinner merged 5 commits intopython:mainfrom
Conversation
Objects/codeobject.c
Outdated
| PyCode_GetCode(PyObject *co) | ||
| { | ||
| if (!PyCode_Check(co)) { | ||
| PyErr_BadInternalCall(); |
There was a problem hiding this comment.
I forgot if this or a TypeError is preferred for the C API (or no error setting at all?)
There was a problem hiding this comment.
Use PyCode_GetCode(PyCodeObject *co) and then you won't need the check.
There was a problem hiding this comment.
I would like to, but co_code was previously PyObject*, and I want this to be a drop-in replacement as far as possible.
There was a problem hiding this comment.
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.
|
Also I frankly have no clue if we need to update |
Objects/codeobject.c
Outdated
| PyCode_GetCode(PyObject *co) | ||
| { | ||
| if (!PyCode_Check(co)) { | ||
| PyErr_BadInternalCall(); |
There was a problem hiding this comment.
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.
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. |
|
I prepared PR python/pythoncapi-compat#34 to add the function to pythoncapi-compat. |
Fixes #92154.