gh-86493: Use PyModule_Add() instead of PyModule_AddObjectRef() by serhiy-storchaka · Pull Request #106860 · python/cpython

Conversation

@serhiy-storchaka

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.

vstinner

Choose a reason for hiding this comment

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

LGTM

brettcannon

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.

Labels