summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-06-22 22:04:39 (GMT)
committerGitHub <noreply@github.com>2023-06-22 22:04:39 (GMT)
commit193a2b2eaab9890f2cb16128c95bb63cb49307f1 (patch)
tree5adc9c1888c7338746c57c7b9ab329e8cf269795 /Python
parent403a574b000569ea2c91f5325e6a8061a29e64bf (diff)
downloadcpython-193a2b2eaab9890f2cb16128c95bb63cb49307f1.zip
cpython-193a2b2eaab9890f2cb16128c95bb63cb49307f1.tar.gz
cpython-193a2b2eaab9890f2cb16128c95bb63cb49307f1.tar.bz2
gh-105922: Use PyImport_AddModuleRef() function (#105999)
Replace PyImport_AddModuleObject() + Py_XNewRef() with PyImport_AddModuleRef() to get directly a strong reference.
Diffstat (limited to 'Python')
-rw-r--r--Python/import.c3
-rw-r--r--Python/pythonrun.c2
2 files changed, 2 insertions, 3 deletions
diff --git a/Python/import.c b/Python/import.c
index 9b1ad87..05da950 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 af82fa4..2986622 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;