[Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Serhiy Storchaka
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

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Berker Peksağ
On Wed, Apr 27, 2016 at 10:14 AM, Serhiy Storchaka wrote: > I think that we can resolve this issue by following steps: > > 1. Add a new function PyModule_AddObject2(), that steals a reference even on > failure. +1 It would be good to document PyModule_AddObject's current behavior in 3.5+ (alread

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Hrvoje Niksic
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.

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Nick Coghlan
On 27 April 2016 at 17:14, Serhiy Storchaka wrote: > I think that we can resolve this issue by following steps: > > 1. Add a new function PyModule_AddObject2(), that steals a reference even on > failure. I'd suggest a variant on this that more closely matches the PyList_SetItem and PyTuple_SetIte

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Nick Coghlan
On 27 April 2016 at 23:08, Nick Coghlan wrote: > On 27 April 2016 at 17:14, Serhiy Storchaka wrote: >> I think that we can resolve this issue by following steps: >> >> 1. Add a new function PyModule_AddObject2(), that steals a reference even on >> failure. > > I'd suggest a variant on this that m

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Serhiy Storchaka
On 27.04.16 10:14, 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 P

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Serhiy Storchaka
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 fa

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Serhiy Storchaka
On 27.04.16 16:08, Nick Coghlan wrote: On 27 April 2016 at 17:14, Serhiy Storchaka wrote: I think that we can resolve this issue by following steps: 1. Add a new function PyModule_AddObject2(), that steals a reference even on failure. I'd suggest a variant on this that more closely matches t

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Stefan Krah
Hrvoje Niksic avl.com> writes: > This inconsistency has caused bugs (or, more fairly, potential leaks) > before, see http://bugs.python.org/issue1782 > > Unfortunately, the suggested Python 3 change to PyModule_AddObject was > not accepted. First, these "leaks" only potentially show up when yo

Re: [Python-Dev] Inconsistency of PyModule_AddObject()

2016-04-27 Thread Case Van Horsen
On Wed, Apr 27, 2016 at 11:06 AM, Serhiy Storchaka wrote: > I think it is better to have relation with PyModule_AddIntConstant() etc > than with PyObject_SetAttrString. > > My patch doesn't introduce new public function, but changes the behavior of > the old function. This needs minimal changes to