-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-27129: Use instruction offsets, not byte offsets, in bytecode and internally. #25069
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
Changes from all commits
05a6c62
5d3c577
2a93cf1
a6f3a79
db2f86b
325d135
3d3b995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| The bytecode interpreter uses instruction, rather byte, offsets internally. | ||
| This reduces the number of EXTENDED_ARG instructions needed and streamlines | ||
| instruction dispatch a bit. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1246,7 +1246,7 @@ PyTypeObject PyCode_Type = { | |
| int | ||
| PyCode_Addr2Line(PyCodeObject *co, int addrq) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer to treat the second argument as an instruction offset, rather than a byte offset. Rather than changing PyCode_Addr2Line() calls. It sounds unfortunate that the API allows to ask the address in the middle of a word (2 bytes). It sounds common to pass f_lasti to PyCode_Addr2Line(): PyCode_Addr2Line(code, f_lasti) would still work, no?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depends on how you think the API is defined.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Also see: |
||
| { | ||
| if (addrq == -1) { | ||
| if (addrq < 0) { | ||
| return co->co_firstlineno; | ||
| } | ||
| assert(addrq >= 0 && addrq < PyBytes_GET_SIZE(co->co_code)); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not go a step further and divide the labels in dis output by 2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. However now we have a confusing discrepancy between what's displayed and how we're encouraged to think about the bytecode in the C code. I guess there's no perfect answer, so status quo wins.