gh-105922: Use PyImport_AddModuleRef() function (#105999)

Replace PyImport_AddModuleObject() + Py_XNewRef() with
PyImport_AddModuleRef() to get directly a strong reference.
This commit is contained in:
Victor Stinner 2023-06-23 00:04:39 +02:00 committed by GitHub
parent 403a574b00
commit 193a2b2eaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 3 deletions

View file

@ -1382,8 +1382,7 @@ create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec)
if (_PyUnicode_EqualToASCIIString(name, p->name)) {
if (p->initfunc == NULL) {
/* Cannot re-init internal module ("sys" or "builtins") */
mod = PyImport_AddModuleObject(name);
return Py_XNewRef(mod);
return import_add_module(tstate, name);
}
mod = _PyImport_InitFunc_TrampolineCall(*p->initfunc);
if (mod == NULL) {