mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains() to check for and handle errors correctly.
This commit is contained in:
@@ -137,6 +137,20 @@ add_flag(int flag, const char *envs)
|
||||
return flag;
|
||||
}
|
||||
|
||||
static int
|
||||
isatty_no_error(PyObject *sys_stream)
|
||||
{
|
||||
PyObject *sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
|
||||
if (sys_isatty) {
|
||||
int isatty = PyObject_IsTrue(sys_isatty);
|
||||
Py_DECREF(sys_isatty);
|
||||
if (isatty >= 0)
|
||||
return isatty;
|
||||
}
|
||||
PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Py_InitializeEx(int install_sigs)
|
||||
{
|
||||
@@ -150,7 +164,7 @@ Py_InitializeEx(int install_sigs)
|
||||
char *errors = NULL;
|
||||
int free_codeset = 0;
|
||||
int overridden = 0;
|
||||
PyObject *sys_stream, *sys_isatty;
|
||||
PyObject *sys_stream;
|
||||
#if defined(Py_USING_UNICODE) && defined(HAVE_LANGINFO_H) && defined(CODESET)
|
||||
char *saved_locale, *loc_codeset;
|
||||
#endif
|
||||
@@ -336,40 +350,25 @@ Py_InitializeEx(int install_sigs)
|
||||
|
||||
if (codeset) {
|
||||
sys_stream = PySys_GetObject("stdin");
|
||||
sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
|
||||
if (!sys_isatty)
|
||||
PyErr_Clear();
|
||||
if ((overridden ||
|
||||
(sys_isatty && PyObject_IsTrue(sys_isatty))) &&
|
||||
PyFile_Check(sys_stream)) {
|
||||
if ((overridden || isatty_no_error(sys_stream)) &&
|
||||
PyFile_Check(sys_stream)) {
|
||||
if (!PyFile_SetEncodingAndErrors(sys_stream, icodeset, errors))
|
||||
Py_FatalError("Cannot set codeset of stdin");
|
||||
}
|
||||
Py_XDECREF(sys_isatty);
|
||||
|
||||
sys_stream = PySys_GetObject("stdout");
|
||||
sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
|
||||
if (!sys_isatty)
|
||||
PyErr_Clear();
|
||||
if ((overridden ||
|
||||
(sys_isatty && PyObject_IsTrue(sys_isatty))) &&
|
||||
PyFile_Check(sys_stream)) {
|
||||
if ((overridden || isatty_no_error(sys_stream)) &&
|
||||
PyFile_Check(sys_stream)) {
|
||||
if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors))
|
||||
Py_FatalError("Cannot set codeset of stdout");
|
||||
}
|
||||
Py_XDECREF(sys_isatty);
|
||||
|
||||
sys_stream = PySys_GetObject("stderr");
|
||||
sys_isatty = PyObject_CallMethod(sys_stream, "isatty", "");
|
||||
if (!sys_isatty)
|
||||
PyErr_Clear();
|
||||
if((overridden ||
|
||||
(sys_isatty && PyObject_IsTrue(sys_isatty))) &&
|
||||
PyFile_Check(sys_stream)) {
|
||||
if ((overridden || isatty_no_error(sys_stream)) &&
|
||||
PyFile_Check(sys_stream)) {
|
||||
if (!PyFile_SetEncodingAndErrors(sys_stream, codeset, errors))
|
||||
Py_FatalError("Cannot set codeset of stderr");
|
||||
}
|
||||
Py_XDECREF(sys_isatty);
|
||||
|
||||
if (free_codeset)
|
||||
free(codeset);
|
||||
|
||||
Reference in New Issue
Block a user