Issue #18520: Fix _PySys_Init(), handle PyDict_SetItemString() errors
This commit is contained in:
parent
f54a574478
commit
580496005d
|
@ -1565,17 +1565,24 @@ static struct PyModuleDef sysmodule = {
|
||||||
PyObject *
|
PyObject *
|
||||||
_PySys_Init(void)
|
_PySys_Init(void)
|
||||||
{
|
{
|
||||||
PyObject *m, *v, *sysdict, *version_info;
|
PyObject *m, *sysdict, *version_info;
|
||||||
|
|
||||||
m = PyModule_Create(&sysmodule);
|
m = PyModule_Create(&sysmodule);
|
||||||
if (m == NULL)
|
if (m == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
sysdict = PyModule_GetDict(m);
|
sysdict = PyModule_GetDict(m);
|
||||||
#define SET_SYS_FROM_STRING(key, value) \
|
#define SET_SYS_FROM_STRING(key, value) \
|
||||||
v = value; \
|
do { \
|
||||||
if (v != NULL) \
|
int res; \
|
||||||
PyDict_SetItemString(sysdict, key, v); \
|
PyObject *v = (value); \
|
||||||
Py_XDECREF(v)
|
if (v == NULL) \
|
||||||
|
return NULL; \
|
||||||
|
res = PyDict_SetItemString(sysdict, key, v); \
|
||||||
|
if (res < 0) { \
|
||||||
|
Py_DECREF(v); \
|
||||||
|
return NULL; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
/* Check that stdin is not a directory
|
/* Check that stdin is not a directory
|
||||||
Using shell redirection, you can redirect stdin to a directory,
|
Using shell redirection, you can redirect stdin to a directory,
|
||||||
|
@ -1597,9 +1604,9 @@ _PySys_Init(void)
|
||||||
|
|
||||||
/* stdin/stdout/stderr are now set by pythonrun.c */
|
/* stdin/stdout/stderr are now set by pythonrun.c */
|
||||||
|
|
||||||
PyDict_SetItemString(sysdict, "__displayhook__",
|
SET_SYS_FROM_STRING("__displayhook__",
|
||||||
PyDict_GetItemString(sysdict, "displayhook"));
|
PyDict_GetItemString(sysdict, "displayhook"));
|
||||||
PyDict_SetItemString(sysdict, "__excepthook__",
|
SET_SYS_FROM_STRING("__excepthook__",
|
||||||
PyDict_GetItemString(sysdict, "excepthook"));
|
PyDict_GetItemString(sysdict, "excepthook"));
|
||||||
SET_SYS_FROM_STRING("version",
|
SET_SYS_FROM_STRING("version",
|
||||||
PyUnicode_FromString(Py_GetVersion()));
|
PyUnicode_FromString(Py_GetVersion()));
|
||||||
|
@ -1664,18 +1671,15 @@ _PySys_Init(void)
|
||||||
#endif
|
#endif
|
||||||
if (warnoptions == NULL) {
|
if (warnoptions == NULL) {
|
||||||
warnoptions = PyList_New(0);
|
warnoptions = PyList_New(0);
|
||||||
|
if (warnoptions == NULL)
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Py_INCREF(warnoptions);
|
Py_INCREF(warnoptions);
|
||||||
}
|
}
|
||||||
if (warnoptions != NULL) {
|
SET_SYS_FROM_STRING("warnoptions", warnoptions);
|
||||||
PyDict_SetItemString(sysdict, "warnoptions", warnoptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
v = get_xoptions();
|
SET_SYS_FROM_STRING("_xoptions", get_xoptions());
|
||||||
if (v != NULL) {
|
|
||||||
PyDict_SetItemString(sysdict, "_xoptions", v);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* version_info */
|
/* version_info */
|
||||||
if (VersionInfoType.tp_name == NULL) {
|
if (VersionInfoType.tp_name == NULL) {
|
||||||
|
|
Loading…
Reference in New Issue