Skip to content
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

Semantics of PyCode_Addr2Line() changed #89127

Closed
pablogsal opened this issue Aug 20, 2021 · 9 comments
Closed

Semantics of PyCode_Addr2Line() changed #89127

pablogsal opened this issue Aug 20, 2021 · 9 comments
Labels
3.10 only security fixes 3.11 only security fixes release-blocker

Comments

@pablogsal
Copy link
Member

BPO 44964
Nosy @ambv, @markshannon, @pablogsal, @miss-islington
PRs
  • bpo-44964: Add a note explaining the new semantics of f_last_i in frame objects #28200
  • [3.10] bpo-44964: Add a note explaining the new semantics of f_last_i in frame objects (GH-28200) #28202
  • bpo-44964: Correct the note about the f_lasti field #28208
  • [3.10] bpo-44964: Correct the note about the f_lasti field (GH-28208) #28276
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-09-07.11:19:03.779>
    created_at = <Date 2021-08-20.18:07:40.166>
    labels = ['release-blocker', '3.10', '3.11']
    title = 'Semantics of PyCode_Addr2Line() changed'
    updated_at = <Date 2021-10-04.19:18:44.150>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2021-10-04.19:18:44.150>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-09-07.11:19:03.779>
    closer = 'pablogsal'
    components = []
    creation = <Date 2021-08-20.18:07:40.166>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 44964
    keywords = ['patch', '3.10regression']
    message_count = 9.0
    messages = ['399985', '399986', '400033', '400035', '401239', '401243', '401585', '401589', '403175']
    nosy_count = 4.0
    nosy_names = ['lukasz.langa', 'Mark.Shannon', 'pablogsal', 'miss-islington']
    pr_nums = ['28200', '28202', '28208', '28276']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue44964'
    versions = ['Python 3.10', 'Python 3.11']

    @pablogsal
    Copy link
    Member Author

    I have noticed that the semantics of PyCode_Addr2Line() have changed from 3.9 to 3.10. Technically, the function was called with:

    PyCode_Addr2Line(frame->f_code, frame->f_last_i * 2)

    but now it needs to be called with

    PyCode_Addr2Line(frame->f_code, frame->f_last_i * 2)

    This is likely going to break all users of this function. This is also not advertised in the 3.10 "how to port to Python 3.10" section.

    We should discuss what's the best approach here because technically this is a backwards incompatible change, although in the other hand PyCode_Addr2Line() was not documented previously so we may have some room.

    We need to decide on this ASAP, because there is only one extra release candidate before the actual release of 3.10/

    @pablogsal pablogsal added 3.10 only security fixes 3.11 only security fixes release-blocker labels Aug 20, 2021
    @pablogsal
    Copy link
    Member Author

    Sorry, bad copy paste. Correction:

    Technically, the function was called with:

    PyCode_Addr2Line(frame->f_code, frame->f_last_i)

    but now it needs to be called with

    PyCode_Addr2Line(frame->f_code, frame->f_last_i * 2)

    @markshannon
    Copy link
    Member

    It is not PyCode_Addr2Line() that has changed, but frame->f_lasti.

    If you call
    PyCode_Addr2Line(frame->f_code, 8) in 3.9

    you get the same behavior as calling

    PyCode_Addr2Line(frame->f_code, 8) in 3.10.

    Assuming the bytecode is unchanged.

    The difference is that for the nth instruction frame->f_lasti is n*2 for 3.9 and n for 3.10.

    People should be using PyFrame_GetLineNumber(), which is part of the API.

    @pablogsal
    Copy link
    Member Author

    Are you ok if I add a small comment to the what's new of 3.10?

    @pablogsal
    Copy link
    Member Author

    New changeset fa2c0b8 by Pablo Galindo Salgado in branch 'main':
    bpo-44964: Add a note explaining the new semantics of f_last_i in frame objects (GH-28200)
    fa2c0b8

    @miss-islington
    Copy link
    Contributor

    New changeset fc84073 by Miss Islington (bot) in branch '3.10':
    bpo-44964: Add a note explaining the new semantics of f_last_i in frame objects (GH-28200)
    fc84073

    @ambv
    Copy link
    Contributor

    ambv commented Sep 10, 2021

    New changeset ab327f2 by Pablo Galindo Salgado in branch 'main':
    bpo-44964: Correct the note about the f_lasti field (GH-28208)
    ab327f2

    @ambv
    Copy link
    Contributor

    ambv commented Sep 10, 2021

    New changeset b045174 by Miss Islington (bot) in branch '3.10':
    bpo-44964: Correct the note about the f_lasti field (GH-28208) (GH-28276)
    b045174

    @pablogsal
    Copy link
    Member Author

    New changeset 490a742 by Pablo Galindo (Miss Islington (bot)) in branch '3.10':
    bpo-44964: Correct the note about the f_lasti field (GH-28208) (GH-28276)
    490a742

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes release-blocker
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants