diff options
author | Victor Stinner <vstinner@python.org> | 2022-11-10 10:23:36 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 10:23:36 (GMT) |
commit | 231d83b72435d61e929d6d62f2be7305e7b5b62b (patch) | |
tree | 17768fa10f1ade6bae9022d26e1470fd0b931366 /Python/import.c | |
parent | d8f239d86eb70c31aa4c4ac46a1d0a27bdb14b20 (diff) | |
download | cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.zip cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.tar.gz cpython-231d83b72435d61e929d6d62f2be7305e7b5b62b.tar.bz2 |
gh-99300: Use Py_NewRef() in Python/ directory (#99317)
Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and
Py_XNewRef() in C files of the Python/ directory.
Update Parser/asdl_c.py to regenerate Python/Python-ast.c.
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/Python/import.c b/Python/import.c index 9d35d26..2fd2d1b 100644 --- a/Python/import.c +++ b/Python/import.c @@ -810,8 +810,7 @@ update_code_filenames(PyCodeObject *co, PyObject *oldname, PyObject *newname) if (PyUnicode_Compare(co->co_filename, oldname)) return; - Py_INCREF(newname); - Py_XSETREF(co->co_filename, newname); + Py_XSETREF(co->co_filename, Py_NewRef(newname)); constants = co->co_consts; n = PyTuple_GET_SIZE(constants); @@ -905,8 +904,7 @@ get_path_importer(PyThreadState *tstate, PyObject *path_importer_cache, importer = PyDict_GetItemWithError(path_importer_cache, p); if (importer != NULL || _PyErr_Occurred(tstate)) { - Py_XINCREF(importer); - return importer; + return Py_XNewRef(importer); } /* set path_importer_cache[p] to None to avoid recursion */ @@ -1403,8 +1401,7 @@ PyImport_ImportFrozenModuleObject(PyObject *name) } } else { - Py_INCREF(Py_None); - origname = Py_None; + origname = Py_NewRef(Py_None); } err = PyDict_SetItemString(d, "__origname__", origname); Py_DECREF(origname); @@ -1516,8 +1513,7 @@ remove_importlib_frames(PyThreadState *tstate) if (in_importlib && (always_trim || _PyUnicode_EqualToASCIIString(code->co_name, remove_frames))) { - Py_XINCREF(next); - Py_XSETREF(*outer_link, next); + Py_XSETREF(*outer_link, Py_XNewRef(next)); prev_link = outer_link; } else { @@ -1813,8 +1809,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, _PyErr_SetString(tstate, PyExc_ValueError, "Empty module name"); goto error; } - abs_name = name; - Py_INCREF(abs_name); + abs_name = Py_NewRef(name); } mod = import_get_module(tstate, abs_name); @@ -1853,8 +1848,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, if (dot == -1) { /* No dot in module name, simple exit */ - final_mod = mod; - Py_INCREF(mod); + final_mod = Py_NewRef(mod); goto error; } @@ -1889,8 +1883,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, } } else { - final_mod = mod; - Py_INCREF(mod); + final_mod = Py_NewRef(mod); } } else { @@ -1905,8 +1898,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *globals, mod, fromlist, interp->import_func, NULL); } else { - final_mod = mod; - Py_INCREF(mod); + final_mod = Py_NewRef(mod); } } |