Message380829
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:20 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, vstinner, brandtbucher |
2020-11-12 15:26:20 | serhiy.storchaka | set | messageid: <1605194780.92.0.106870522482.issue42327@roundup.psfhosted.org> |
2020-11-12 15:26:20 | serhiy.storchaka | link | issue42327 messages |
2020-11-12 15:26:20 | serhiy.storchaka | create | |
|