Skip to content

Conversation

serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 18, 2023

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.

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

int rc = PyModule_AddObjectRef(mod, "WITH_PYMALLOC", v);
Py_DECREF(v);
if (rc < 0) {
if (PyModule_AddObjectRef(mod, "WITH_PYMALLOC", v) < 0) {
Copy link
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
Member Author

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:main Jul 18, 2023
@serhiy-storchaka serhiy-storchaka deleted the use-PyModule_Add2 branch July 18, 2023 20:59
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.

4 participants