[Python-Dev] Inconsistency of PyModule_AddObject() (original) (raw)

Serhiy Storchaka storchaka at gmail.com
Wed Apr 27 14:06:25 EDT 2016


On 27.04.16 16:08, Nick Coghlan wrote:

On 27 April 2016 at 17:14, Serhiy Storchaka <storchaka at gmail.com> wrote:

I think that we can resolve this issue by following steps:

1. Add a new function PyModuleAddObject2(), that steals a reference even on failure. I'd suggest a variant on this that more closely matches the PyListSetItem and PyTupleSetItem cases: PyModuleSetAttrString The first two match the signature of PySequenceSetItem, but steal the reference instead of making a new one, and the same relationship would exist between PyObjectSetAttrString and the new PyModuleSetAttrString.

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 user code that mostly use PyModule_AddObject() incorrectly (not blaming authors).



More information about the Python-Dev mailing list