diff options
author | Victor Stinner <vstinner@python.org> | 2023-08-23 20:59:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-23 20:59:00 (GMT) |
commit | 4dc9f4893084f7c3acf78a0384620cd44f604a0d (patch) | |
tree | e68ff4cc214daa87aedf3f508ad07c3f0d61ff66 /Python/import.c | |
parent | 1700d34d314f5304a7a75363bda295a8c15c371f (diff) | |
download | cpython-4dc9f4893084f7c3acf78a0384620cd44f604a0d.zip cpython-4dc9f4893084f7c3acf78a0384620cd44f604a0d.tar.gz cpython-4dc9f4893084f7c3acf78a0384620cd44f604a0d.tar.bz2 |
gh-108308: Replace _PyDict_GetItemStringWithError() (#108372)
Replace _PyDict_GetItemStringWithError() calls with
PyDict_GetItemStringRef() which returns a strong reference to the
item.
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Python/import.c')
-rw-r--r-- | Python/import.c | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/Python/import.c b/Python/import.c index 4abb2f6..5681deb 100644 --- a/Python/import.c +++ b/Python/import.c @@ -1,7 +1,6 @@ /* Module definition and import implementation */ #include "Python.h" -#include "pycore_dict.h" // _PyDict_GetItemStringWithError() #include "pycore_hashtable.h" // _Py_hashtable_new_full() #include "pycore_import.h" // _PyImport_BootstrapImp() #include "pycore_initconfig.h" // _PyStatus_OK() @@ -2435,12 +2434,11 @@ int _PyImport_InitDefaultImportFunc(PyInterpreterState *interp) { // Get the __import__ function - PyObject *import_func = _PyDict_GetItemStringWithError(interp->builtins, - "__import__"); - if (import_func == NULL) { + PyObject *import_func; + if (PyDict_GetItemStringRef(interp->builtins, "__import__", &import_func) <= 0) { return -1; } - IMPORT_FUNC(interp) = Py_NewRef(import_func); + IMPORT_FUNC(interp) = import_func; return 0; } |