This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Semantics of PyCode_Addr2Line() changed
Type: Stage: resolved
Components: Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Mark.Shannon, lukasz.langa, miss-islington, pablogsal
Priority: release blocker Keywords: 3.10regression, patch

Created on 2021-08-20 18:07 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 28200 merged pablogsal, 2021-09-07 11:04
PR 28202 merged miss-islington, 2021-09-07 11:19
PR 28208 merged pablogsal, 2021-09-07 15:07
PR 28276 merged miss-islington, 2021-09-10 15:53
Messages (9)
msg399985 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-20 18:07
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/
msg399986 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-20 18:08
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)
msg400033 - (view) Author: Mark Shannon (Mark.Shannon) * (Python committer) Date: 2021-08-21 15:02
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.
msg400035 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-08-21 16:40
Are you ok if I add a small comment to the what's new of 3.10?
msg401239 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-09-07 11:18
New changeset fa2c0b85a8d5c9486661083afdf38cbaadb3432a 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)
https://github.com/python/cpython/commit/fa2c0b85a8d5c9486661083afdf38cbaadb3432a
msg401243 - (view) Author: miss-islington (miss-islington) Date: 2021-09-07 11:36
New changeset fc840736e54da0557616882012f362b809490165 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)
https://github.com/python/cpython/commit/fc840736e54da0557616882012f362b809490165
msg401585 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-10 15:53
New changeset ab327f2929589407595a3de95727c8ab34ddd4af by Pablo Galindo Salgado in branch 'main':
bpo-44964: Correct the note about the f_lasti field (GH-28208)
https://github.com/python/cpython/commit/ab327f2929589407595a3de95727c8ab34ddd4af
msg401589 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-09-10 16:17
New changeset b045174a6dbf1060f092265853f0c78f0704a21a by Miss Islington (bot) in branch '3.10':
bpo-44964: Correct the note about the f_lasti field (GH-28208) (GH-28276)
https://github.com/python/cpython/commit/b045174a6dbf1060f092265853f0c78f0704a21a
msg403175 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2021-10-04 19:18
New changeset 490a7427dce1cba55a9fbdbccd092e4c8ffae05f by Pablo Galindo (Miss Islington (bot)) in branch '3.10':
bpo-44964: Correct the note about the f_lasti field (GH-28208) (GH-28276)
https://github.com/python/cpython/commit/490a7427dce1cba55a9fbdbccd092e4c8ffae05f
History
Date User Action Args
2022-04-11 14:59:49adminsetgithub: 89127
2021-10-04 19:18:44pablogsalsetmessages: + msg403175
2021-09-10 16:17:00lukasz.langasetmessages: + msg401589
2021-09-10 15:53:50miss-islingtonsetpull_requests: + pull_request26694
2021-09-10 15:53:45lukasz.langasetnosy: + lukasz.langa
messages: + msg401585
2021-09-07 15:07:33pablogsalsetpull_requests: + pull_request26633
2021-09-07 11:36:59miss-islingtonsetnosy: + miss-islington
messages: + msg401243
2021-09-07 11:19:03pablogsalsetstatus: open -> closed
nosy: - miss-islington

resolution: fixed
stage: patch review -> resolved
2021-09-07 11:19:01miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request26627
2021-09-07 11:18:58pablogsalsetmessages: + msg401239
2021-09-07 11:04:47pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request26625
2021-08-21 16:40:14pablogsalsetmessages: + msg400035
2021-08-21 15:02:22Mark.Shannonsetmessages: + msg400033
2021-08-20 18:08:09pablogsalsetmessages: + msg399986
2021-08-20 18:07:40pablogsalcreate