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-112066: Use PyDict_SetDefaultRef in place of PyDict_SetDefault. #112211

Merged
merged 3 commits into from Feb 7, 2024

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Nov 17, 2023

This changes a number of internal usages of PyDict_SetDefault to use PyDict_SetDefaultRef.

Copy link
Member

@encukou encukou left a comment

Choose a reason for hiding this comment

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

+1 from me; IMO the chance of C-API WG having objections is low enough, let's be optimistic and merge this.

Python/compile.c Outdated
Comment on lines 986 to 990
if (res < 0) {
Py_DECREF(key);
return NULL;
}
if (res == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe merge them in single test != 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks - I combined the cases.

…fault`.

This changes a number of internal usages of `PyDict_SetDefault` to
use `PyDict_SetDefaultRef`.
@colesbury
Copy link
Contributor Author

I've rebased this PR now that #112123 is merged. @serhiy-storchaka, would you please look over this?

Python/compile.c Outdated Show resolved Hide resolved
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@colesbury colesbury merged commit ef3ceab into python:main Feb 7, 2024
33 checks passed
@colesbury colesbury deleted the PyDict_SetDefaultRef-usage branch February 7, 2024 18:43
@vstinner
Copy link
Member

vstinner commented Feb 8, 2024

Nice change, it makes the code more readable.

fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
…fault`. (python#112211)

This changes a number of internal usages of `PyDict_SetDefault` to use `PyDict_SetDefaultRef`.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
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.

None yet

5 participants