Issue 30081: Inconsistent handling of failure of PyModule_AddObject - Python tracker

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Change weird behavior of PyModule_AddObject()
View: 26871
Assigned To: Nosy List: serhiy.storchaka, xiang.zhang
Priority: normal Keywords:

Created on 2017-04-16 16:22 by xiang.zhang, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg291750 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-04-16 16:22
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
msg291751 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-04-16 16:33
This is a duplicate of issue26868 and issue26871. There is also a thread on Python-Dev.
msg291753 - (view) Author: Xiang Zhang (xiang.zhang) * (Python committer) Date: 2017-04-16 16:44
Ohh, I am not alone. :-)