-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-111789: Use PyDict_GetItemRef() #111790
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
Conversation
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.
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.
Modules/_ctypes/_ctypes.c
Outdated
return -1; | ||
} | ||
int rc = PyDict_GetItemRef(dict, key, presult); | ||
if (rc <= 0) { // error or not found | ||
*presult = NULL; |
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.
Is it now redundant?
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.
Yes, redundant. And the code here can be simplified even more.
Modules/_ctypes/_ctypes.c
Outdated
} | ||
if (result) { | ||
if (_PyDict_GetItemProxy(cache, key, &result) != 0) { | ||
// error or found | ||
Py_DECREF(key); | ||
return result; | ||
} |
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.
Please add // not found
after to be extra explicit, since this code pattern is not common.
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.
Added here and in other places.
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. |
It was merged with The remaining is relatively small and simple. |
Split on more PRs. |
Is this PR ready for a review? It's marked as a draft and now has a conflict. |
I left the combined PR to see the general image, but most of changes were already merged in other PRs. |
It is a sample. We perhaps will only merge a part of these changes.