Skip to content

gh-112066: Use PyDict_SetDefaultRef in place of PyDict_SetDefault. - #112211

Merged
colesbury merged 3 commits into
python:mainfrom
colesbury:PyDict_SetDefaultRef-usage
Feb 7, 2024
Merged

gh-112066: Use PyDict_SetDefaultRef in place of PyDict_SetDefault.#112211
colesbury merged 3 commits into
python:mainfrom
colesbury:PyDict_SetDefaultRef-usage

Conversation

@colesbury

@colesburycolesbury commented Nov 17, 2023

Copy link
Copy Markdown
Contributor

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

@encukouencukou left a comment

Copy link
Copy Markdown
Member

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.

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

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
colesburyforce-pushed the PyDict_SetDefaultRef-usage branch from 3899746 to 14a00f4CompareFebruary 6, 2024 16:38
@colesbury
colesbury marked this pull request as ready for review February 6, 2024 16:39
@colesbury

Copy link
Copy Markdown
ContributorAuthor

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

Comment threadPython/compile.c Outdated
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@colesbury
colesbury merged commit ef3ceab into python:mainFeb 7, 2024
@colesbury
colesbury deleted the PyDict_SetDefaultRef-usage branch February 7, 2024 18:43
@vstinner

Copy link
Copy Markdown
Member

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 freeto 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.

5 participants

@colesbury@vstinner@encukou@serhiy-storchaka@erlend-aasland