summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
Diffstat (limited to 'Doc')
-rw-r--r--Doc/c-api/code.rst14
-rw-r--r--Doc/whatsnew/3.11.rst5
2 files changed, 19 insertions, 0 deletions
diff --git a/Doc/c-api/code.rst b/Doc/c-api/code.rst
index 407d8b4..7915b81 100644
--- a/Doc/c-api/code.rst
+++ b/Doc/c-api/code.rst
@@ -76,3 +76,17 @@ bound into a function.
information is not available for any particular element.
Returns ``1`` if the function succeeds and 0 otherwise.
+
+.. c:function:: PyObject* PyCode_GetCode(PyCodeObject *co)
+
+ Equivalent to the Python code ``getattr(co, 'co_code')``.
+ Returns a strong reference to a :c:type:`PyBytesObject` representing the
+ bytecode in a code object. On error, ``NULL`` is returned and an exception
+ is raised.
+
+ This ``PyBytesObject`` may be created on-demand by the interpreter and does
+ not necessarily represent the bytecode actually executed by CPython. The
+ primary use case for this function is debuggers and profilers.
+
+ .. versionadded:: 3.11
+
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index 607f2e7..c19f158 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -1412,6 +1412,11 @@ C API Changes
To get a custom code object: create a code object using the compiler,
then get a modified version with the ``replace`` method.
+* :c:type:`PyCodeObject` no longer has a ``co_code`` field. Instead,
+ use ``PyObject_GetAttrString(code_object, "co_code")`` or
+ :c:func:`PyCode_GetCode` to get the underlying bytes object.
+ (Contributed by Brandt Bucher in :issue:`46841` and Ken Jin in :gh:`92154`.)
+
New Features
------------