mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
bpo-38631: Avoid Py_FatalError() in _PyCodecRegistry_Init() (GH-18217)
_PyCodecRegistry_Init() now reports exceptions to the caller, rather than calling Py_FatalError().
This commit is contained in:
parent
dd023ad161
commit
d3a1de2270
1 changed files with 24 additions and 19 deletions
|
@ -1494,32 +1494,37 @@ static int _PyCodecRegistry_Init(void)
|
||||||
|
|
||||||
PyInterpreterState *interp = _PyInterpreterState_Get();
|
PyInterpreterState *interp = _PyInterpreterState_Get();
|
||||||
PyObject *mod;
|
PyObject *mod;
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
if (interp->codec_search_path != NULL)
|
if (interp->codec_search_path != NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
interp->codec_search_path = PyList_New(0);
|
interp->codec_search_path = PyList_New(0);
|
||||||
interp->codec_search_cache = PyDict_New();
|
if (interp->codec_search_path == NULL) {
|
||||||
interp->codec_error_registry = PyDict_New();
|
return -1;
|
||||||
|
|
||||||
if (interp->codec_error_registry) {
|
|
||||||
for (i = 0; i < Py_ARRAY_LENGTH(methods); ++i) {
|
|
||||||
PyObject *func = PyCFunction_NewEx(&methods[i].def, NULL, NULL);
|
|
||||||
int res;
|
|
||||||
if (!func)
|
|
||||||
Py_FatalError("can't initialize codec error registry");
|
|
||||||
res = PyCodec_RegisterError(methods[i].name, func);
|
|
||||||
Py_DECREF(func);
|
|
||||||
if (res)
|
|
||||||
Py_FatalError("can't initialize codec error registry");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (interp->codec_search_path == NULL ||
|
interp->codec_search_cache = PyDict_New();
|
||||||
interp->codec_search_cache == NULL ||
|
if (interp->codec_search_cache == NULL) {
|
||||||
interp->codec_error_registry == NULL)
|
return -1;
|
||||||
Py_FatalError("can't initialize codec registry");
|
}
|
||||||
|
|
||||||
|
interp->codec_error_registry = PyDict_New();
|
||||||
|
if (interp->codec_error_registry == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < Py_ARRAY_LENGTH(methods); ++i) {
|
||||||
|
PyObject *func = PyCFunction_NewEx(&methods[i].def, NULL, NULL);
|
||||||
|
if (!func) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = PyCodec_RegisterError(methods[i].name, func);
|
||||||
|
Py_DECREF(func);
|
||||||
|
if (res) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
mod = PyImport_ImportModuleNoBlock("encodings");
|
mod = PyImport_ImportModuleNoBlock("encodings");
|
||||||
if (mod == NULL) {
|
if (mod == NULL) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue