Skip to content
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

gh-111789: Use PyDict_GetItemRef() #111790

Closed

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Nov 6, 2023

It is a sample. We perhaps will only merge a part of these changes.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Reviewing code with 3 cases (error, not found, found) is really hard to me, especially since you also change ownership and reference counting in the same PR. I cannot review such giant single PR. If you want me to review it, please create smaller PRs. For example, only change around 10 PyDict_Get call per PR. Just Modules/_ctypes/_ctypes.c alone is already a big piece.

return -1;
}
int rc = PyDict_GetItemRef(dict, key, presult);
if (rc <= 0) { // error or not found
*presult = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

Is it now redundant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, redundant. And the code here can be simplified even more.

}
if (result) {
if (_PyDict_GetItemProxy(cache, key, &result) != 0) {
// error or found
Py_DECREF(key);
return result;
}
Copy link
Member

Choose a reason for hiding this comment

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

Please add // not found after to be extra explicit, since this code pattern is not common.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added here and in other places.

@vstinner
Copy link
Member

What's the status of that PR? Was it rebased on the main branch to retrieve other already merged changes? It's marked as a draft. I prefer to wait until it's not a draft to review it.

@serhiy-storchaka
Copy link
Member Author

It was merged with main to include already merged changes. I extracted also Python/bytecodes.c in a separate PR #111978.

The remaining is relatively small and simple.

@serhiy-storchaka
Copy link
Member Author

Split on more PRs.

@serhiy-storchaka serhiy-storchaka marked this pull request as draft November 14, 2023 19:22
@vstinner
Copy link
Member

Split on more PRs.

Is this PR ready for a review? It's marked as a draft and now has a conflict.

@serhiy-storchaka
Copy link
Member Author

I left the combined PR to see the general image, but most of changes were already merged in other PRs.

@serhiy-storchaka serhiy-storchaka deleted the use-dict_getitemref branch January 11, 2024 09:30
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