Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.4k
Closed
Description
The C APIPyImport_AddModule() returns a borrowed reference using a special dance added by commit4db8988 of issue#86160:
PyObject*ref=PyWeakref_NewRef(mod,NULL);Py_DECREF(mod);if (ref==NULL) {returnNULL; }mod=PyWeakref_GetObject(ref);Py_DECREF(ref);
Borrowed references are bad:
- "Functions must not return borrowed references" sayshttps://devguide.python.org/developer-workflow/c-api/index.html
- Unclear lifetimes of borrowed references capi-workgroup/problems#5
I proposed to:
- Add a new
PyImport_AddModuleRef(const char *name)
function, similar toPyImport_AddModule()
but return astrong reference - Deprecate
PyImport_AddModule()
andPyImport_AddModuleObject()