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() in _ctypes #111828

Merged

Conversation

serhiy-storchaka
Copy link
Member

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

@vstinner
Copy link
Member

vstinner commented Nov 8, 2023

Ping me when this PR is ready for review. Now it's marked as a draft.

@serhiy-storchaka
Copy link
Member Author

It is ready for review. I marked it as draft because I do not insist that all these changes should be applied.

@serhiy-storchaka serhiy-storchaka marked this pull request as ready for review November 8, 2023 17:47
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.

LGTM

}
*presult = NULL;
return 0;
int rc = PyDict_GetItemRef(dict, key, presult);
Copy link
Member

Choose a reason for hiding this comment

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

_PyDict_GetItemProxy() now returns 1 if PyDict_GetItemRef() returns 1 and PyWeakref_CheckProxy() is false. It's only called once with if (_PyDict_GetItemProxy(cache, key, &result) != 0) {. So it's ok.

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, it has the same semantic as PyDict_GetItemRef().

1 -- found, returns a strong reference
0 -- not found (or was destroyed)
-1 -- error

}
*presult = NULL;
return 0;
int rc = PyDict_GetItemRef(dict, key, presult);
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, it has the same semantic as PyDict_GetItemRef().

1 -- found, returns a strong reference
0 -- not found (or was destroyed)
-1 -- error

@serhiy-storchaka serhiy-storchaka merged commit c98600b into python:main Nov 14, 2023
@serhiy-storchaka serhiy-storchaka deleted the use-dict_getitemref-in-ctypes branch November 14, 2023 09:28
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
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