mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
(cherry picked from commit 41cddc2e93
)
In _PySys_AddXOptionWithError() and sys_add_xoption(),
bail on first error to prevent exceptions from possibly being
overwritten.
This commit is contained in:
parent
a03449374e
commit
f98d475ee3
2 changed files with 20 additions and 6 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
Fix bugs in :mod:`sys` where exceptions could end up being overwritten
|
||||||
|
because of deferred error handling.
|
|
@ -2360,15 +2360,21 @@ _PySys_AddXOptionWithError(const wchar_t *s)
|
||||||
const wchar_t *name_end = wcschr(s, L'=');
|
const wchar_t *name_end = wcschr(s, L'=');
|
||||||
if (!name_end) {
|
if (!name_end) {
|
||||||
name = PyUnicode_FromWideChar(s, -1);
|
name = PyUnicode_FromWideChar(s, -1);
|
||||||
|
if (name == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
value = Py_True;
|
value = Py_True;
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
name = PyUnicode_FromWideChar(s, name_end - s);
|
name = PyUnicode_FromWideChar(s, name_end - s);
|
||||||
|
if (name == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
||||||
}
|
if (value == NULL) {
|
||||||
if (name == NULL || value == NULL) {
|
goto error;
|
||||||
goto error;
|
}
|
||||||
}
|
}
|
||||||
if (PyDict_SetItem(opts, name, value) < 0) {
|
if (PyDict_SetItem(opts, name, value) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -3019,15 +3025,21 @@ sys_add_xoption(PyObject *opts, const wchar_t *s)
|
||||||
const wchar_t *name_end = wcschr(s, L'=');
|
const wchar_t *name_end = wcschr(s, L'=');
|
||||||
if (!name_end) {
|
if (!name_end) {
|
||||||
name = PyUnicode_FromWideChar(s, -1);
|
name = PyUnicode_FromWideChar(s, -1);
|
||||||
|
if (name == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
value = Py_True;
|
value = Py_True;
|
||||||
Py_INCREF(value);
|
Py_INCREF(value);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
name = PyUnicode_FromWideChar(s, name_end - s);
|
name = PyUnicode_FromWideChar(s, name_end - s);
|
||||||
|
if (name == NULL) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
value = PyUnicode_FromWideChar(name_end + 1, -1);
|
||||||
}
|
if (value == NULL) {
|
||||||
if (name == NULL || value == NULL) {
|
goto error;
|
||||||
goto error;
|
}
|
||||||
}
|
}
|
||||||
if (PyDict_SetItem(opts, name, value) < 0) {
|
if (PyDict_SetItem(opts, name, value) < 0) {
|
||||||
goto error;
|
goto error;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue