mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
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:
parent
1700d34d31
commit
4dc9f48930
4 changed files with 32 additions and 39 deletions
|
@ -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()
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue