[Python-Dev] Inconsistency of PyModule_AddObject()

Stefan Krah stefan at bytereef.org
Thu Apr 28 05:05:13 EDT 2016

Serhiy Storchaka <storchaka <at> gmail.com> writes:
> But are you sure, that your code uses PyModule_AddObject() correctly? 
> Only two modules in the stdlib (_json and _tkinter) used it correctly. 
> Other modules have bugs even in tries to use PyModule_AddObject() 
> correctly for some operations.

For the list, this is the extent of this horrible "bug":

diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -5804,8 +5804,7 @@
                PyObject_CallObject((PyObject *)&PyDecContext_Type, NULL));
-    CHECK_INT(PyModule_AddObject(m, "BasicContext",
-                                 basic_context_template));
+    CHECK_INT(-1);

$ valgrind --suppressions=Misc/valgrind-python.supp ./python -c "import decimal"

==16945== LEAK SUMMARY:
==16945==    definitely lost: 0 bytes in 0 blocks

Stefan Krah

More information about the Python-Dev mailing list