Repository navigation
gh-156725: document O(N) behavior of PyCode_Addr2Line and the private line-table API - #156736
ZeroIntensity merged 4 commits into
Conversation
Documentation build overview
207 files changed ·
|
…rivate line-table API The C-API docs for PyCode_Addr2Line pointed to the PEP 626 section that describes PyLineTable_InitAddressRange / PyLineTable_NextAddressRange / PyLineTable_PreviousAddressRange, but those functions have since been renamed with a leading underscore and moved to the private header Include/internal/pycore_code.h. Point to the current private names, note that they are not a stable public API, and document that PyCode_Addr2Line is O(N).
3f8d96b to
7707506
Compare
| .. warning:: | ||
| These functions are **internal and not a public C-API**. They are | ||
| declared in a private header, may change or be removed without notice, | ||
| and are not exported as stable symbols. |
There was a problem hiding this comment.
I'm not sure if we should document internal. Users should not be calling them, and pointing it from the docs might send the wrong message.
https://docs.python.org/3/c-api/stable.html#:~:text=Names%20prefixed%20by%20an%20underscore
| For efficiently iterating over the line numbers in a code object, use :pep:`the API described in PEP 626 | ||
| <0626#out-of-process-debuggers-and-profilers>`. | ||
| To iterate efficiently over the line numbers in a code object, use the | ||
| private, unstable line-table iteration APIs declared in the private header |
There was a problem hiding this comment.
Unstable has specific meaning:
| ``Include/internal/pycore_code.h``: | ||
|
|
||
| * ``_PyCode_InitAddressRange`` initializes a ``PyCodeAddressRange`` for a code object. | ||
| * ``_PyLineTable_NextAddressRange`` advances the range to the next | ||
| line-number entry. | ||
| * ``_PyLineTable_PreviousAddressRange`` retreats the range to the | ||
| previous entry. | ||
|
|
||
| .. warning:: |
There was a problem hiding this comment.
I agree that we shouldn't document internal APIs. In a separate PR, let's instead promote these to the unstable API.
| instructions in the code object, so it is not suitable for iterating over | ||
| all the line numbers in a code object. |
There was a problem hiding this comment.
I wouldn't say that it's not suitable, it's just not performant:
| instructions in the code object, so it is not suitable for iterating over | |
| all the line numbers in a code object. | |
| instructions in the code object, so it is not performant for iterating over | |
| all the line numbers in a code object. |
|
Thanks for the review @ZeroIntensity and @maurycy! I have updated the wording to |
|
Thanks for the review @ZeroIntensity and @maurycy! I have updated the wording to |
There was a problem hiding this comment.
Per the issue, this API is outdated, and we shouldn't mention it in the docs.
|
|
||
| Return the line number of the 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. This is ``O(N)`` in the number of |
There was a problem hiding this comment.
It may be O(N). It's not a guarantee.
|
Thanks @ZeroIntensity! Updated |
|
Thanks @Himesh-rupchandani for the PR, and @ZeroIntensity for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15. |
|
GH-160453 is a backport of this pull request to the 3.15 branch. |
|
GH-160454 is a backport of this pull request to the 3.14 branch. |
[
Closesgh-156725.Summary
The C-API docs for
PyCode_Addr2Linepointed to the PEP 626 section describingPyLineTable_InitAddressRange,PyLineTable_NextAddressRange, andPyLineTable_PreviousAddressRange. Those functions were renamed with a leadingunderscore and moved to the private header
Include/internal/pycore_code.h; theyare no longer a public C-API.
This docs PR:
PyCode_Addr2Lineis O(N) in the number of instructions;_PyCode_InitAddressRange,_PyLineTable_NextAddressRange,_PyLineTable_PreviousAddressRange) and flagsthem as internal/unstable.
I left the request to expose these as PyUnstable public APIs as a separate feature
proposal, per the issue.](gh-156725: Document O(N) behavior of PyCode_Addr2Line)