Skip to content

Conversation

@corona10
Copy link
Member

@corona10 corona10 commented Dec 14, 2025

@corona10 corona10 marked this pull request as draft December 14, 2025 14:27
@corona10 corona10 changed the title gh-134584: Eliminate redundant refcounting from _STORE_SUBSCR_DICT [wip] gh-134584: Eliminate redundant refcounting from _STORE_SUBSCR_DICT Dec 14, 2025
}
INPUTS_DEAD();
st = dict_st;
sb = sub;
Copy link
Member

Choose a reason for hiding this comment

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

Reference to sub is already stolen by _PyDict_SetItem_Take2. So you can't pass this down.

PyStackRef_CLOSE(dict_st);
ERROR_IF(err);
if (err) {
ERROR_NO_POP();
Copy link
Member

Choose a reason for hiding this comment

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

We can't do this here. The problem is that _PyDict_SetItem_Take2 has already stolen the references to sub and value. This means when we jump to error, we decref sub and value again, causing a double decref.

The fix might be to do

if (err) {
    PyStackRef_CLOSE(dict_st);
    ERROR_IF(1);
}

@corona10 corona10 changed the title [wip] gh-134584: Eliminate redundant refcounting from _STORE_SUBSCR_DICT gh-134584: Eliminate redundant refcounting from _STORE_SUBSCR_DICT Dec 15, 2025
@corona10 corona10 marked this pull request as ready for review December 15, 2025 05:13
@corona10
Copy link
Member Author

@Fidget-Spinner Done :) Thanks for the guide.

}

op(_STORE_SUBSCR_DICT, (value, dict_st, sub -- st)) {
(void)value;
Copy link
Member

Choose a reason for hiding this comment

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

Can you please add a (void)sub here as well? So that we don't get compiler warnings.

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