Skip to content

gh-148871: make LOAD_COMMON_CONSTANT use immortal stackref borrows#149625

Open
NekoAsakura wants to merge 1 commit into
python:mainfrom
NekoAsakura:gh-148871-immortal-stackref
Open

gh-148871: make LOAD_COMMON_CONSTANT use immortal stackref borrows#149625
NekoAsakura wants to merge 1 commit into
python:mainfrom
NekoAsakura:gh-148871-immortal-stackref

Conversation

@NekoAsakura
Copy link
Copy Markdown
Member

@NekoAsakura NekoAsakura commented May 9, 2026

gc.is_tracked(all/any) True -> False

Comment thread Python/bytecodes.c
// Keep in sync with _common_constants in opcode.py
assert(oparg < NUM_COMMON_CONSTANTS);
value = PyStackRef_FromPyObjectNew(tstate->interp->common_consts[oparg]);
value = PyStackRef_DUP(tstate->interp->common_consts[oparg]);
Copy link
Copy Markdown
Member

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 changing PyObject * to _PyStackRef here

Comment thread Python/flowgraph.c
if (opcode == LOAD_COMMON_CONSTANT) {
assert(oparg < NUM_COMMON_CONSTANTS);
return Py_NewRef(_PyInterpreterState_GET()->common_consts[oparg]);
return Py_NewRef(PyStackRef_AsPyObjectBorrow(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
return Py_NewRef(PyStackRef_AsPyObjectBorrow(
return PyStackRef_AsPyObjectBorrow(

These objects are immortal, you can borrow references to them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants