gh-108308: Replace _PyDict_GetItemStringWithError() by vstinner · Pull Request #108372 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions Objects/structseq.c
12 changes: 5 additions & 7 deletions Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Copyright (c) Corporation for National Research Initiatives.

#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_dict.h" // _PyDict_GetItemStringWithError()
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
#include "pycore_pyerrors.h" // _PyErr_FormatNote()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
Expand Down Expand Up @@ -618,20 +617,19 @@ int PyCodec_RegisterError(const char *name, PyObject *error)
the error handling callback for strict encoding will be returned. */
PyObject *PyCodec_LookupError(const char *name)
{
PyObject *handler = NULL;

PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
return NULL;

if (name==NULL)
name = "strict";
handler = _PyDict_GetItemStringWithError(interp->codec_error_registry, name);
if (handler) {
Py_INCREF(handler);
PyObject *handler;
if (PyDict_GetItemStringRef(interp->codec_error_registry, name, &handler) < 0) {
return NULL;
}
else if (!PyErr_Occurred()) {
if (handler == NULL) {
PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name);
return NULL;
}
return handler;
}
Expand Down
8 changes: 3 additions & 5 deletions Python/import.c
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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;
}

Expand Down
26 changes: 14 additions & 12 deletions Python/pylifecycle.c