(original) (raw)
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst --- a/Doc/c-api/module.rst +++ b/Doc/c-api/module.rst @@ -403,17 +403,26 @@ The module initialization function (if u a function called from a module execution slot (if using multi-phase initialization), can use the following functions to help initialize the module state: .. c:function:: int PyModule_AddObject(PyObject *module, const char *name, PyObject *value) Add an object to *module* as *name*. This is a convenience function which can be used from the module's initialization function. This steals a reference to - *value*. Return ``-1`` on error, ``0`` on success. + *value*. Return ``-1`` on error, ``0`` on success. On error, you need to + :c:func:`Py_DECREF` *value* manually. + + Example:: + + Py_INCREF(spam); + if (PyModule_AddObject(module, "spam", spam) == -1) { + Py_DECREF(spam); + return NULL; + } .. c:function:: int PyModule_AddIntConstant(PyObject *module, const char *name, long value) Add an integer constant to *module* as *name*. This convenience function can be used from the module's initialization function. Return ``-1`` on error, ``0`` on success.