gh-86493: Use PyModule_Add() instead of PyModule_AddObjectRef() by serhiy-storchaka · Pull Request #106860 · python/cpython
Conversation
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.
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) { |
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()?
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters