[issue42327] Add PyModule_Add()

2021-10-05 Thread Łukasz Langa
Change by Łukasz Langa : -- nosy: +lukasz.langa nosy_count: 3.0 -> 4.0 pull_requests: +27089 pull_request: https://github.com/python/cpython/pull/28741 ___ Python tracker ___ __

[issue42327] Add PyModule_Add()

2021-01-11 Thread STINNER Victor
STINNER Victor added the comment: Note for myself: I added PyModule_AddObjectRef() to https://github.com/pythoncapi/pythoncapi_compat If it's renamed, pythoncapi_compat must also be updated. -- ___ Python tracker

[issue42327] Add PyModule_Add()

2020-11-21 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- pull_requests: +22335 pull_request: https://github.com/python/cpython/pull/23443 ___ Python tracker ___

[issue42327] Add PyModule_Add()

2020-11-12 Thread STINNER Victor
STINNER Victor added the comment: > PyModule_AddObjectRef() is just Py_XINCREF() followed by PyModule_Add(). But > since most values added to the module are new references, Py_XINCREF() is > usually not needed. There is no general rule. I saw two main cases. (A) Create an object only to ad

[issue42327] Add PyModule_Add()

2020-11-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: PyModule_Add() allows to make such macro much simpler: #define MOD_ADD(name, expr) \ do { \ if (PyModule_Add(mod, name, expr) < 0) { \ return -1; \ } \ } while (0) PyModule_AddObjectRef() is just Py_XINCREF() followed by

[issue42327] Add PyModule_Add()

2020-11-12 Thread STINNER Victor
STINNER Victor added the comment: In practice, PyModule_AddRef(mod, obj) behaves as PyModule_Add(mod, Py_NewRef(obj)) if I understood correctly. -- ___ Python tracker ___ ___

[issue42327] Add PyModule_Add()

2020-11-12 Thread STINNER Victor
STINNER Victor added the comment: If PyModule_Add() is added, I would suggest to rename PyModule_AddObjectRef() to PyModule_AddRef() for consistency. IMHO PyModule_AddObjectRef() remains useful even if PyModule_Add() is added. -- ___ Python tracke

[issue42327] Add PyModule_Add()

2020-11-12 Thread STINNER Victor
STINNER Victor added the comment: I'm using more and more often such macro: #define MOD_ADD(name, expr) \ do { \ PyObject *obj = (expr); \ if (obj == NULL) { \ return -1; \ } \ if (PyModule_AddObjectRef(mod, name, obj) < 0) { \ Py_DEC

[issue42327] Add PyModule_Add()

2020-11-12 Thread STINNER Victor
STINNER Victor added the comment: Oh, I just rejected PR 17298. Copy of my message: --- I added PyModule_AddObjectRef() which uses strong references, rather than only stealing a reference on success. I also enhanced the documentation to show concrete examples: https://docs.python.org/dev/c-ap

[issue42327] Add PyModule_Add()

2020-11-11 Thread Brandt Bucher
Brandt Bucher added the comment: See also: https://bugs.python.org/issue38823 https://github.com/python/cpython/pull/17298 -- nosy: +brandtbucher ___ Python tracker ___

[issue42327] Add PyModule_Add()

2020-11-11 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- keywords: +patch pull_requests: +22137 stage: -> patch review pull_request: https://github.com/python/cpython/pull/23240 ___ Python tracker ___

[issue42327] Add PyModule_Add()

2020-11-11 Thread Serhiy Storchaka
New submission from Serhiy Storchaka : There is a design flaw in PyModule_AddObject(). It steals reference of its value only if the result is success. To avoid leaks it should be used in the following form: PyObject *tmp = ; if (PyModule_AddObject(name, name, tmp) < 0) { Py_XD