-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
gh-148871: make LOAD_COMMON_CONSTANT use immortal stackref borrows
#149625
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ | |||||
| #include "pycore_opcode_utils.h" | ||||||
| #include "pycore_opcode_metadata.h" // OPCODE_HAS_ARG, etc | ||||||
| #include "pycore_pystate.h" // _PyInterpreterState_GET() | ||||||
| #include "pycore_stackref.h" // PyStackRef_AsPyObjectBorrow() | ||||||
|
|
||||||
| #include <stdbool.h> | ||||||
|
|
||||||
|
|
@@ -1330,7 +1331,8 @@ get_const_value(int opcode, int oparg, PyObject *co_consts) | |||||
| } | ||||||
| if (opcode == LOAD_COMMON_CONSTANT) { | ||||||
| assert(oparg < NUM_COMMON_CONSTANTS); | ||||||
| return Py_NewRef(_PyInterpreterState_GET()->common_consts[oparg]); | ||||||
| return Py_NewRef(PyStackRef_AsPyObjectBorrow( | ||||||
|
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.
Suggested change
These objects are immortal, you can borrow references to them. |
||||||
| _PyInterpreterState_GET()->common_consts[oparg])); | ||||||
| } | ||||||
|
|
||||||
| if (constant == NULL) { | ||||||
|
|
||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
This needs to check the tag.
Could you add
PyStackRef_DupImmortal(ref)which would return its argument unchanged and assert that the referenced object is immortal, otherwise it defeats the point of changingPyObject *to_PyStackRefhere