On 27.04.16 15:31, Hrvoje Niksic wrote:
On 04/27/2016 09:14 AM, Serhiy Storchaka wrote:
There are three functions (or at least three documented functions) in C
API that "steals" references: PyList_SetItem(), PyTuple_SetItem() and
PyModule_AddObject(). The first two "steals" references even on failure,
and this is well known behaviour. But PyModule_AddObject() "steals" a
reference only on success. There is nothing in the documentation that
points on this.

This inconsistency has caused bugs (or, more fairly, potential leaks)
before, see http://bugs.python.org/issue1782

Glad to hear I'm not the first faced with this problem.

Unfortunately, the suggested Python 3 change to PyModule_AddObject was
not accepted.

Bad. May be it happened because of the risk to break third-party working code.

I propose a gradual path to change PyModule_AddObject.

1. Add a new function PyModule_AddObject2(), that steals a reference
even on failure.

This sounds like a good idea, except the name could be prettier :), e.g.
PyModule_InsertObject. PyModule_AddObject could be deprecated.

I have decided to not introduce new public function. But just control the behavior of old function with the macro. This needs minimal changes to user code.


_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to