This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients brandtbucher, serhiy.storchaka, vstinner
Date 2020-11-12.15:26:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
PyModule_Add() allows to make such macro much simpler:

#define MOD_ADD(name, expr) \
    do { \
        if (PyModule_Add(mod, name, expr) < 0) { \
            return -1; \
        } \
    } while (0)

PyModule_AddObjectRef() is just Py_XINCREF() followed by PyModule_Add(). But since most values added to the module are new references, Py_XINCREF() is usually not needed. The PyModule_Add* API is a convenient API. It is not necessary, you can use PyModule_GetDict() + PyDict_SetItemString(), but with this API it is easier. And PyModule_Add() is a correct PyModule_AddObject() (which was broken a long time ago and cannot be fixed now) and is more convenient than PyModule_AddObjectRef().

PyModule_AddIntConstant() and PyModule_AddStringConstant() can be easily expressed in terms of PyModule_Add():

    PyModule_Add(m, name, PyLong_FromLong(value))
    PyModule_Add(m, name, PyUnicode_FromString(value))

And it is easy to combine it with other functions: PyLong_FromLongLong(), PyLong_FromUnsignedLong(), PyLong_FromVoidPtr(), PyFloat_FromDouble(), PyCapsule_New(), PyType_FromSpec(), etc.
Date User Action Args
2020-11-12 15:26:20serhiy.storchakasetrecipients: + serhiy.storchaka, vstinner, brandtbucher
2020-11-12 15:26:20serhiy.storchakasetmessageid: <>
2020-11-12 15:26:20serhiy.storchakalinkissue42327 messages
2020-11-12 15:26:20serhiy.storchakacreate