New submission from Xiang Zhang: The doc of PyModule_AddObject()[1] states it steals a reference to *value*. But this is only the case when it succeed. On failure the reference is not stolen.
The usages of it across the code base are inconsistent. Some realizes this situation and depends on it: [2]. Some doesn't realize: [3]. Most just assume it always succeeds: [4]. BTW, it seems many modules doesn't release memories well in failure situations in their PyMOD_INIT. Maybe I miss some post-handling procedures? [1] https://docs.python.org/3/c-api/module.html#c.PyModule_AddObject [2] https://github.com/python/cpython/blob/master/Python/modsupport.c#L644 [3] https://github.com/python/cpython/blob/master/Modules/gcmodule.c#L1590 [4] https://github.com/python/cpython/blob/master/Modules/_datetimemodule.c#L5799 ---------- messages: 291750 nosy: xiang.zhang priority: normal severity: normal status: open title: Inconsistent handling of failure of PyModule_AddObject type: behavior _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue30081> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com