bpo-26868: Fix example usage of PyModule_AddObject. (#15725)
* Add a note to the PyModule_AddObject docs.
* Correct example usages of PyModule_AddObject.
* Whitespace.
* Clean up wording.
* 📜🤖 Added by blurb_it.
* First code review.
* Add < 0 in the tests with PyModule_AddObject
diff --git a/Doc/includes/custom.c b/Doc/includes/custom.c
index 13d16f5..bda32e2 100644
--- a/Doc/includes/custom.c
+++ b/Doc/includes/custom.c
@@ -35,6 +35,11 @@
return NULL;
Py_INCREF(&CustomType);
- PyModule_AddObject(m, "Custom", (PyObject *) &CustomType);
+ if (PyModule_AddObject(m, "Custom", (PyObject *) &CustomType) < 0) {
+ Py_DECREF(&CustomType);
+ PY_DECREF(m);
+ return NULL;
+ }
+
return m;
}