Skip to content

gh-86493: Use PyModule_Add() instead of PyModule_AddObjectRef() - #106860

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:use-PyModule_Add2
Jul 18, 2023
Merged

gh-86493: Use PyModule_Add() instead of PyModule_AddObjectRef()#106860
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:use-PyModule_Add2

Conversation

@serhiy-storchaka

@serhiy-storchakaserhiy-storchaka commented Jul 18, 2023

Copy link
Copy Markdown
Member

If PyModule_AddObjectRef() followed by Py_DECREF() of the added value, the code can be simplified by using PyModule_Add() which was designed specially for such cases.

@vstinnervstinner 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.

LGTM

int rc = PyModule_AddObjectRef(mod, "WITH_PYMALLOC", v);
Py_DECREF(v);
if (rc < 0) {
if (PyModule_AddObjectRef(mod, "WITH_PYMALLOC", v) < 0) {

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.

Was this purposefully not converted to PyModule_Add()?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Yes, PyModule_AddObjectRef() is more fitting here. But the old code was complicated without need.

@serhiy-storchaka
serhiy-storchaka merged commit a293fa5 into python:mainJul 18, 2023
@serhiy-storchaka
serhiy-storchaka deleted the use-PyModule_Add2 branch July 18, 2023 20:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@serhiy-storchaka@brettcannon@vstinner@bedevere-bot