Skip to content

Commit 193a2b2

Browse files
authored
gh-105922: Use PyImport_AddModuleRef() function (#105999)
Replace PyImport_AddModuleObject() + Py_XNewRef() with PyImport_AddModuleRef() to get directly a strong reference.
1 parent 403a574 commit 193a2b2

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Python/import.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,7 @@ create_builtin(PyThreadState *tstate, PyObject *name, PyObject *spec)
13821382
if (_PyUnicode_EqualToASCIIString(name, p->name)) {
13831383
if (p->initfunc == NULL) {
13841384
/* Cannot re-init internal module ("sys" or "builtins") */
1385-
mod = PyImport_AddModuleObject(name);
1386-
return Py_XNewRef(mod);
1385+
return import_add_module(tstate, name);
13871386
}
13881387
mod = _PyImport_InitFunc_TrampolineCall(*p->initfunc);
13891388
if (mod == NULL) {

Python/pythonrun.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ PyRun_InteractiveOneObjectEx(FILE *fp, PyObject *filename,
276276
return parse_res;
277277
}
278278

279-
PyObject *main_module = Py_XNewRef(PyImport_AddModuleObject(&_Py_ID(__main__)));
279+
PyObject *main_module = PyImport_AddModuleRef("__main__");
280280
if (main_module == NULL) {
281281
_PyArena_Free(arena);
282282
return -1;

0 commit comments

Comments
 (0)