From 5481eefcd83913cb25f3847720ae1c9b892057f1 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Wed, 31 Mar 2021 11:12:37 +0100 Subject: [PATCH 1/2] Document PyCode_Addr2Line function. --- Doc/c-api/code.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/c-api/code.rst b/Doc/c-api/code.rst index b3a17f1898e8e1..5ad9d301efb56d 100644 --- a/Doc/c-api/code.rst +++ b/Doc/c-api/code.rst @@ -51,3 +51,11 @@ bound into a function. Return a new empty code object with the specified filename, function name, and first line number. It is illegal to :func:`exec` or :func:`eval` the resulting code object. + +.. c:function:: int PyCode_Addr2Line(PyCodeObject *co, int byte_offset) + + Return the line number of the of instruction that occurs on or before ``byte_offset`` and ends after it. + If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead. + + For effciently determining line numbers in a code object, use `the API described in PEP 626 + `_. From cb225d0211b18409a8df0db66d5ecaf1d286543f Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Thu, 1 Apr 2021 17:37:41 +0100 Subject: [PATCH 2/2] Fix typo and clarify when to use PEP 626 line iterators. --- Doc/c-api/code.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/code.rst b/Doc/c-api/code.rst index 5ad9d301efb56d..6e18a4225e8f43 100644 --- a/Doc/c-api/code.rst +++ b/Doc/c-api/code.rst @@ -54,8 +54,8 @@ bound into a function. .. c:function:: int PyCode_Addr2Line(PyCodeObject *co, int byte_offset) - Return the line number of the of instruction that occurs on or before ``byte_offset`` and ends after it. + Return the line number of the instruction that occurs on or before ``byte_offset`` and ends after it. If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead. - For effciently determining line numbers in a code object, use `the API described in PEP 626 + For efficiently iterating over the line numbers in a code object, use `the API described in PEP 626 `_.