From: Victor Stinner Date: Thu, 22 Jun 2023 22:04:39 +0000 (+0200) Subject: gh-105922: Use PyImport_AddModuleRef() function (#105999) X-Git-Tag: v3.13.0a1~1669 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=193a2b2eaab9890f2cb16128c95bb63cb49307f1;p=thirdparty%2FPython%2Fcpython.git gh-105922: Use PyImport_AddModuleRef() function (#105999) Replace PyImport_AddModuleObject() + Py_XNewRef() with PyImport_AddModuleRef() to get directly a strong reference. --- diff --git a/Python/import.c b/Python/import.c index 9b1ad87b84f6..05da9506cc0b 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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) { diff --git a/Python/pythonrun.c b/Python/pythonrun.c index af82fa491511..2986622a8b0d 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -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;