Skip to content

Commit

Permalink
pythongh-105922: Use PyImport_AddModuleRef() function
Browse files Browse the repository at this point in the history
Replace PyImport_AddModuleObject() + Py_XNewRef() with
PyImport_AddModuleRef() to get directly a strong reference.
  • Loading branch information
vstinner committed Jun 22, 2023
1 parent c38da1e commit 57b2b7b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions Python/import.c
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Python/pythonrun.c
Expand Up @@ -276,7 +276,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
return parse_res;
}

PyObject *main_module = Py_XNewRef(PyImport_AddModuleObject(&_Py_ID(__main__)));
PyObject *main_module = PyImport_AddModuleRef("__main__");
if (main_module == NULL) {
_PyArena_Free(arena);
return -1;
Expand Down

0 comments on commit 57b2b7b

Please sign in to comment.