[3.11] Fix error handling in _PySys_UpdateConfig() (GH-109524) (GH-109551)

(cherry picked from commit c829975428)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-09-18 11:24:41 -07:00 committed by GitHub
parent 2184b76496
commit 17a335dd02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3113,7 +3113,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
if (config->pycache_prefix != NULL) { if (config->pycache_prefix != NULL) {
SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix); SET_SYS_FROM_WSTR("pycache_prefix", config->pycache_prefix);
} else { } else {
PyDict_SetItemString(sysdict, "pycache_prefix", Py_None); if (PyDict_SetItemString(sysdict, "pycache_prefix", Py_None) < 0) {
return -1;
}
} }
COPY_LIST("argv", config->argv); COPY_LIST("argv", config->argv);
@ -3127,7 +3129,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
SET_SYS_FROM_WSTR("_stdlib_dir", stdlibdir); SET_SYS_FROM_WSTR("_stdlib_dir", stdlibdir);
} }
else { else {
PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None); if (PyDict_SetItemString(sysdict, "_stdlib_dir", Py_None) < 0) {
return -1;
}
} }
#undef SET_SYS_FROM_WSTR #undef SET_SYS_FROM_WSTR
@ -3137,6 +3141,9 @@ _PySys_UpdateConfig(PyThreadState *tstate)
// sys.flags // sys.flags
PyObject *flags = _PySys_GetObject(interp, "flags"); // borrowed ref PyObject *flags = _PySys_GetObject(interp, "flags"); // borrowed ref
if (flags == NULL) { if (flags == NULL) {
if (!_PyErr_Occurred(tstate)) {
_PyErr_SetString(tstate, PyExc_RuntimeError, "lost sys.flags");
}
return -1; return -1;
} }
if (set_flags_from_config(interp, flags) < 0) { if (set_flags_from_config(interp, flags) < 0) {