Skip to content

Commit 2bc1255

Browse files
[3.15] gh-156725: Document O(N) behavior of PyCode_Addr2Line (GH-156736) (GH-160453)
(cherry picked from commit 8d11920) Co-authored-by: Himesh Rupchandani <rupchandanihimesh69@gmail.com>
1 parent cc3a0c9 commit 2bc1255

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

‎Doc/c-api/code.rst‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ bound into a function.
9494
9595
.. c:function:: int PyCode_Addr2Line(PyCodeObject *co, int byte_offset)
9696
97-
Return the line number of the instruction that occurs on or before ``byte_offset`` and ends after it.
98-
If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead.
97+
Return the line number of the instruction that occurs on or before
98+
``byte_offset`` and ends after it. This may be ``O(N)`` in the number of
99+
instructions in the code object, so it is not performant for iterating over
100+
all the line numbers in a code object.
99101
100-
For efficiently iterating over the line numbers in a code object, use :pep:`the API described in PEP 626
101-
<0626#out-of-process-debuggers-and-profilers>`.
102+
If you just need the line number of a frame, use :c:func:`PyFrame_GetLineNumber` instead.
102103
103104
.. c:function:: int PyCode_Addr2Location(PyObject *co, int byte_offset, int *start_line, int *start_column, int *end_line, int *end_column)
104105

0 commit comments

Comments
 (0)