Skip to content

Document PyCode_Addr2Line function. #25111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2021

Conversation

markshannon
Copy link
Member

No description provided.

.. 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.
This function is kept for backwards compatibility, its use is not recommended.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this function should not be used, I suggest to officially deprecate it. Add ".. deprecated:: 3.10", add it to https://docs.python.org/dev/whatsnew/3.10.html#id3 and add Py_DEPRECATED() in the header file where it's defined. Usually, we wait at two Python releases before removing a function (PEP 387).

I checked Tools/gdb/libpython.py: it reimplements this function :-)

    def addr2line(self, addrq):
        '''
        Get the line number for a given bytecode offset

        Analogous to PyCode_Addr2Line; translated from pseudocode in
        Objects/lnotab_notes.txt
        '''

Comment on lines 60 to 61
For determining line numbers in a code object, use the API described in PEP 626:
https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For determining line numbers in a code object, use the API described in PEP 626:
https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers
For determining line numbers in a code object, use `the API described in the PEP 626
<https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers>`_.

@markshannon
Copy link
Member Author

@vstinner Since the functions in PEP 626 aren't technically part of the API. We probably don't want to deprecate this.
I've updated the wording.

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
<https://www.python.org/dev/peps/pep-0626/#out-of-process-debuggers-and-profilers>`_.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand. PyLineTable_InitAddressRange() doesn't seem to be implemented in Python 3.10. Do you plan to implement it?

If it's not implemented yet, I suggest to remove this paragraph, and add it once it will be implemented.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is implemented https://github.com/python/cpython/blob/master/Objects/codeobject.c#L1259
It isn't part of the API, though. Which is why we need to keep PyCode_Addr2Line


.. 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
For effciently determining line numbers in a code object, use `the API described in PEP 626
For effeciently determining line numbers in a code object, use `the API described in PEP 626

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

No "versionadded" is needed, it exists since Python 3.0 (and nothing exists before Python 3).

@markshannon markshannon merged commit 58384c6 into python:master Apr 2, 2021
@markshannon markshannon deleted the doc-api-func branch August 23, 2021 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants