From 4dc9f4893084f7c3acf78a0384620cd44f604a0d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 23 Aug 2023 22:59:00 +0200 Subject: 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 --- Python/import.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'Python/import.c') diff --git a/Python/import.c b/Python/import.c index 4abb2f6a06b..5681deb3c4f 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; } -- cgit v1.2.3