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>
This commit is contained in:
Victor Stinner 2023-08-23 22:59:00 +02:00 committed by GitHub
parent 1700d34d31
commit 4dc9f48930
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 39 deletions

View file

@ -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;
}