bpo-42260: Improve error handling in _PyConfig_FromDict (GH-23488)
This commit is contained in:
parent
c0c23ea72b
commit
14d81dcaf8
|
@ -1050,8 +1050,8 @@ fail:
|
|||
static PyObject*
|
||||
config_dict_get(PyObject *dict, const char *name)
|
||||
{
|
||||
PyObject *item = PyDict_GetItemString(dict, name);
|
||||
if (item == NULL) {
|
||||
PyObject *item = _PyDict_GetItemStringWithError(dict, name);
|
||||
if (item == NULL && !PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_ValueError, "missing config key: %s", name);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1085,7 +1085,7 @@ config_dict_get_int(PyObject *dict, const char *name, int *result)
|
|||
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||
config_dict_invalid_type(name);
|
||||
}
|
||||
else {
|
||||
else if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
|
||||
config_dict_invalid_value(name);
|
||||
}
|
||||
return -1;
|
||||
|
@ -1104,7 +1104,12 @@ config_dict_get_ulong(PyObject *dict, const char *name, unsigned long *result)
|
|||
}
|
||||
unsigned long value = PyLong_AsUnsignedLong(item);
|
||||
if (value == (unsigned long)-1 && PyErr_Occurred()) {
|
||||
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||
config_dict_invalid_type(name);
|
||||
}
|
||||
else if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
|
||||
config_dict_invalid_value(name);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
*result = value;
|
||||
|
|
Loading…
Reference in New Issue